From 724a0db0111b7921cfea62202b7eb1fd529122ec Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 4 Apr 2025 11:25:04 +0200 Subject: [PATCH 1/2] ref(js): Small fixes to configure sampling structure --- .../tracing/configure-sampling/index.mdx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx b/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx index 86173b4b592e7e..bb77209f7e6cbf 100644 --- a/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx +++ b/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx @@ -6,18 +6,20 @@ sidebar_order: 30 Sentry's tracing functionality helps you monitor application performance by capturing distributed traces, attaching attributes, and span performance across your application. However, Capturing traces for every transaction can generate significant volumes of data. Sampling allows you to control the amount of spans that are sent to Sentry from your application. -## Sampling Configuration Options - The JavaScript SDK provides two main options for controlling the sampling rate: -1. Uniform Sample Rate (`tracesSampleRate`) +1. [Uniform Sample Rate](#uniform-sample-rate-tracessamplerate) +2. [Sampling Function](#sampling-function-tracessampler) + +## Uniform Sample Rate (`tracesSampleRate`) + `tracesSampleRate` is floating point value 0.0 and 1.0, which controls the probability that a transaction will be sampled. With `tracesSampleRate` set to `0.25`, each transaction in your application is randomly sampled with a probability of 25%, so you can expect that one in every four transactions will be sent to Sentry. -### Sampling Function (`tracesSampler`) +## Sampling Function (`tracesSampler`) For more granular control, you provide a `tracesSampler` function. This approach allows you to: @@ -36,16 +38,16 @@ When the `tracesSampler` function is called, it receives a `samplingContext` obj interface SamplingContext { // Name of the span/transaction name: string; - + // Initial attributes of the span/transaction attributes: SpanAttributes | undefined; - + // Whether the parent span was sampled (undefined if no incoming trace) parentSampled: boolean | undefined; - + // Sample rate from incoming trace (undefined if no incoming trace) parentSampleRate: number | undefined; - + // Utility function to inherit parent decision or fallback inheritOrSampleWith: (fallbackRate: number) => number; } @@ -125,7 +127,7 @@ tracesSampler: (samplingContext) => { When multiple sampling mechanisms could apply, Sentry follows this order of precedence: -- If `tracesSampler` is defined, its decision is used. Although the `tracesSampler` can override the parent sampling decision, most users will want to ensure their `tracesSampler` respects the parent sampling decision. +- If `tracesSampler` is defined, its decision is used. Although the `tracesSampler` can override the parent sampling decision, most users will want to ensure their `tracesSampler` respects the parent sampling decision. - If no `tracesSampler` is defined, but there is a parent sampling decision from an incoming distributed trace, we use the parent sampling decision - If neither of the above, `tracesSampleRate` is used - If `tracesSampleRate` is set to 0, no spans will be sampled, and no downstream spans will be sampled either since they inherit the parent sampling decision @@ -134,4 +136,3 @@ When multiple sampling mechanisms could apply, Sentry follows this order of prec ## Conclusion Effective sampling is key to getting the most value from Sentry's performance monitoring while minimizing overhead. The `tracesSampler` function gives you precise control over which transactions to record, allowing you to focus on the most important parts of your application. - From 2c48a8909380a8b9d066a96e1ac183cd0db4a954 Mon Sep 17 00:00:00 2001 From: Cody De Arkland Date: Sun, 6 Apr 2025 23:31:22 -0700 Subject: [PATCH 2/2] Update docs/platforms/javascript/common/tracing/configure-sampling/index.mdx Co-authored-by: Sigrid Huemer <32902192+s1gr1d@users.noreply.github.com> --- .../javascript/common/tracing/configure-sampling/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx b/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx index bb77209f7e6cbf..a4a8d00c537633 100644 --- a/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx +++ b/docs/platforms/javascript/common/tracing/configure-sampling/index.mdx @@ -8,7 +8,7 @@ Sentry's tracing functionality helps you monitor application performance by capt The JavaScript SDK provides two main options for controlling the sampling rate: -1. [Uniform Sample Rate](#uniform-sample-rate-tracessamplerate) +1. [Uniform Sample Rate](#uniform-sample-rate-tracessamplerate) (recommended) 2. [Sampling Function](#sampling-function-tracessampler) ## Uniform Sample Rate (`tracesSampleRate`)