@@ -3,6 +3,7 @@ import { dropUndefinedKeys } from '@sentry/utils';
33
44import { DEFAULT_ENVIRONMENT } from '../constants' ;
55import { getClient , getCurrentScope } from '../exports' ;
6+ import { spanIsSampled , spanToJSON } from '../utils/spanUtils' ;
67
78/**
89 * Creates a dynamic sampling context from a client.
@@ -54,16 +55,15 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
5455 }
5556
5657 // passing emit=false here to only emit later once the DSC is actually populated
57- const dsc = getDynamicSamplingContextFromClient ( span . traceId , client , getCurrentScope ( ) , false ) ;
58+ const dsc = getDynamicSamplingContextFromClient ( spanToJSON ( span ) . trace_id || '' , client , getCurrentScope ( ) , false ) ;
5859
60+ // As long as we use `Transaction`s internally, this should be fine.
61+ // TODO: We need to replace this with a `getRootSpan(span)` function though
5962 const txn = span . transaction as TransactionWithV7FrozenDsc | undefined ;
6063 if ( ! txn ) {
6164 return dsc ;
6265 }
6366
64- // As long as we use `Transaction`s internally, this should be fine.
65- // TODO: We need to replace this with a `getRootSpan(span)` function though
66-
6767 // TODO (v8): Remove v7FrozenDsc as a Transaction will no longer have _frozenDynamicSamplingContext
6868 // For now we need to avoid breaking users who directly created a txn with a DSC, where this field is still set.
6969 // @see Transaction class constructor
@@ -79,16 +79,14 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
7979
8080 // We don't want to have a transaction name in the DSC if the source is "url" because URLs might contain PII
8181 const source = txn . metadata . source ;
82+ const jsonSpan = spanToJSON ( txn ) ;
83+
84+ // after JSON conversion, txn.name becomes jsonSpan.description
8285 if ( source && source !== 'url' ) {
83- dsc . transaction = txn . name ;
86+ dsc . transaction = jsonSpan . description ;
8487 }
8588
86- // TODO: Switch to `spanIsSampled` once we have it
87- // eslint-disable-next-line deprecation/deprecation
88- if ( txn . sampled !== undefined ) {
89- // eslint-disable-next-line deprecation/deprecation
90- dsc . sampled = String ( txn . sampled ) ;
91- }
89+ dsc . sampled = String ( spanIsSampled ( txn ) ) ;
9290
9391 client . emit && client . emit ( 'createDsc' , dsc ) ;
9492
0 commit comments