Skip to content

Commit 1fdb95f

Browse files
authored
fix(tracing): Add transaction name as tag on error events (#3024)
Restores previous behavior which got lost somewhere along the way.
1 parent c864ff6 commit 1fdb95f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/hub/src/scope.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ export class Scope implements ScopeInterface {
392392
// errors with transaction and it relys on that.
393393
if (this._span) {
394394
event.contexts = { trace: this._span.getTraceContext(), ...event.contexts };
395+
const transactionName = this._span.transaction?.name;
396+
if (transactionName) {
397+
event.tags = { transaction: transactionName, ...event.tags };
398+
}
395399
}
396400

397401
this._applyFingerprint(event);

packages/hub/test/scope.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,38 @@ describe('Scope', () => {
297297
});
298298
});
299299

300+
test('applyToEvent transaction name tag when transaction on scope', async () => {
301+
expect.assertions(1);
302+
const scope = new Scope();
303+
const transaction = {
304+
fake: 'span',
305+
getTraceContext: () => ({ a: 'b' }),
306+
name: 'fake transaction',
307+
} as any;
308+
transaction.transaction = transaction; // because this is a transaction, its transaction pointer points to itself
309+
scope.setSpan(transaction);
310+
const event: Event = {};
311+
return scope.applyToEvent(event).then(processedEvent => {
312+
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
313+
});
314+
});
315+
316+
test('applyToEvent transaction name tag when span on scope', async () => {
317+
expect.assertions(1);
318+
const scope = new Scope();
319+
const transaction = { name: 'fake transaction' };
320+
const span = {
321+
fake: 'span',
322+
getTraceContext: () => ({ a: 'b' }),
323+
transaction,
324+
} as any;
325+
scope.setSpan(span);
326+
const event: Event = {};
327+
return scope.applyToEvent(event).then(processedEvent => {
328+
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
329+
});
330+
});
331+
300332
test('clear', () => {
301333
const scope = new Scope();
302334
scope.setExtra('a', 2);

0 commit comments

Comments
 (0)