Skip to content

ref(core): Update multiplexed transport to default to errors only #7964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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