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
With `tracesSampleRate` set to `0.25`, approximately 25% of transactions will be recorded and sent to Sentry. This provides an even cross-section of transactions regardless of where in your app they occur.
18
+
With `tracesSampleRate` set to `0.25`, each transaction in your application is randomly sampled with a probability of `0.25`, so you can expect that one in every four transactions will be sent to Sentry.
19
19
20
20
2. Sampling Function (`tracesSampler`)
21
21
22
-
For more granular control, you can use the`tracesSampler` function. This approach allows you to:
22
+
For more granular control, you provide a`tracesSampler` function. This approach allows you to:
23
23
24
24
- Apply different sampling rates to different types of transactions
25
25
- Filter out specific transactions entirely
@@ -28,6 +28,29 @@ For more granular control, you can use the `tracesSampler` function. This approa
- `attributes`: Initial tags and attributes set on the transaction
126
-
- `parentSampled`: Whether the parent transaction was sampled (for distributed tracing)
127
-
- `parentSampleRate`: The sample rate used in the parent transaction
128
-
- `inheritOrSampleWith`: A utility function to handle inheritance logic (recommended)
129
-
130
-
## Inheritance in Distributed Tracing
131
-
132
-
In distributed systems, trace information is propagated between services. The inheritOrSampleWith function simplifies handling parent sampling decisions:
// Otherwise inherit parent sampling decision or fall back to 0.1
144
-
returninheritOrSampleWith(0.1);
145
-
}
146
-
```
147
-
This approach ensures consistent sampling decisions across your entire distributed trace. All transactions in a given trace will share the same sampling decision, preventing broken or incomplete traces.
148
-
149
-
**Note:** The `inheritOrSampleWith` helper was introduced in version 9 of the SDK. For earlier versions, you can implement similar logic manually using the `parentSampled` property.
150
-
151
122
## Sampling Decision Precedence
152
123
153
124
When multiple sampling mechanisms could apply, Sentry follows this order of precedence:
154
125
155
-
- If `tracesSampler` is defined, its decision is used (can consider parent sampling)
156
-
- If no `tracesSampler` but parent sampling is available, parent decision is used
126
+
- If a sampling decision is passed to `startSpan`, that decision is used
127
+
- 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.
128
+
- If no `tracesSampler` is defined, but there is a parent sampling decision from an incoming distributed trace, we use the parent sampling decision
157
129
- If neither of the above, `tracesSampleRate` is used
158
-
- If none of the above are set, no transactions are sampled (0%)
159
-
160
-
## How Sampling Propagates in Distributed Traces
161
-
162
-
Sentry uses a "head-based" sampling approach:
163
-
164
-
- A sampling decision is made in the originating service (the "head")
165
-
- This decision is propagated to all downstream services via HTTP headers
166
-
167
-
The two key headers are:
168
-
- `sentry-trace`: Contains trace ID, span ID, and sampling decision
169
-
- `baggage`: Contains additional trace metadata including sample rate
170
-
171
-
Sentry automatically attaches these headers to outgoing HTTP requests when using the `browserTracingIntegration`. For other communication channels like WebSockets, you can manually propagate trace information:
// Add to your custom request (example using WebSocket)
180
-
webSocket.send(JSON.stringify({
181
-
message:"Your data here",
182
-
metadata: {
183
-
sentryTrace: sentryTraceHeader,
184
-
baggage: sentryBaggageHeader
185
-
}
186
-
}));
187
-
```
130
+
- If none of the above are set, no transactions are sampled. This is equivalent to setting `tracesSampleRate` to `0.0`.
188
131
189
132
## Conclusion
190
133
191
-
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.
192
-
193
-
By implementing a thoughtful sampling strategy, you'll get the performance insights you need without overwhelming your systems or your Sentry quota.
134
+
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