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/python/tracing/configure-sampling/index.mdx
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,16 @@ description: "Learn how to configure sampling in your app."
4
4
sidebar_order: 30
5
5
---
6
6
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.
7
+
Sentry's tracing functionality helps you monitor application performance by capturing distributed traces, attaching attributes, and adding span performance metrics 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
+
9
+
Effective sampling is key to getting the most value from Sentry's performance monitoring while minimizing overhead. The `traces_sampler` function gives you precise control over which transactions to record, allowing you to focus on the most important parts of your application.
8
10
9
11
## Sampling Configuration Options
10
12
11
13
The Python SDK provides two main options for controlling the sampling rate:
12
14
13
15
1. Uniform Sample Rate (`traces_sample_rate`)
16
+
14
17
This option sets a fixed percentage of transactions to be captured:
When the `traces_sampler` function is called, it receives a `sampling_context` object with valuable information to help make sampling decisions:
202
+
When the `traces_sampler` function is called, the Sentry SDK passes a `sampling_context` object with information from the relevant span to help make sampling decisions:
200
203
201
204
```python
202
205
{
@@ -282,8 +285,4 @@ message = {
282
285
queue.send(json.dumps(message))
283
286
```
284
287
285
-
## Conclusion
286
-
287
-
Effective sampling is key to getting the most value from Sentry's performance monitoring while minimizing overhead. The `traces_sampler` function gives you precise control over which transactions to record, allowing you to focus on the most important parts of your application.
288
-
289
288
By implementing a thoughtful sampling strategy, you'll get the performance insights you need without overwhelming your systems or your Sentry quota.
# The span automatically ends here when the 'with' block exits
32
36
```
33
37
34
38
Alternatively, you can create spans manually and control their lifecycle yourself, which gives you more flexibility but also more responsibility:
@@ -41,6 +45,8 @@ try:
41
45
# Your code here
42
46
finally:
43
47
# Remember to always end your spans
48
+
# If you don't call span.finish(), the span will remain open indefinitely,
49
+
# causing memory leaks and incorrect timing data
44
50
span.finish()
45
51
```
46
52
@@ -177,7 +183,7 @@ See <PlatformLink to="/tracing/distributed-tracing/">Distributed Tracing</Platfo
177
183
178
184
### Adding Span Attributes
179
185
180
-
You can capture additional context with span attributes. These can be key-value pairs of various Python types:
186
+
Span attributes customize information you can get through tracing. This information can be found in the traces views in Sentry, once you drill into a span. You can capture additional context with span attributes. These can be key-value pairs of various Python types.
0 commit comments