Skip to content

Commit a47cb46

Browse files
committed
fix populated DSC not being stored on span
1 parent cd78621 commit a47cb46

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/tracing/src/span.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
import { getCurrentHub } from '@sentry/hub';
3-
import { Baggage, Hub, Primitive, Span as SpanInterface, SpanContext } from '@sentry/types';
3+
import { Baggage, Hub, Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
44
import {
55
createBaggage,
66
dropUndefinedKeys,
@@ -12,8 +12,6 @@ import {
1212
uuid4,
1313
} from '@sentry/utils';
1414

15-
import { Transaction } from './transaction';
16-
1715
/**
1816
* Keeps track of finished spans for a given transaction
1917
* @internal
@@ -325,6 +323,11 @@ export class Span implements SpanInterface {
325323
? this._populateBaggageWithSentryValues(existingBaggage)
326324
: existingBaggage;
327325

326+
// In case, we poulated the DSC, we have update the stored one on the transaction.
327+
if (existingBaggage !== finalBaggage && this.transaction) {
328+
this.transaction.metadata.baggage = finalBaggage;
329+
}
330+
328331
return finalBaggage;
329332
}
330333

@@ -372,7 +375,9 @@ export class Span implements SpanInterface {
372375
* @returns modified and immutable baggage object
373376
*/
374377
private _populateBaggageWithSentryValues(baggage: Baggage = createBaggage({})): Baggage {
375-
const hub: Hub = (this.transaction && this.transaction._hub) || getCurrentHub();
378+
// Because of a cicular dependency, we cannot import the Transaction class here, hence the type casts
379+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
380+
const hub: Hub = ((this.transaction as any) && (this.transaction as any)._hub) || getCurrentHub();
376381
const client = hub && hub.getClient();
377382

378383
const { environment, release } = (client && client.getOptions()) || {};

0 commit comments

Comments
 (0)