Skip to content

Commit e04d1b1

Browse files
committed
ref(tracing): Sync baggage data in Http and envelope headers
1 parent d97ad84 commit e04d1b1

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

packages/core/src/envelope.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,12 @@ function createEventEnvelopeHeaders(
128128
...(event.type === 'transaction' &&
129129
event.contexts &&
130130
event.contexts.trace && {
131-
// TODO: Grab this from baggage
132131
trace: dropUndefinedKeys({
133132
// Trace context must be defined for transactions
134133
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
135-
trace_id: event.contexts!.trace.trace_id as string,
136-
environment: event.environment,
137-
release: event.release,
138-
transaction: event.transaction,
139-
user: event.user && {
140-
id: event.user.id,
141-
segment: event.user.segment,
142-
},
134+
trace_id: (event.contexts!.trace as Record<string, unknown>).trace_id as string,
143135
public_key: dsn.publicKey,
136+
...event.contexts.baggage,
144137
}),
145138
}),
146139
};

packages/tracing/src/span.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Baggage, Hub, Primitive, Span as SpanInterface, SpanContext, Transactio
44
import {
55
createBaggage,
66
dropUndefinedKeys,
7-
isBaggageEmpty,
87
isBaggageMutable,
98
isSentryBaggageEmpty,
109
setBaggageImmutable,
@@ -312,7 +311,7 @@ export class Span implements SpanInterface {
312311
/**
313312
* @inheritdoc
314313
*/
315-
public getBaggage(): Baggage | undefined {
314+
public getBaggage(): Baggage {
316315
const existingBaggage = this.transaction && this.transaction.metadata.baggage;
317316

318317
// Only add Sentry baggage items to baggage, if baggage does not exist yet or it is still
@@ -322,7 +321,7 @@ export class Span implements SpanInterface {
322321
? this._getBaggageWithSentryValues(existingBaggage)
323322
: existingBaggage;
324323

325-
return isBaggageEmpty(finalBaggage) ? undefined : finalBaggage;
324+
return finalBaggage;
326325
}
327326

328327
/**

packages/tracing/src/transaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TransactionContext,
77
TransactionMetadata,
88
} from '@sentry/types';
9-
import { dropUndefinedKeys, logger } from '@sentry/utils';
9+
import { dropUndefinedKeys, getSentryBaggageItems, logger } from '@sentry/utils';
1010

1111
import { Span as SpanClass, SpanRecorder } from './span';
1212

@@ -122,6 +122,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
122122
const transaction: Event = {
123123
contexts: {
124124
trace: this.getTraceContext(),
125+
baggage: getSentryBaggageItems(this.getBaggage()),
125126
},
126127
spans: finishedSpans,
127128
start_timestamp: this.startTimestamp,

0 commit comments

Comments
 (0)