Skip to content

feat(core): Set custom transaction source for event processors #5722

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 2 commits into from
Sep 13, 2022
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
21 changes: 21 additions & 0 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
resolvedSyncPromise,
SentryError,
SyncPromise,
timestampInSeconds,
truncate,
uuid4,
} from '@sentry/utils';
Expand Down Expand Up @@ -658,6 +659,26 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
this._updateSessionFromEvent(session, processedEvent);
}

// None of the Sentry built event processor will update transaction name,
// so if the transaction name has been changed by an event processor, we know
// it has to come from custom event processor added by a user
const transactionInfo = processedEvent.transaction_info;
if (isTransaction && transactionInfo && processedEvent.transaction !== event.transaction) {
const source = 'custom';
Comment on lines +666 to +667
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I first saw this, my gut reaction was to worry that it was going to break the RequestData integration, until I realized that the integration shouldn't ever change a transaction event's transaction, only an error event's transaction. So we're good there, but still, I wonder if it might not be worth putting a note here basically saying "we know none of our stuff does this, so if it happened, it must be because of some custom event processor added by the user."

processedEvent.transaction_info = {
...transactionInfo,
source,
changes: [
...transactionInfo.changes,
{
source,
timestamp: timestampInSeconds(),
propagations: transactionInfo.propagations,
},
],
};
}

this.sendEvent(processedEvent, hint);
return processedEvent;
})
Expand Down
47 changes: 47 additions & 0 deletions packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,53 @@ describe('BaseClient', () => {
expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'error');
});

test('mutating transaction name with event processors sets transaction name change metadata', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableSend: true });
const client = new TestClient(options);

const transaction: Event = {
contexts: {
trace: {
op: 'pageload',
span_id: 'a3df84a60c2e4e76',
trace_id: '86f39e84263a4de99c326acab3bfe3bd',
},
},
environment: 'production',
event_id: '972f45b826a248bba98e990878a177e1',
spans: [],
start_timestamp: 1591603196.614865,
timestamp: 1591603196.728485,
transaction: 'initialName',
type: 'transaction',
transaction_info: {
source: 'url',
changes: [],
propagations: 3,
},
};

const scope = new Scope();
scope.addEventProcessor(event => {
event.transaction = 'updatedName';
return event;
});

client.captureEvent(transaction, {}, scope);
expect(TestClient.instance!.event!.transaction).toEqual('updatedName');
expect(TestClient.instance!.event!.transaction_info).toEqual({
source: 'custom',
changes: [
{
propagations: 3,
source: 'custom',
timestamp: expect.any(Number),
},
],
propagations: 3,
});
});

test('eventProcessor sends an event and logs when it crashes', () => {
expect.assertions(3);

Expand Down