Skip to content

fix(core): Stop clobbering existing transaction name with scope value #5825

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

Closed
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: 5 additions & 1 deletion packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,11 @@ export class Scope implements ScopeInterface {
event.level = this._level;
}
if (this._transactionName) {
event.transaction = this._transactionName;
// This runs before any event processors, so the only way that the event would already have a `transaction` value
// at this point is if either a) it's a transaction (they have a `transaction` value - their name - from the
// get-go, which we take great pains to ensure is as high-quality as possible), or b) it's a custom event in which
// the user has set the `transaction` value (and in that case we should respect that).
event.transaction = event.transaction || this._transactionName;
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment here on why we did this? I.e. a one- or two-liner saying that we don't want to set event.transaction for transaction events and that it works because transaction events have a transaction field set from the get-go.

}

// We want to set the trace context for normal events only if there isn't already
Expand Down
4 changes: 2 additions & 2 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ describe('Scope', () => {
});
});

test('scope transaction should have priority over event transaction', async () => {
test("scope transaction shouldn't overwrite existing event transaction", async () => {
expect.assertions(1);
const scope = new Scope();
scope.setTransactionName('/abc');
const event: Event = {};
event.transaction = '/cdf';
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.transaction).toEqual('/abc');
expect(processedEvent!.transaction).toEqual('/cdf');
});
});

Expand Down