All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.cjs.tracing.dynamicSamplingContext.js.map Maven / Gradle / Ivy

There is a newer version: 8.39.0
Show newest version
{"version":3,"file":"dynamicSamplingContext.js","sources":["../../../src/tracing/dynamicSamplingContext.ts"],"sourcesContent":["import type { Client, DynamicSamplingContext, Span } from '@sentry/types';\nimport {\n  addNonEnumerableProperty,\n  baggageHeaderToDynamicSamplingContext,\n  dropUndefinedKeys,\n  dynamicSamplingContextToSentryBaggageHeader,\n} from '@sentry/utils';\n\nimport { DEFAULT_ENVIRONMENT } from '../constants';\nimport { getClient } from '../currentScopes';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';\nimport { hasTracingEnabled } from '../utils/hasTracingEnabled';\nimport { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';\n\n/**\n * If you change this value, also update the terser plugin config to\n * avoid minification of the object property!\n */\nconst FROZEN_DSC_FIELD = '_frozenDsc';\n\ntype SpanWithMaybeDsc = Span & {\n  [FROZEN_DSC_FIELD]?: Partial | undefined;\n};\n\n/**\n * Freeze the given DSC on the given span.\n */\nexport function freezeDscOnSpan(span: Span, dsc: Partial): void {\n  const spanWithMaybeDsc = span as SpanWithMaybeDsc;\n  addNonEnumerableProperty(spanWithMaybeDsc, FROZEN_DSC_FIELD, dsc);\n}\n\n/**\n * Creates a dynamic sampling context from a client.\n *\n * Dispatches the `createDsc` lifecycle hook as a side effect.\n */\nexport function getDynamicSamplingContextFromClient(trace_id: string, client: Client): DynamicSamplingContext {\n  const options = client.getOptions();\n\n  const { publicKey: public_key } = client.getDsn() || {};\n\n  const dsc = dropUndefinedKeys({\n    environment: options.environment || DEFAULT_ENVIRONMENT,\n    release: options.release,\n    public_key,\n    trace_id,\n  }) as DynamicSamplingContext;\n\n  client.emit('createDsc', dsc);\n\n  return dsc;\n}\n\n/**\n * Creates a dynamic sampling context from a span (and client and scope)\n *\n * @param span the span from which a few values like the root span name and sample rate are extracted.\n *\n * @returns a dynamic sampling context\n */\nexport function getDynamicSamplingContextFromSpan(span: Span): Readonly> {\n  const client = getClient();\n  if (!client) {\n    return {};\n  }\n\n  const dsc = getDynamicSamplingContextFromClient(spanToJSON(span).trace_id || '', client);\n\n  const rootSpan = getRootSpan(span);\n\n  // For core implementation, we freeze the DSC onto the span as a non-enumerable property\n  const frozenDsc = (rootSpan as SpanWithMaybeDsc)[FROZEN_DSC_FIELD];\n  if (frozenDsc) {\n    return frozenDsc;\n  }\n\n  // For OpenTelemetry, we freeze the DSC on the trace state\n  const traceState = rootSpan.spanContext().traceState;\n  const traceStateDsc = traceState && traceState.get('sentry.dsc');\n\n  // If the span has a DSC, we want it to take precedence\n  const dscOnTraceState = traceStateDsc && baggageHeaderToDynamicSamplingContext(traceStateDsc);\n\n  if (dscOnTraceState) {\n    return dscOnTraceState;\n  }\n\n  // Else, we generate it from the span\n  const jsonSpan = spanToJSON(rootSpan);\n  const attributes = jsonSpan.data || {};\n  const maybeSampleRate = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];\n\n  if (maybeSampleRate != null) {\n    dsc.sample_rate = `${maybeSampleRate}`;\n  }\n\n  // We don't want to have a transaction name in the DSC if the source is \"url\" because URLs might contain PII\n  const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];\n\n  // after JSON conversion, txn.name becomes jsonSpan.description\n  const name = jsonSpan.description;\n  if (source !== 'url' && name) {\n    dsc.transaction = name;\n  }\n\n  // How can we even land here with hasTracingEnabled() returning false?\n  // Otel creates a Non-recording span in Tracing Without Performance mode when handling incoming requests\n  // So we end up with an active span that is not sampled (neither positively nor negatively)\n  if (hasTracingEnabled()) {\n    dsc.sampled = String(spanIsSampled(rootSpan));\n  }\n\n  client.emit('createDsc', dsc, rootSpan);\n\n  return dsc;\n}\n\n/**\n * Convert a Span to a baggage header.\n */\nexport function spanToBaggageHeader(span: Span): string | undefined {\n  const dsc = getDynamicSamplingContextFromSpan(span);\n  return dynamicSamplingContextToSentryBaggageHeader(dsc);\n}\n"],"names":["addNonEnumerableProperty","dropUndefinedKeys","DEFAULT_ENVIRONMENT","getClient","spanToJSON","getRootSpan","baggageHeaderToDynamicSamplingContext","SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","hasTracingEnabled","spanIsSampled","dynamicSamplingContextToSentryBaggageHeader"],"mappings":";;;;;;;;;AAcA;AACA;AACA;AACA;AACA,MAAM,gBAAA,GAAmB,YAAY,CAAA;;AAMrC;AACA;AACA;AACO,SAAS,eAAe,CAAC,IAAI,EAAQ,GAAG,EAAyC;AACxF,EAAE,MAAM,gBAAiB,GAAE,IAAK,EAAA;AAChC,EAAEA,8BAAwB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAA;AACnE,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mCAAmC,CAAC,QAAQ,EAAU,MAAM,EAAkC;AAC9G,EAAE,MAAM,OAAQ,GAAE,MAAM,CAAC,UAAU,EAAE,CAAA;AACrC;AACA,EAAE,MAAM,EAAE,SAAS,EAAE,YAAa,GAAE,MAAM,CAAC,MAAM,EAAG,IAAG,EAAE,CAAA;AACzD;AACA,EAAE,MAAM,GAAA,GAAMC,uBAAiB,CAAC;AAChC,IAAI,WAAW,EAAE,OAAO,CAAC,WAAA,IAAeC,6BAAmB;AAC3D,IAAI,OAAO,EAAE,OAAO,CAAC,OAAO;AAC5B,IAAI,UAAU;AACd,IAAI,QAAQ;AACZ,GAAG,CAAE,EAAA;AACL;AACA,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;AAC/B;AACA,EAAE,OAAO,GAAG,CAAA;AACZ,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC,CAAC,IAAI,EAAmD;AACzG,EAA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