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

package.build.cjs.utils.traceData.js.map Maven / Gradle / Ivy

There is a newer version: 8.39.0
Show newest version
{"version":3,"file":"traceData.js","sources":["../../../src/utils/traceData.ts"],"sourcesContent":["import type { SerializedTraceData } from '@sentry/types';\nimport {\n  TRACEPARENT_REGEXP,\n  dynamicSamplingContextToSentryBaggageHeader,\n  generateSentryTraceHeader,\n  logger,\n} from '@sentry/utils';\nimport { getAsyncContextStrategy } from '../asyncContext';\nimport { getMainCarrier } from '../carrier';\nimport { getClient, getCurrentScope } from '../currentScopes';\nimport { getDynamicSamplingContextFromClient, getDynamicSamplingContextFromSpan } from '../tracing';\nimport { getActiveSpan, getRootSpan, spanToTraceHeader } from './spanUtils';\n\n/**\n * Extracts trace propagation data from the current span or from the client's scope (via transaction or propagation\n * context) and serializes it to `sentry-trace` and `baggage` values to strings. These values can be used to propagate\n * a trace via our tracing Http headers or Html `` tags.\n *\n * This function also applies some validation to the generated sentry-trace and baggage values to ensure that\n * only valid strings are returned.\n *\n * @returns an object with the tracing data values. The object keys are the name of the tracing key to be used as header\n * or meta tag name.\n */\nexport function getTraceData(): SerializedTraceData {\n  const carrier = getMainCarrier();\n  const acs = getAsyncContextStrategy(carrier);\n  if (acs.getTraceData) {\n    return acs.getTraceData();\n  }\n\n  const client = getClient();\n  const scope = getCurrentScope();\n  const span = getActiveSpan();\n\n  const { dsc, sampled, traceId } = scope.getPropagationContext();\n  const rootSpan = span && getRootSpan(span);\n\n  const sentryTrace = span ? spanToTraceHeader(span) : generateSentryTraceHeader(traceId, undefined, sampled);\n\n  const dynamicSamplingContext = rootSpan\n    ? getDynamicSamplingContextFromSpan(rootSpan)\n    : dsc\n      ? dsc\n      : client\n        ? getDynamicSamplingContextFromClient(traceId, client)\n        : undefined;\n\n  const baggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);\n\n  const isValidSentryTraceHeader = TRACEPARENT_REGEXP.test(sentryTrace);\n  if (!isValidSentryTraceHeader) {\n    logger.warn('Invalid sentry-trace data. Cannot generate trace data');\n    return {};\n  }\n\n  const validBaggage = isValidBaggageString(baggage);\n  if (!validBaggage) {\n    logger.warn('Invalid baggage data. Not returning \"baggage\" value');\n  }\n\n  return {\n    'sentry-trace': sentryTrace,\n    ...(validBaggage && { baggage }),\n  };\n}\n\n/**\n * Tests string against baggage spec as defined in:\n *\n * - W3C Baggage grammar: https://www.w3.org/TR/baggage/#definition\n * - RFC7230 token definition: https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6\n *\n * exported for testing\n */\nexport function isValidBaggageString(baggage?: string): boolean {\n  if (!baggage || !baggage.length) {\n    return false;\n  }\n  const keyRegex = \"[-!#$%&'*+.^_`|~A-Za-z0-9]+\";\n  const valueRegex = '[!#-+-./0-9:<=>?@A-Z\\\\[\\\\]a-z{-}]+';\n  const spaces = '\\\\s*';\n  // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor -- RegExp for readability, no user input\n  const baggageRegex = new RegExp(\n    `^${keyRegex}${spaces}=${spaces}${valueRegex}(${spaces},${spaces}${keyRegex}${spaces}=${spaces}${valueRegex})*$`,\n  );\n  return baggageRegex.test(baggage);\n}\n"],"names":["carrier","getMainCarrier","getAsyncContextStrategy","getClient","getCurrentScope","getActiveSpan","getRootSpan","spanToTraceHeader","generateSentryTraceHeader","dynamicSamplingContext","getDynamicSamplingContextFromSpan","getDynamicSamplingContextFromClient","dynamicSamplingContextToSentryBaggageHeader","TRACEPARENT_REGEXP","logger"],"mappings":";;;;;;;;;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,YAAY,GAAwB;AACpD,EAAE,MAAMA,SAAA,GAAUC,sBAAc,EAAE,CAAA;AAClC,EAAE,MAAM,GAAI,GAAEC,6BAAuB,CAACF,SAAO,CAAC,CAAA;AAC9C,EAAE,IAAI,GAAG,CAAC,YAAY,EAAE;AACxB,IAAI,OAAO,GAAG,CAAC,YAAY,EAAE,C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