Skip to content

Commit fead246

Browse files
committed
update transaction to record name changes
1 parent 68d6eba commit fead246

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

packages/tracing/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browser';
2727
export { Span, spanStatusfromHttpCode } from './span';
2828
// eslint-disable-next-line deprecation/deprecation
2929
export { SpanStatus } from './spanstatus';
30-
export { Transaction } from './transaction';
30+
export { Transaction, generateTransactionNameChange } from './transaction';
3131
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './browser';
3232
export { IdleTransaction } from './idletransaction';
3333
export { startIdleTransaction } from './hubextensions';

packages/tracing/src/transaction.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ import {
88
Transaction as TransactionInterface,
99
TransactionContext,
1010
TransactionMetadata,
11+
TransactionNameChange,
12+
TransactionSource,
1113
} from '@sentry/types';
12-
import { createBaggage, dropUndefinedKeys, getSentryBaggageItems, isBaggageMutable, logger } from '@sentry/utils';
14+
import {
15+
createBaggage,
16+
dropUndefinedKeys,
17+
getSentryBaggageItems,
18+
isBaggageMutable,
19+
logger,
20+
timestampWithMs,
21+
} from '@sentry/utils';
1322

1423
import { Span as SpanClass, SpanRecorder } from './span';
1524

@@ -45,6 +54,8 @@ export class Transaction extends SpanClass implements TransactionInterface {
4554
this.metadata = {
4655
...transactionContext.metadata,
4756
spanMetadata: {},
57+
nameChanges: [],
58+
numPropagations: 0,
4859
};
4960

5061
this._trimEnd = transactionContext.trimEnd;
@@ -61,7 +72,9 @@ export class Transaction extends SpanClass implements TransactionInterface {
6172
/** Setter for `name` property, which also sets `source` */
6273
public set name(newName: string) {
6374
this._name = newName;
64-
this.metadata.source = 'custom';
75+
const source = 'custom';
76+
this.metadata.source = source;
77+
this.metadata.nameChanges.push(generateTransactionNameChange(newName, source, this.metadata.numPropagations));
6578
}
6679

6780
/**
@@ -70,6 +83,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
7083
public setName(name: string, source: TransactionMetadata['source'] = 'custom'): void {
7184
this.name = name;
7285
this.metadata.source = source;
86+
this.metadata.nameChanges.push(generateTransactionNameChange(name, source, this.metadata.numPropagations));
7387
}
7488

7589
/**
@@ -156,6 +170,8 @@ export class Transaction extends SpanClass implements TransactionInterface {
156170
...(metadata.source && {
157171
transaction_info: {
158172
source: metadata.source,
173+
name_changes: metadata.nameChanges,
174+
num_propagations: metadata.numPropagations,
159175
},
160176
}),
161177
};
@@ -273,3 +289,17 @@ export class Transaction extends SpanClass implements TransactionInterface {
273289
);
274290
}
275291
}
292+
293+
/** Generate objects representing a transaction name change */
294+
export function generateTransactionNameChange(
295+
name: string,
296+
source: TransactionSource,
297+
propagations: number,
298+
): TransactionNameChange {
299+
return {
300+
name,
301+
source,
302+
timestamp: timestampWithMs(),
303+
propagations,
304+
};
305+
}

0 commit comments

Comments
 (0)