Set Up Tracing for Python
With Tracing, Sentry tracks your software performance, measuring metrics like throughput and latency, and displays the impact of errors across multiple systems.
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry Python SDK.- You have the Python SDK installed (version 0.11.2 or higher)
To enable tracing in your application, adjust the traces_sample_rate based on the number of trace samples you want to send to Sentry by adding the highlighted code snippet below. (Setting a value of 1.0 will send 100% of your traces.)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
+ traces_sample_rate=1.0,
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
+ traces_sample_rate=1.0,
)
If you’re adopting Tracing in a high-throughput environment, we recommend testing prior to deployment to ensure that your service’s performance characteristics maintain expectations.
Learn more about tracing options, how to use the traces_sampler function, or how to sample transactions.
If you're building with agents or LLMs, you can extend your tracing setup to capture agent workflows, model calls, tool executions, and token usage. With tracing already enabled, the Python SDK automatically instruments supported libraries like OpenAI, Anthropic, LangChain, and others.
Set up Agent Tracing to get started.
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").