Skip to content

Commit 0ef9393

Browse files
committed
ref(tracing): Record transaction name changes
1 parent 203a3ed commit 0ef9393

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

packages/tracing/src/transaction.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import {
99
TransactionContext,
1010
TransactionMetadata,
1111
} from '@sentry/types';
12-
import { createBaggage, dropUndefinedKeys, getSentryBaggageItems, isBaggageMutable, logger } from '@sentry/utils';
12+
import {
13+
createBaggage,
14+
dropUndefinedKeys,
15+
getSentryBaggageItems,
16+
isBaggageMutable,
17+
logger,
18+
timestampInSeconds,
19+
} from '@sentry/utils';
1320

1421
import { Span as SpanClass, SpanRecorder } from './span';
1522

@@ -60,18 +67,22 @@ export class Transaction extends SpanClass implements TransactionInterface {
6067
return this._name;
6168
}
6269

63-
/** Setter for `name` property, which also sets `source` */
70+
/** Setter for `name` property, which also sets `source` as custom */
6471
public set name(newName: string) {
65-
this._name = newName;
66-
this.metadata.source = 'custom';
72+
this.setName(newName);
6773
}
6874

6975
/**
7076
* JSDoc
7177
*/
7278
public setName(name: string, source: TransactionMetadata['source'] = 'custom'): void {
73-
this.name = name;
79+
this._name = name;
7480
this.metadata.source = source;
81+
this.metadata.changes.push({
82+
source,
83+
timestamp: timestampInSeconds(),
84+
propagations: this.metadata.propagations,
85+
});
7586
}
7687

7788
/**

packages/tracing/test/transaction.test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,46 @@ describe('`Transaction` class', () => {
2424
expect(transaction.metadata.source).toEqual('custom');
2525
});
2626

27+
it('updates transaction metadata with correct variables needed', () => {
28+
const transaction = new Transaction({ name: 'dogpark' });
29+
expect(transaction.metadata.changes).toEqual([]);
30+
31+
transaction.name = 'ballpit';
32+
33+
expect(transaction.metadata.changes).toEqual([
34+
{
35+
source: 'custom',
36+
timestamp: expect.any(Number),
37+
propagations: 0,
38+
},
39+
]);
40+
41+
transaction.metadata.propagations += 3;
42+
43+
expect(transaction.metadata.changes).toEqual([
44+
{
45+
source: 'custom',
46+
timestamp: expect.any(Number),
47+
propagations: 0,
48+
},
49+
]);
50+
51+
transaction.name = 'playground';
52+
53+
expect(transaction.metadata.changes).toEqual([
54+
{
55+
source: 'custom',
56+
timestamp: expect.any(Number),
57+
propagations: 0,
58+
},
59+
{
60+
source: 'custom',
61+
timestamp: expect.any(Number),
62+
propagations: 3,
63+
},
64+
]);
65+
});
66+
2767
describe('`setName` method', () => {
2868
it("sets source to `'custom'` if no source provided", () => {
2969
const transaction = new Transaction({ name: 'dogpark' });
@@ -40,6 +80,46 @@ describe('`Transaction` class', () => {
4080
expect(transaction.name).toEqual('ballpit');
4181
expect(transaction.metadata.source).toEqual('route');
4282
});
83+
84+
it('updates transaction metadata with correct variables needed', () => {
85+
const transaction = new Transaction({ name: 'dogpark' });
86+
expect(transaction.metadata.changes).toEqual([]);
87+
88+
transaction.name = 'ballpit';
89+
90+
expect(transaction.metadata.changes).toEqual([
91+
{
92+
source: 'custom',
93+
timestamp: expect.any(Number),
94+
propagations: 0,
95+
},
96+
]);
97+
98+
transaction.metadata.propagations += 3;
99+
100+
expect(transaction.metadata.changes).toEqual([
101+
{
102+
source: 'custom',
103+
timestamp: expect.any(Number),
104+
propagations: 0,
105+
},
106+
]);
107+
108+
transaction.setName('playground', 'task');
109+
110+
expect(transaction.metadata.changes).toEqual([
111+
{
112+
source: 'custom',
113+
timestamp: expect.any(Number),
114+
propagations: 0,
115+
},
116+
{
117+
source: 'task',
118+
timestamp: expect.any(Number),
119+
propagations: 3,
120+
},
121+
]);
122+
});
43123
});
44124
});
45125
});

0 commit comments

Comments
 (0)