Skip to content

Commit d1b09c6

Browse files
authored
ref(core): Update multiplexed transport to default to errors only (#7964)
By default, we only multiplex errors, but allow to opt-in to more envelope types.
1 parent bce8c36 commit d1b09c6

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

packages/core/src/transports/multiplexed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ interface MatchParam {
1717
/**
1818
* A function that returns an event from the envelope if one exists. You can optionally pass an array of envelope item
1919
* types to filter by - only envelopes matching the given types will be multiplexed.
20+
* Allowed values are: 'event', 'transaction', 'profile', 'replay_event'
2021
*
21-
* @param types Defaults to ['event', 'transaction', 'profile', 'replay_event']
22+
* @param types Defaults to ['event']
2223
*/
2324
getEvent(types?: EnvelopeItemType[]): Event | undefined;
2425
}
@@ -61,8 +62,7 @@ export function makeMultiplexedTransport<TO extends BaseTransportOptions>(
6162

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

packages/core/test/lib/transports/multiplexed.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import type { BaseTransportOptions, ClientReport, EventEnvelope, EventItem, Transport } from '@sentry/types';
1+
import type {
2+
BaseTransportOptions,
3+
ClientReport,
4+
EventEnvelope,
5+
EventItem,
6+
TransactionEvent,
7+
Transport,
8+
} from '@sentry/types';
29
import { createClientReportEnvelope, createEnvelope, dsnFromString } from '@sentry/utils';
310
import { TextEncoder } from 'util';
411

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

25+
const TRANSACTION_EVENT: TransactionEvent = { type: 'transaction', event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' };
1826
const TRANSACTION_ENVELOPE = createEnvelope<EventEnvelope>(
1927
{ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' },
20-
[[{ type: 'transaction' }, { event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' }] as EventItem],
28+
[[{ type: 'transaction' }, TRANSACTION_EVENT] as EventItem],
2129
);
2230

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

146-
it('callback getEvent can ignore transactions', async () => {
154+
it('callback getEvent ignores transactions by default', async () => {
147155
expect.assertions(2);
148156

149157
const makeTransport = makeMultiplexedTransport(
150158
createTestTransport(url => {
151159
expect(url).toBe(DSN2_URL);
152160
}),
153161
({ getEvent }) => {
154-
expect(getEvent(['event'])).toBeUndefined();
162+
expect(getEvent()).toBeUndefined();
163+
return [DSN2];
164+
},
165+
);
166+
167+
const transport = makeTransport({ url: DSN1_URL, ...transportOptions });
168+
await transport.send(TRANSACTION_ENVELOPE);
169+
});
170+
171+
it('callback getEvent can define envelope types', async () => {
172+
expect.assertions(2);
173+
174+
const makeTransport = makeMultiplexedTransport(
175+
createTestTransport(url => {
176+
expect(url).toBe(DSN2_URL);
177+
}),
178+
({ getEvent }) => {
179+
expect(getEvent(['event', 'transaction'])).toBe(TRANSACTION_EVENT);
155180
return [DSN2];
156181
},
157182
);

0 commit comments

Comments
 (0)