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 25%, so you can expect that one in every four transactions will be sent to Sentry.
19
19
20
20
### 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,7 +28,30 @@ For more granular control, you can use the `tracesSampler` function. This approa
- `attributes`: Initial tags and attributes set on the transaction
128
-
- `parentSampled`: Whether the parent transaction was sampled (for distributed tracing)
129
-
- `parentSampleRate`: The sample rate used in the parent transaction
130
-
- `inheritOrSampleWith`: A utility function to handle inheritance logic (recommended)
131
-
132
-
## Inheritance in Distributed Tracing
133
-
134
-
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
146
-
returninheritOrSampleWith(0.1);
147
-
}
148
-
```
149
-
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.
150
-
151
-
**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.
152
-
153
124
## Sampling Decision Precedence
154
125
155
126
When multiple sampling mechanisms could apply, Sentry follows this order of precedence:
156
127
157
-
- If `tracesSampler` is defined, its decision is used (can consider parent sampling)
158
-
- If no `tracesSampler` but parent sampling is available, parent decision is used
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.
129
+
- If no `tracesSampler`is defined, but there is a parent sampling decision from an incoming distributed trace, we use the parent sampling decision
159
130
- If neither of the above, `tracesSampleRate` is used
160
-
- If none of the above are set, no transactions are sampled (0%)
161
-
162
-
## How Sampling Propagates in Distributed Traces
163
-
164
-
Sentry uses a "head-based" sampling approach:
165
-
166
-
- A sampling decision is made in the originating service (the "head")
167
-
- This decision is propagated to all downstream services via HTTP headers
168
-
169
-
The two key headers are:
170
-
- `sentry-trace`: Contains trace ID, span ID, and sampling decision
171
-
- `baggage`: Contains additional trace metadata including sample rate
172
-
173
-
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)
182
-
webSocket.send(JSON.stringify({
183
-
message:"Your data here",
184
-
metadata: {
185
-
sentryTrace: sentryTraceHeader,
186
-
baggage: sentryBaggageHeader
187
-
}
188
-
}));
189
-
```
131
+
- 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
132
+
- If none of the above are set, no transactions are sampled and tracing will be disabled
190
133
191
134
## Conclusion
192
135
193
136
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.
194
137
195
-
By implementing a thoughtful sampling strategy, you'll get the performance insights you need without overwhelming your systems or your Sentry quota.
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/tracing/distributed-tracing/index.mdx
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,3 +60,32 @@ Server-side SDKs handle traces automatically on a per-request basis. This means
60
60
</PlatformCategorySection>
61
61
62
62
If necessary, you can override the default trace duration by [manually starting a new trace](./custom-instrumentation#starting-a-new-trace).
63
+
64
+
## How Sampling Propagates in Distributed Traces
65
+
66
+
Sentry uses a "head-based" sampling approach:
67
+
68
+
- A sampling decision is made in the originating service (the "head")
69
+
- This decision is propagated to all downstream services
70
+
71
+
The two key headers are:
72
+
-`sentry-trace`: Contains trace ID, span ID, and sampling decision
73
+
-`baggage`: Contains additional trace metadata including sample rate
74
+
75
+
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:
The frontend span tracks job submission and monitoring, while the backend span captures queue management and processing details. The distributed trace provides visibility into the entire job lifecycle, enabling you to:
421
-
422
-
- Monitor end-to-end job processing times and success rates
423
-
- Track queue health and worker resource utilization
424
-
- Identify bottlenecks in specific processing stages
425
-
- Analyze job scheduling efficiency and queue wait times
426
-
- Optimize resource allocation based on job characteristics
427
-
428
-
For more information about implementing these examples effectively, see our <PlatformLinkto="/tracing/span-metrics/">Span Metrics guide</PlatformLink> which includes detailed best practices and implementation guidelines.
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/tracing/span-metrics/index.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,11 +41,11 @@ When adding metrics as span attributes:
41
41
42
42
- Use consistent naming conventions (for example, `category.metric_name`)
43
43
- Keep attribute names concise but descriptive
44
-
- Use appropriate data types (string, number, boolean, or (non-mixed) arrays of these types)
44
+
- Use appropriate data types (string, number, boolean, or an array containing only one of these types)
45
45
46
46
## Creating Dedicated Metric Spans
47
47
48
-
For more detailed operations, task, or process tracking, you can create custom dedicated spans that focus on specific metrics or attributes that you want to track. This approach provides better discoverability and more precise span configurations, however it can also appear to create more noise in your trace waterfall.
48
+
For more detailed operations, tasks, or process tracking, you can create custom dedicated spans that focus on specific metrics or attributes that you want to track. This approach provides better discoverability and more precise span configurations, however it can also create more noise in your trace waterfall.
0 commit comments