diff --git a/platform-includes/performance/traces-sampler-as-sampler/javascript.mdx b/platform-includes/performance/traces-sampler-as-sampler/javascript.mdx index 6c981ca0561a4..82fc774389ba3 100644 --- a/platform-includes/performance/traces-sampler-as-sampler/javascript.mdx +++ b/platform-includes/performance/traces-sampler-as-sampler/javascript.mdx @@ -1,25 +1,41 @@ -```javascript +```typescript +// The shape of samplingContext that is passed to the tracesSampler function +interface SamplingContext { + // Name of the span + name: string; + // Initial attributes of the span + attributes: SpanAttributes | undefined; + // If the parent span was sampled - undefined if there is no parent span + parentSampled: boolean | undefined; +} + Sentry.init({ // ... - tracesSampler: samplingContext => { - // Examine provided context data (including parent decision, if any) along - // with anything in the global namespace to compute the sample rate or - // sampling decision for this transaction + tracesSampler: ({ name, attributes, parentSampled }) => { + // Do not sample health checks ever + if (name.includes("healthcheck")) { + // Drop this completelty, by setting its sample rate to 0% + return 0; + } - if ("...") { - // These are important - take a big sample + // These are important - take a big sample + if (name.includes("auth")) { return 1; - } else if ("...") { - // These are less important or happen much more frequently - only take 1% + } + + // These are less important or happen much more frequently - only take 1% + if (name.includes("comment")) { return 0.01; - } else if ("...") { - // These aren't something worth tracking - drop all transactions like this - return 0; - } else { - // Default sample rate - return 0.5; } - }; + + // Continue trace decision, if there is any parentSampled information + if (typeof parentSampled === "boolean") { + return parentSampled; + } + + // Else, use default sample rate + return 0.5; + }, }); ```