Skip to content

Commit b594920

Browse files
committed
apply new APIs (spanIsSampled, spanToJson) after rebase
1 parent 50ca889 commit b594920

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { dropUndefinedKeys } from '@sentry/utils';
33

44
import { DEFAULT_ENVIRONMENT } from '../constants';
55
import { 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

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
3535

3636
private _trimEnd?: boolean;
3737

38+
// DO NOT yet remove this property, it is used in a hack for v7 backwards compatibility.
3839
private _frozenDynamicSamplingContext: Readonly<Partial<DynamicSamplingContext>> | undefined;
3940

4041
private _metadata: Partial<TransactionMetadata>;

packages/core/test/lib/tracing/dynamicSamplingContext.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
2929
test('returns a new DSC, if no DSC was provided during transaction creation', () => {
3030
const transaction = new Transaction({
3131
name: 'tx',
32+
sampled: true,
3233
metadata: {
3334
sampleRate: 0.56,
3435
},
@@ -39,6 +40,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
3940
expect(dynamicSamplingContext).toStrictEqual({
4041
release: '1.0.1',
4142
environment: 'production',
43+
sampled: 'true',
4244
sample_rate: '0.56',
4345
trace_id: expect.any(String),
4446
transaction: 'tx',

0 commit comments

Comments
 (0)