Skip to content

Commit c25a312

Browse files
authored
feat(tracing): Add transaction name to tracestate value (#3937)
1 parent c1f86c4 commit c25a312

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

packages/core/test/lib/request.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ describe('eventToSentryRequest', () => {
8787
// public_key: 'dogsarebadatkeepingsecrets',
8888
// release: 'off.leash.park',
8989
// user: { id: '1121', segment: 'bigs' },
90+
// transaction: '/dogs/are/great/',
9091
// }),
9192
tracestate: {
9293
sentry:
9394
'sentry=eyJ0cmFjZV9pZCI6IjEyMzEyMDEyMTEyMTIwMTIiLCJlbnZpcm9ubWVudCI6ImRvZ3BhcmsiLCJwdWJsaWNfa2V5Ijo' +
9495
'iZG9nc2FyZWJhZGF0a2VlcGluZ3NlY3JldHMiLCJyZWxlYXNlIjoib2ZmLmxlYXNoLnBhcmsiLCJ1c2VyIjp7ImlkIjoiMTEyM' +
95-
'SIsInNlZ21lbnQiOiJiaWdzIn19',
96+
'SIsInNlZ21lbnQiOiJiaWdzIn0sInRyYW5zYWN0aW9uIjoiL2RvZ3MvYXJlL2dyZWF0LyJ9',
9697
},
9798
},
9899
spans: [],
@@ -135,6 +136,7 @@ describe('eventToSentryRequest', () => {
135136
public_key: 'dogsarebadatkeepingsecrets',
136137
release: 'off.leash.park',
137138
user: { id: '1121', segment: 'bigs' },
139+
transaction: '/dogs/are/great/',
138140
});
139141
});
140142
});

packages/tracing/src/span.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ export class Span implements SpanInterface {
393393
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
394394
public_key: dsn.publicKey!,
395395
user,
396+
transaction: this.transaction?.name,
396397
})}`;
397398
}
398399

packages/tracing/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ type SentryTracestateData = {
157157
release?: string;
158158
public_key: string;
159159
user?: { id?: string; segment?: string };
160+
transaction?: string;
160161
};
161162

162163
/**

packages/tracing/test/span.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,20 @@ describe('Span', () => {
110110
const environment = 'dogpark';
111111
const traceId = '12312012123120121231201212312012';
112112
const user = { id: '1121', segment: 'bigs' };
113+
const transactionName = 'FETCH /ball';
113114

114-
const computedTracestate = `sentry=${computeTracestateValue({
115+
const baseTracestateData = {
115116
trace_id: traceId,
116117
environment,
117118
release,
118119
public_key: publicKey,
119120
user,
121+
};
122+
const computedTracestate = `sentry=${computeTracestateValue({
123+
...baseTracestateData,
124+
transaction: transactionName,
120125
})}`;
126+
const computedOrphanTracestate = `sentry=${computeTracestateValue(baseTracestateData)}`;
121127
const thirdpartyData = 'maisey=silly,charlie=goofy';
122128

123129
const hub = new Hub(
@@ -134,14 +140,14 @@ describe('Span', () => {
134140
});
135141

136142
test('no third-party data', () => {
137-
const transaction = new Transaction({ name: 'FETCH /ball', traceId }, hub);
143+
const transaction = new Transaction({ name: transactionName, traceId }, hub);
138144
const span = transaction.startChild({ op: 'dig.hole' });
139145

140146
expect(span.getTraceHeaders().tracestate).toEqual(computedTracestate);
141147
});
142148

143149
test('third-party data', () => {
144-
const transaction = new Transaction({ name: 'FETCH /ball' }, hub);
150+
const transaction = new Transaction({ name: transactionName }, hub);
145151
transaction.setMetadata({ tracestate: { sentry: computedTracestate, thirdparty: thirdpartyData } });
146152
const span = transaction.startChild({ op: 'dig.hole' });
147153

@@ -153,7 +159,7 @@ describe('Span', () => {
153159
const span = new Span({ op: 'dig.hole' });
154160
span.traceId = traceId;
155161

156-
expect(span.getTraceHeaders().tracestate).toEqual(computedTracestate);
162+
expect(span.getTraceHeaders().tracestate).toEqual(computedOrphanTracestate);
157163
});
158164
});
159165

0 commit comments

Comments
 (0)