Skip to content

Commit 3111ed0

Browse files
committed
use tags to transmit tracestate during processing
1 parent e344829 commit 3111ed0

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

packages/core/src/request.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,28 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
3333
* @returns SentryRequest in envelope form
3434
*/
3535
export function transactionToSentryRequest(event: Event, api: API): SentryRequest {
36-
// since JS has no Object.prototype.pop()
37-
const { __sentry_samplingMethod: samplingMethod, __sentry_sampleRate: sampleRate, ...otherTags } = event.tags || {};
36+
// pull our temporary values out of the tags, so they don't get sent to Sentry
37+
const {
38+
__sentry_samplingMethod: samplingMethod,
39+
__sentry_sampleRate: sampleRate,
40+
__sentry_tracestate: encodedTracestate,
41+
...otherTags
42+
} = event.tags || {};
3843
event.tags = otherTags;
3944

40-
let tracestate = {};
41-
if (event.tracestate) {
42-
try {
43-
// the tracestate is stored in bas64-encoded JSON, but envelope header values are expected to be full JS values,
44-
// so we have to decode and reinflate it
45-
tracestate = JSON.parse(base64ToUnicode(event.tracestate));
46-
} catch (err) {
47-
logger.warn(err);
48-
}
45+
// the tracestate is stored in bas64-encoded JSON, but envelope header values are expected to be full JS values,
46+
// so we have to decode and reinflate it
47+
let tracestate;
48+
try {
49+
tracestate = JSON.parse(base64ToUnicode(encodedTracestate as string));
50+
} catch (err) {
51+
logger.warn(err);
4952
}
50-
delete event.tracestate;
5153

5254
const envelopeHeaders = JSON.stringify({
5355
event_id: event.event_id,
5456
sent_at: new Date().toISOString(),
55-
trace: tracestate, // trace context for dynamic sampling on relay
57+
...(tracestate && { trace: tracestate }), // trace context for dynamic sampling on relay
5658
});
5759

5860
const itemHeaders = JSON.stringify({

packages/tracing/src/transaction.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export class Transaction extends SpanClass implements TransactionInterface {
103103
}).endTimestamp;
104104
}
105105

106+
this.tags.__sentry_tracestate = this.tracestate;
107+
106108
const transactionEvent: Event = {
107109
contexts: {
108110
trace: this.getTraceContext(),
@@ -111,7 +113,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
111113
start_timestamp: this.startTimestamp,
112114
tags: this.tags,
113115
timestamp: this.endTimestamp,
114-
tracestate: this.tracestate,
115116
transaction: this.name,
116117
type: 'transaction',
117118
};
@@ -123,8 +124,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
123124
transactionEvent.measurements = this._measurements;
124125
}
125126

126-
transactionEvent.tracestate = this.tracestate;
127-
128127
return this._hub.captureEvent(transactionEvent);
129128
}
130129

packages/types/src/event.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export interface Event {
4141
type?: EventType;
4242
spans?: Span[];
4343
measurements?: Measurements;
44-
tracestate?: string;
4544
}
4645

4746
/** JSDoc */

0 commit comments

Comments
 (0)