Skip to content

Commit 2bb1bcf

Browse files
committed
only use scope transaction name if event doesn't already have a transaction
1 parent d1f0b60 commit 2bb1bcf

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/hub/src/scope.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,11 @@ export class Scope implements ScopeInterface {
465465
event.level = this._level;
466466
}
467467
if (this._transactionName) {
468-
event.transaction = this._transactionName;
468+
// This runs before any event processors, so the only way that the event would already have a `transaction` value
469+
// at this point is if either a) it's a transaction (they have a `transaction` value - their name - from the
470+
// get-go, which we take great pains to ensure is as high-quality as possible), or b) it's a custom event in which
471+
// the user has set the `transaction` value (and in that case we should respect that).
472+
event.transaction = event.transaction || this._transactionName;
469473
}
470474

471475
// We want to set the trace context for normal events only if there isn't already

packages/hub/test/scope.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ describe('Scope', () => {
302302
});
303303
});
304304

305-
test('scope transaction should have priority over event transaction', async () => {
305+
test("scope transaction shouldn't overwrite existing event transaction", async () => {
306306
expect.assertions(1);
307307
const scope = new Scope();
308308
scope.setTransactionName('/abc');
309309
const event: Event = {};
310310
event.transaction = '/cdf';
311311
return scope.applyToEvent(event).then(processedEvent => {
312-
expect(processedEvent!.transaction).toEqual('/abc');
312+
expect(processedEvent!.transaction).toEqual('/cdf');
313313
});
314314
});
315315

0 commit comments

Comments
 (0)