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

package.build.esm.tracing.sampling.js.map Maven / Gradle / Ivy

There is a newer version: 8.39.0
Show newest version
{"version":3,"file":"sampling.js","sources":["../../../src/tracing/sampling.ts"],"sourcesContent":["import type { Options, SamplingContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { DEBUG_BUILD } from '../debug-build';\nimport { hasTracingEnabled } from '../utils/hasTracingEnabled';\nimport { parseSampleRate } from '../utils/parseSampleRate';\n\n/**\n * Makes a sampling decision for the given options.\n *\n * Called every time a root span is created. Only root spans which emerge with a `sampled` value of `true` will be\n * sent to Sentry.\n */\nexport function sampleSpan(\n  options: Pick,\n  samplingContext: SamplingContext,\n): [sampled: boolean, sampleRate?: number] {\n  // nothing to do if tracing is not enabled\n  if (!hasTracingEnabled(options)) {\n    return [false];\n  }\n\n  // we would have bailed already if neither `tracesSampler` nor `tracesSampleRate` nor `enableTracing` were defined, so one of these should\n  // work; prefer the hook if so\n  let sampleRate;\n  if (typeof options.tracesSampler === 'function') {\n    sampleRate = options.tracesSampler(samplingContext);\n  } else if (samplingContext.parentSampled !== undefined) {\n    sampleRate = samplingContext.parentSampled;\n  } else if (typeof options.tracesSampleRate !== 'undefined') {\n    sampleRate = options.tracesSampleRate;\n  } else {\n    // When `enableTracing === true`, we use a sample rate of 100%\n    sampleRate = 1;\n  }\n\n  // Since this is coming from the user (or from a function provided by the user), who knows what we might get.\n  // (The only valid values are booleans or numbers between 0 and 1.)\n  const parsedSampleRate = parseSampleRate(sampleRate);\n\n  if (parsedSampleRate === undefined) {\n    DEBUG_BUILD && logger.warn('[Tracing] Discarding transaction because of invalid sample rate.');\n    return [false];\n  }\n\n  // if the function returned 0 (or false), or if `tracesSampleRate` is 0, it's a sign the transaction should be dropped\n  if (!parsedSampleRate) {\n    DEBUG_BUILD &&\n      logger.log(\n        `[Tracing] Discarding transaction because ${\n          typeof options.tracesSampler === 'function'\n            ? 'tracesSampler returned 0 or false'\n            : 'a negative sampling decision was inherited or tracesSampleRate is set to 0'\n        }`,\n      );\n    return [false, parsedSampleRate];\n  }\n\n  // Now we roll the dice. Math.random is inclusive of 0, but not of 1, so strict < is safe here. In case sampleRate is\n  // a boolean, the < comparison will cause it to be automatically cast to 1 if it's true and 0 if it's false.\n  const shouldSample = Math.random() < parsedSampleRate;\n\n  // if we're not going to keep it, we're done\n  if (!shouldSample) {\n    DEBUG_BUILD &&\n      logger.log(\n        `[Tracing] Discarding transaction because it's not included in the random sample (sampling rate = ${Number(\n          sampleRate,\n        )})`,\n      );\n    return [false, parsedSampleRate];\n  }\n\n  return [true, parsedSampleRate];\n}\n"],"names":[],"mappings":";;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU;AAC1B,EAAE,OAAO;AACT,EAAE,eAAe;AACjB,EAA2C;AAC3C;AACA,EAAE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE;AACnC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAA;AAClB,GAAE;AACF;AACA;AACA;AACA,EAAE,IAAI,UAAU,CAAA;AAChB,EAAE,IAAI,OAAO,OAAO,CAAC,aAAc,KAAI,UAAU,EAAE;AACnD,IAAI,aAAa,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAA;AACvD,GAAE,MAAO,IAAI,eAAe,CAAC,aAAA,KAAkB,SAAS,EAAE;AAC1D,IAAI,UAAW,GAAE,eAAe,CAAC,aAAa,CAAA;AAC9C,GAAE,MAAO,IAAI,OAAO,OAAO,CAAC,gBAAA,KAAqB,WAAW,EAAE;AAC9D,IAAI,UAAW,GAAE,OAAO,CAAC,gBAAgB,CAAA;AACzC,SAAS;AACT;AACA,IAAI,UAAA,GAAa,CAAC,CAAA;AAClB,GAAE;AACF;AACA;AACA;AACA,EAAE,MAAM,gBAAiB,GAAE,eAAe,CAAC,UAAU,CAAC,CAAA;AACtD;AACA,EAAE,IAAI,gBAAiB,KAAI,SAAS,EAAE;AACtC,IAAI,eAAe,MA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