Set Up Profiling
With profiling, Sentry tracks your software's performance by sampling your program's call stack in a variety of environments. This feature collects function-level information about your code and enables you to fine-tune your program's performance. Sentry's profiler captures function calls and their exact locations, aggregates them, and shows you the most common code paths of your program. This highlights areas you could optimize to help increase both the performance of your code and increase user satisfaction, as well as drive down costs.
Enable Performance Monitoring
Profiling depends on Sentry’s performance monitoring product being enabled beforehand. To enable performance monitoring in the SDK:
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
traces_sample_rate=1.0,
)
Check out the performance setup documentation for more detailed information on how to configure sampling. Setting the sample rate to 1.0 means all transactions will be captured.
Enable Profiling
Python profiling is available starting in SDK version 1.18.0
.
import sentry_sdk
def profiles_sampler(sampling_context):
# ...
# return a number between 0 and 1 or a boolean
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
traces_sample_rate=1.0,
# To set a uniform sample rate
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production,
profiles_sample_rate=1.0,
# Alternatively, to control sampling dynamically
profiles_sampler=profiles_sampler
)
The profiles_sample_rate
setting is relative to the traces_sample_rate
setting.
Upgrading from older SDK versions
The feature was experimental prior to version 1.17.0
. To update to the latest SDK, remove profiles_sample_rate
from _experiments
and set it in the top-level options.
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
traces_sample_rate=1.0,
_experiments={
"profiles_sample_rate": 1.0, # for versions before 1.17.0
},
)
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- pypi:sentry-sdk
- Version:
- 1.40.0
- Repository:
- https://github.com/getsentry/sentry-python
- API Documentation:
- https://getsentry.github.io/sentry-python/