From 2bb1bcf09a45553a9c37657b22c2073df03c4b1f Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Sun, 11 Sep 2022 20:27:32 -0700 Subject: [PATCH] only use scope transaction name if event doesn't already have a transaction --- packages/hub/src/scope.ts | 6 +++++- packages/hub/test/scope.test.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/hub/src/scope.ts b/packages/hub/src/scope.ts index 4f72afa34a61..570864064254 100644 --- a/packages/hub/src/scope.ts +++ b/packages/hub/src/scope.ts @@ -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; } // We want to set the trace context for normal events only if there isn't already diff --git a/packages/hub/test/scope.test.ts b/packages/hub/test/scope.test.ts index 1bad52db6d9f..0b7eceb522a5 100644 --- a/packages/hub/test/scope.test.ts +++ b/packages/hub/test/scope.test.ts @@ -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'); }); });