Skip to content

feat(core/v8): Remove _frozenDynamicSamplingContext #11279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions dev-packages/rollup-utils/plugins/bundlePlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ export function makeTerserPlugin() {
// These are used by instrument.ts in utils for identifying HTML elements & events
'_sentryCaptured',
'_sentryId',
// For v7 backwards-compatibility we need to access txn._frozenDynamicSamplingContext
// TODO (v8): Remove this reserved word
'_frozenDynamicSamplingContext',
// These are used to keep span relationships
'_sentryRootSpan',
'_sentryChildSpans',
Expand Down
32 changes: 7 additions & 25 deletions packages/core/src/tracing/dynamicSamplingContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Client, DynamicSamplingContext, Span, Transaction } from '@sentry/types';
import type { Client, DynamicSamplingContext, Span } from '@sentry/types';
import { dropUndefinedKeys } from '@sentry/utils';

import { DEFAULT_ENVIRONMENT } from '../constants';
import { getClient } from '../currentScopes';
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
import { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';

/**
Expand All @@ -28,11 +28,6 @@ export function getDynamicSamplingContextFromClient(trace_id: string, client: Cl
return dsc;
}

/**
* A Span with a frozen dynamic sampling context.
*/
type TransactionWithV7FrozenDsc = Transaction & { _frozenDynamicSamplingContext?: DynamicSamplingContext };

/**
* Creates a dynamic sampling context from a span (and client and scope)
*
Expand All @@ -47,34 +42,21 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
}

const dsc = getDynamicSamplingContextFromClient(spanToJSON(span).trace_id || '', client);

// TODO (v8): Remove v7FrozenDsc as a Transaction will no longer have _frozenDynamicSamplingContext
const rootSpan = getRootSpan(span);
if (!rootSpan) {
return dsc;
}

// TODO (v8): Remove v7FrozenDsc as a Transaction will no longer have _frozenDynamicSamplingContext
// For now we need to avoid breaking users who directly created a txn with a DSC, where this field is still set.
// @see Transaction class constructor
const v7FrozenDsc = rootSpan && (rootSpan as TransactionWithV7FrozenDsc)._frozenDynamicSamplingContext;
if (v7FrozenDsc) {
return v7FrozenDsc;
}
// We don't want to have a transaction name in the DSC if the source is "url" because URLs might contain PII
const jsonSpan = spanToJSON(rootSpan);
const data = jsonSpan.data || {};

// TODO (v8): Replace txn.metadata with txn.attributes[]
// We can't do this yet because attributes aren't always set yet.
// eslint-disable-next-line deprecation/deprecation
const { sampleRate: maybeSampleRate } = (rootSpan as TransactionWithV7FrozenDsc).metadata || {};
const source = data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
const maybeSampleRate = data[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
if (maybeSampleRate != null) {
dsc.sample_rate = `${maybeSampleRate}`;
}

// We don't want to have a transaction name in the DSC if the source is "url" because URLs might contain PII
const jsonSpan = spanToJSON(rootSpan);

const source = (jsonSpan.data || {})[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];

// after JSON conversion, txn.name becomes jsonSpan.description
if (source && source !== 'url') {
dsc.transaction = jsonSpan.description;
Expand Down
11 changes: 0 additions & 11 deletions packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {

private _trimEnd?: boolean | undefined;

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

private _metadata: Partial<TransactionMetadata>;

/**
Expand Down Expand Up @@ -78,14 +75,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {
// TODO (v8): Replace this with another way to set the root span
// eslint-disable-next-line deprecation/deprecation
this.transaction = this;

// If Dynamic Sampling Context is provided during the creation of the transaction, we freeze it as it usually means
// there is incoming Dynamic Sampling Context. (Either through an incoming request, a baggage meta-tag, or other means)
const incomingDynamicSamplingContext = this._metadata.dynamicSamplingContext;
if (incomingDynamicSamplingContext) {
// We shallow copy this in case anything writes to the original reference of the passed in `dynamicSamplingContext`
this._frozenDynamicSamplingContext = { ...incomingDynamicSamplingContext };
}
}

// This sadly conflicts with the getter/setter ordering :(
Expand Down