diff --git a/packages/node-integration-tests/suites/express/tracing/test.ts b/packages/node-integration-tests/suites/express/tracing/test.ts index f924e904dd09..1e74dd509b68 100644 --- a/packages/node-integration-tests/suites/express/tracing/test.ts +++ b/packages/node-integration-tests/suites/express/tracing/test.ts @@ -38,7 +38,13 @@ test('should set a correct transaction name for routes specified in RegEx', asyn transaction: 'GET /\\/test\\/regex/', transaction_info: { source: 'route', - changes: [], + changes: [ + { + propagations: 0, + source: 'route', + timestamp: expect.any(Number), + }, + ], propagations: 0, }, contexts: { @@ -68,7 +74,13 @@ test.each([['array1'], ['array5']])( transaction: 'GET /test/array1,/\\/test\\/array[2-9]', transaction_info: { source: 'route', - changes: [], + changes: [ + { + propagations: 0, + source: 'route', + timestamp: expect.any(Number), + }, + ], propagations: 0, }, contexts: { @@ -106,7 +118,13 @@ test.each([ transaction: 'GET /test/arr/:id,/\\/test\\/arr[0-9]*\\/required(path)?(\\/optionalPath)?\\/(lastParam)?', transaction_info: { source: 'route', - changes: [], + changes: [ + { + propagations: 0, + source: 'route', + timestamp: expect.any(Number), + }, + ], propagations: 0, }, contexts: { diff --git a/packages/tracing/src/transaction.ts b/packages/tracing/src/transaction.ts index 87e68fb6dc3e..f0c4ac185ed7 100644 --- a/packages/tracing/src/transaction.ts +++ b/packages/tracing/src/transaction.ts @@ -9,7 +9,14 @@ import { TransactionContext, TransactionMetadata, } from '@sentry/types'; -import { createBaggage, dropUndefinedKeys, getSentryBaggageItems, isBaggageMutable, logger } from '@sentry/utils'; +import { + createBaggage, + dropUndefinedKeys, + getSentryBaggageItems, + isBaggageMutable, + logger, + timestampInSeconds, +} from '@sentry/utils'; import { Span as SpanClass, SpanRecorder } from './span'; @@ -60,18 +67,22 @@ export class Transaction extends SpanClass implements TransactionInterface { return this._name; } - /** Setter for `name` property, which also sets `source` */ + /** Setter for `name` property, which also sets `source` as custom */ public set name(newName: string) { - this._name = newName; - this.metadata.source = 'custom'; + this.setName(newName); } /** * JSDoc */ public setName(name: string, source: TransactionMetadata['source'] = 'custom'): void { - this.name = name; + this._name = name; this.metadata.source = source; + this.metadata.changes.push({ + source, + timestamp: timestampInSeconds(), + propagations: this.metadata.propagations, + }); } /** diff --git a/packages/tracing/test/transaction.test.ts b/packages/tracing/test/transaction.test.ts index d47971679a71..d0bb373e467a 100644 --- a/packages/tracing/test/transaction.test.ts +++ b/packages/tracing/test/transaction.test.ts @@ -24,6 +24,46 @@ describe('`Transaction` class', () => { expect(transaction.metadata.source).toEqual('custom'); }); + it('updates transaction metadata with correct variables needed', () => { + const transaction = new Transaction({ name: 'dogpark' }); + expect(transaction.metadata.changes).toEqual([]); + + transaction.name = 'ballpit'; + + expect(transaction.metadata.changes).toEqual([ + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 0, + }, + ]); + + transaction.metadata.propagations += 3; + + expect(transaction.metadata.changes).toEqual([ + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 0, + }, + ]); + + transaction.name = 'playground'; + + expect(transaction.metadata.changes).toEqual([ + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 0, + }, + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 3, + }, + ]); + }); + describe('`setName` method', () => { it("sets source to `'custom'` if no source provided", () => { const transaction = new Transaction({ name: 'dogpark' }); @@ -40,6 +80,46 @@ describe('`Transaction` class', () => { expect(transaction.name).toEqual('ballpit'); expect(transaction.metadata.source).toEqual('route'); }); + + it('updates transaction metadata with correct variables needed', () => { + const transaction = new Transaction({ name: 'dogpark' }); + expect(transaction.metadata.changes).toEqual([]); + + transaction.name = 'ballpit'; + + expect(transaction.metadata.changes).toEqual([ + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 0, + }, + ]); + + transaction.metadata.propagations += 3; + + expect(transaction.metadata.changes).toEqual([ + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 0, + }, + ]); + + transaction.setName('playground', 'task'); + + expect(transaction.metadata.changes).toEqual([ + { + source: 'custom', + timestamp: expect.any(Number), + propagations: 0, + }, + { + source: 'task', + timestamp: expect.any(Number), + propagations: 3, + }, + ]); + }); }); }); });