Skip to content

Commit be86902

Browse files
Small improvements to traces_sampler configuration. (#13470)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR A small change to make the documentation for `traces_sampler` a bit better. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Shannon Anahata <[email protected]>
1 parent 9cb4d7c commit be86902

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

docs/platforms/python/configuration/options.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ The callback typically gets a second argument (called a "hint") which contains t
246246

247247
</SdkOption>
248248

249+
<PlatformContent includePath="/performance/traces-sampler-config-option" />
250+
249251
## Transport Options
250252

251253
Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.
@@ -331,11 +333,7 @@ If you want to disable all tracing you need to set `traces_sample_rate=None`. In
331333

332334
</SdkOption>
333335

334-
<SdkOption name="traces_sampler" type='function' defaultValue='None'>
335-
336-
A function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering transactions, by returning `0` for those that are unwanted. Either this or `traces_sample_rate` must be defined to enable tracing.
337-
338-
</SdkOption>
336+
<PlatformContent includePath="/performance/traces-sampler-config-option" />
339337

340338
<SdkOption name="trace_propagation_targets" type='list' defaultValue="['.*']">
341339

platform-includes/performance/sampling-function-intro/python.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
To use the sampling function, set the <PlatformIdentifier name="traces-sampler" /> option in your `sentry-sdk.init()` to a function that will accept a <PlatformIdentifier name="sampling-context" /> dictionary and return a sample rate between 0 and 1. For example:
1+
To use the sampling function, set the <PlatformIdentifier name="traces-sampler" /> option in your `sentry-sdk.init()` to a function that will accept a <PlatformIdentifier name="sampling-context" /> dictionary and return a sample rate between `0` and `1`. For example:
22

33
<PlatformContent includePath="performance/traces-sampler-as-sampler" />
44

platform-includes/performance/traces-sampler-as-filter/python.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import sentry_sdk
33
from sentry_sdk.types import SamplingContext
44

55
def traces_sampler(sampling_context: SamplingContext) -> float:
6+
# Examine provided sampling context along with anything in the
7+
# global namespace to compute the sample rate for this transaction
68
if "...":
79
# Drop this transaction, by setting its sample rate to 0%
810
return 0
9-
else:
10-
# Default sample rate for all others (replaces traces_sample_rate)
11-
return 0.1
11+
12+
# Default sample rate for all others (replaces traces_sample_rate)
13+
return 0.1
1214

1315
sentry_sdk.init(
1416
# ...

platform-includes/performance/traces-sampler-as-sampler/python.mdx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,27 @@ import sentry_sdk
33
from sentry_sdk.types import SamplingContext
44

55
def traces_sampler(sampling_context: SamplingContext) -> float:
6-
# Examine provided context data (including parent decision, if any)
7-
# along with anything in the global namespace to compute the sample rate
8-
# or sampling decision for this transaction
9-
106
# Use the parent sampling decision if we have an incoming trace.
117
# Note: we strongly recommend respecting the parent sampling decision,
128
# as this ensures your traces will be complete!
139
parent_sampling_decision = sampling_context.get("parent_sampled")
1410
if parent_sampling_decision is not None:
1511
return float(parent_sampling_decision)
1612

13+
# Examine provided sampling context along with anything in the
14+
# global namespace to compute the sample rate for this transaction
1715
if "...":
1816
# These are important - take a big sample
1917
return 0.5
2018
elif "...":
21-
# These are less important or happen much more frequently - only take 1%
19+
# These are less important - only take 1%
2220
return 0.01
2321
elif "...":
24-
# These aren't something worth tracking - drop all transactions like this
22+
# These aren't worth tracking - drop these transactions
2523
return 0
26-
else:
27-
# Default sample rate
28-
return 0.1
24+
25+
# Default sample rate
26+
return 0.1
2927

3028
sentry_sdk.init(
3129
# ...
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<SdkOption name="traces_sampler" type='function' defaultValue='None'>
2+
3+
A function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering transactions, by returning `0` for those that are unwanted. Either this or `traces_sample_rate` must be defined to enable tracing.
4+
5+
</SdkOption>

0 commit comments

Comments
 (0)