Skip to content
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
4 changes: 4 additions & 0 deletions packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ export class Scope implements ScopeInterface {
// errors with transaction and it relys on that.
if (this._span) {
event.contexts = { trace: this._span.getTraceContext(), ...event.contexts };
const transactionName = this._span.transaction?.name;
if (transactionName) {
event.tags = { transaction: transactionName, ...event.tags };
}
}

this._applyFingerprint(event);
Expand Down
32 changes: 32 additions & 0 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,38 @@ describe('Scope', () => {
});
});

test('applyToEvent transaction name tag when transaction on scope', async () => {
expect.assertions(1);
const scope = new Scope();
const transaction = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
name: 'fake transaction',
} as any;
transaction.transaction = transaction; // because this is a transaction, its transaction pointer points to itself
scope.setSpan(transaction);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
});
});

test('applyToEvent transaction name tag when span on scope', async () => {
expect.assertions(1);
const scope = new Scope();
const transaction = { name: 'fake transaction' };
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
transaction,
} as any;
scope.setSpan(span);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
});
});

test('clear', () => {
const scope = new Scope();
scope.setExtra('a', 2);
Expand Down