Skip to content

fix(tracing): Only record transaction name changes if data is different #5728

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

Merged
Merged
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
15 changes: 10 additions & 5 deletions packages/tracing/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ export class Transaction extends SpanClass implements TransactionInterface {
* JSDoc
*/
public setName(name: string, source: TransactionMetadata['source'] = 'custom'): void {
// `source` could change without the name changing if we discover that an unparameterized route is actually
// parameterized by virtue of having no parameters in its path
if (name !== this.name || source !== this.metadata.source) {
this.metadata.changes.push({
source,
timestamp: timestampInSeconds(),
propagations: this.metadata.propagations,
});
}

this._name = name;
this.metadata.source = source;
this.metadata.changes.push({
source,
timestamp: timestampInSeconds(),
propagations: this.metadata.propagations,
});
}

/**
Expand Down
62 changes: 60 additions & 2 deletions packages/tracing/test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('`Transaction` class', () => {
expect(transaction.metadata.source).toEqual('custom');
});

it('updates transaction metadata with correct variables needed', () => {
it('updates transaction name changes with correct variables needed', () => {
const transaction = new Transaction({ name: 'dogpark' });
expect(transaction.metadata.changes).toEqual([]);

Expand Down Expand Up @@ -62,6 +62,64 @@ describe('`Transaction` class', () => {
propagations: 3,
},
]);

// Only change `source`
transaction.setName('playground', 'route');

expect(transaction.metadata.changes).toEqual([
{
source: 'custom',
timestamp: expect.any(Number),
propagations: 0,
},
{
source: 'custom',
timestamp: expect.any(Number),
propagations: 3,
},
{
source: 'route',
timestamp: expect.any(Number),
propagations: 3,
},
]);
});

it("doesn't update transaction name changes if no change in data", () => {
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.name = 'ballpit';

// Still only one entry
expect(transaction.metadata.changes).toEqual([
{
source: 'custom',
timestamp: expect.any(Number),
propagations: 0,
},
]);

transaction.setName('ballpit', 'custom');

// Still only one entry
expect(transaction.metadata.changes).toEqual([
{
source: 'custom',
timestamp: expect.any(Number),
propagations: 0,
},
]);
});

describe('`setName` method', () => {
Expand All @@ -81,7 +139,7 @@ describe('`Transaction` class', () => {
expect(transaction.metadata.source).toEqual('route');
});

it('updates transaction metadata with correct variables needed', () => {
it('updates transaction name changes with correct variables needed', () => {
const transaction = new Transaction({ name: 'dogpark' });
expect(transaction.metadata.changes).toEqual([]);

Expand Down