Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions docs/platforms/python/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ The callback typically gets a second argument (called a "hint") which contains t

</SdkOption>

<PlatformContent includePath="/performance/traces-sampler-config-option" />

## Transport Options

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

</SdkOption>

<SdkOption name="traces_sampler" type='function' defaultValue='None'>

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.

</SdkOption>
<PlatformContent includePath="/performance/traces-sampler-config-option" />

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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:
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:

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import sentry_sdk
from sentry_sdk.types import SamplingContext

def traces_sampler(sampling_context: SamplingContext) -> float:
# Examine provided sampling context along with anything in the
# global namespace to compute the sample rate for this transaction
if "...":
# Drop this transaction, by setting its sample rate to 0%
return 0
else:
# Default sample rate for all others (replaces traces_sample_rate)
return 0.1

# Default sample rate for all others (replaces traces_sample_rate)
return 0.1

sentry_sdk.init(
# ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ import sentry_sdk
from sentry_sdk.types import SamplingContext

def traces_sampler(sampling_context: SamplingContext) -> float:
# Examine provided context data (including parent decision, if any)
# along with anything in the global namespace to compute the sample rate
# or sampling decision for this transaction

# Use the parent sampling decision if we have an incoming trace.
# Note: we strongly recommend respecting the parent sampling decision,
# as this ensures your traces will be complete!
parent_sampling_decision = sampling_context.get("parent_sampled")
if parent_sampling_decision is not None:
return float(parent_sampling_decision)

# Examine provided sampling context along with anything in the
# global namespace to compute the sample rate for this transaction
if "...":
# These are important - take a big sample
return 0.5
elif "...":
# These are less important or happen much more frequently - only take 1%
# These are less important - only take 1%
return 0.01
elif "...":
# These aren't something worth tracking - drop all transactions like this
# These aren't worth tracking - drop these transactions
return 0
else:
# Default sample rate
return 0.1

# Default sample rate
return 0.1

sentry_sdk.init(
# ...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<SdkOption name="traces_sampler" type='function' defaultValue='None'>

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.

</SdkOption>