You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/tracing/configure-sampling/index.mdx
+11-10Lines changed: 11 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,18 +6,20 @@ sidebar_order: 30
6
6
7
7
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.
8
8
9
-
## Sampling Configuration Options
10
-
11
9
The JavaScript SDK provides two main options for controlling the sampling rate:
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.
19
21
20
-
###Sampling Function (`tracesSampler`)
22
+
## Sampling Function (`tracesSampler`)
21
23
22
24
For more granular control, you provide a `tracesSampler` function. This approach allows you to:
23
25
@@ -36,16 +38,16 @@ When the `tracesSampler` function is called, it receives a `samplingContext` obj
36
38
interfaceSamplingContext {
37
39
// Name of the span/transaction
38
40
name:string;
39
-
41
+
40
42
// Initial attributes of the span/transaction
41
43
attributes:SpanAttributes|undefined;
42
-
44
+
43
45
// Whether the parent span was sampled (undefined if no incoming trace)
44
46
parentSampled:boolean|undefined;
45
-
47
+
46
48
// Sample rate from incoming trace (undefined if no incoming trace)
47
49
parentSampleRate:number|undefined;
48
-
50
+
49
51
// Utility function to inherit parent decision or fallback
When multiple sampling mechanisms could apply, Sentry follows this order of precedence:
127
129
128
-
- 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.
130
+
- 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.
129
131
- If no `tracesSampler` is defined, but there is a parent sampling decision from an incoming distributed trace, we use the parent sampling decision
130
132
- If neither of the above, `tracesSampleRate` is used
131
133
- 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
134
136
## Conclusion
135
137
136
138
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.
0 commit comments