Skip to content

Commit

Permalink
ref(core): Update multiplexed transport to default to errors only (#7964
Browse files Browse the repository at this point in the history
)

By default, we only multiplex errors, but allow to opt-in to more envelope types.
  • Loading branch information
mydea authored Apr 26, 2023
1 parent bce8c36 commit d1b09c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/transports/multiplexed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ interface MatchParam {
/**
* A function that returns an event from the envelope if one exists. You can optionally pass an array of envelope item
* types to filter by - only envelopes matching the given types will be multiplexed.
* Allowed values are: 'event', 'transaction', 'profile', 'replay_event'
*
* @param types Defaults to ['event', 'transaction', 'profile', 'replay_event']
* @param types Defaults to ['event']
*/
getEvent(types?: EnvelopeItemType[]): Event | undefined;
}
Expand Down Expand Up @@ -61,8 +62,7 @@ export function makeMultiplexedTransport<TO extends BaseTransportOptions>(

async function send(envelope: Envelope): Promise<void | TransportMakeRequestResponse> {
function getEvent(types?: EnvelopeItemType[]): Event | undefined {
const eventTypes: EnvelopeItemType[] =
types && types.length ? types : ['event', 'transaction', 'profile', 'replay_event'];
const eventTypes: EnvelopeItemType[] = types && types.length ? types : ['event'];
return eventFromEnvelope(envelope, eventTypes);
}

Expand Down
33 changes: 29 additions & 4 deletions packages/core/test/lib/transports/multiplexed.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { BaseTransportOptions, ClientReport, EventEnvelope, EventItem, Transport } from '@sentry/types';
import type {
BaseTransportOptions,
ClientReport,
EventEnvelope,
EventItem,
TransactionEvent,
Transport,
} from '@sentry/types';
import { createClientReportEnvelope, createEnvelope, dsnFromString } from '@sentry/utils';
import { TextEncoder } from 'util';

Expand All @@ -15,9 +22,10 @@ const ERROR_ENVELOPE = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4b
[{ type: 'event' }, ERROR_EVENT] as EventItem,
]);

const TRANSACTION_EVENT: TransactionEvent = { type: 'transaction', event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' };
const TRANSACTION_ENVELOPE = createEnvelope<EventEnvelope>(
{ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' },
[[{ type: 'transaction' }, { event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' }] as EventItem],
[[{ type: 'transaction' }, TRANSACTION_EVENT] as EventItem],
);

const DEFAULT_DISCARDED_EVENTS: ClientReport['discarded_events'] = [
Expand Down Expand Up @@ -143,15 +151,32 @@ describe('makeMultiplexedTransport', () => {
await transport.send(CLIENT_REPORT_ENVELOPE);
});

it('callback getEvent can ignore transactions', async () => {
it('callback getEvent ignores transactions by default', async () => {
expect.assertions(2);

const makeTransport = makeMultiplexedTransport(
createTestTransport(url => {
expect(url).toBe(DSN2_URL);
}),
({ getEvent }) => {
expect(getEvent(['event'])).toBeUndefined();
expect(getEvent()).toBeUndefined();
return [DSN2];
},
);

const transport = makeTransport({ url: DSN1_URL, ...transportOptions });
await transport.send(TRANSACTION_ENVELOPE);
});

it('callback getEvent can define envelope types', async () => {
expect.assertions(2);

const makeTransport = makeMultiplexedTransport(
createTestTransport(url => {
expect(url).toBe(DSN2_URL);
}),
({ getEvent }) => {
expect(getEvent(['event', 'transaction'])).toBe(TRANSACTION_EVENT);
return [DSN2];
},
);
Expand Down

0 comments on commit d1b09c6

Please sign in to comment.