---
title: "Tracing"
description: "Follow requests, background jobs, and agent runs across services, and see where they fail or slow down."
url: https://docs.sentry.io/platforms/python/tracing/
---

# Set Up Tracing for Python

## Set up with Sentry CLI

Set up the Sentry Python SDK with the Sentry CLI. Install the CLI with one of these commands, then follow the Sentry CLI docs to finish setup.

**cURL**

```bash
curl https://cli.sentry.dev/install -fsS | bash
```

**PowerShell**

```powershell
irm https://cli.sentry.dev/install.ps1 | iex
```

**Homebrew**

```bash
brew install getsentry/tools/sentry
```

**npx**

```bash
npx sentry@latest
```

[Learn more about the Sentry CLI](https://cli.sentry.dev/)

With [tracing](https://docs.sentry.io/concepts/key-terms/tracing.md), Sentry follows requests, background jobs, and [agent runs](https://docs.sentry.io/product/agents.md) across services so you can see where they fail or slow down.

## [Prerequisites](https://docs.sentry.io/platforms/python/tracing.md#prerequisites)

* You have the [Python SDK installed](https://docs.sentry.io/platforms/python.md) (version 0.11.2 or higher)

## [Configure](https://docs.sentry.io/platforms/python/tracing.md#configure)

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.)

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },
    # Set traces_sample_rate to 1.0 to capture 100%
    # of service spans 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](https://docs.sentry.io/platforms/python/configuration/options.md#tracing-options), how to use the [traces\_sampler](https://docs.sentry.io/platforms/python/configuration/sampling.md#setting-a-sampling-function) function, or how to [sample transactions](https://docs.sentry.io/platforms/python/configuration/sampling.md#sampling-transaction-events).

## [Agent Tracing](https://docs.sentry.io/platforms/python/tracing.md#agent-tracing)

If you're building with agents or LLMs, the same trace can include the agent run, so you can see the model calls, tool executions, and where the run failed or slowed down. With tracing already enabled, the Python SDK automatically instruments supported libraries like OpenAI, Anthropic, LangChain, and others.

[Set up Agent Tracing](https://docs.sentry.io/platforms/python/agent-tracing.md) to get started.

## [Next Steps](https://docs.sentry.io/platforms/python/tracing.md#next-steps)

* #### [Span Lifecycle](https://docs.sentry.io/platforms/python/tracing/span-lifecycle.md)

  Learn how to add attributes to spans in Sentry to monitor performance and debug applications.

* #### [Set Up Distributed Tracing](https://docs.sentry.io/platforms/python/tracing/distributed-tracing.md)

  Learn how to connect events across applications/services using the Sentry Python SDK.

* #### [Configure Sampling](https://docs.sentry.io/platforms/python/tracing/configure-sampling.md)

  Learn how to configure sampling in your app using the Sentry Python SDK.

* #### [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md)

  Learn how to use stream mode to send spans to Sentry as they finish, removing the 1,000-span limit and making trace data visible sooner.

* #### [Instrumentation](https://docs.sentry.io/platforms/python/tracing/instrumentation.md)

  Learn what Sentry instruments automatically, and how to configure spans to capture tracing data on any action in your app.

* #### [Tracing Troubleshooting](https://docs.sentry.io/platforms/python/tracing/troubleshooting.md)

  Learn how to troubleshoot your tracing setup.

## Pages in this section

- [Span Lifecycle](https://docs.sentry.io/platforms/python/tracing/span-lifecycle.md)
- [Set Up Distributed Tracing](https://docs.sentry.io/platforms/python/tracing/distributed-tracing.md)
- [Configure Sampling](https://docs.sentry.io/platforms/python/tracing/configure-sampling.md)
- [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md)
- [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans__v2.x.md)
- [Instrumentation](https://docs.sentry.io/platforms/python/tracing/instrumentation.md)
- [Troubleshooting](https://docs.sentry.io/platforms/python/tracing/troubleshooting.md)
- [Troubleshooting](https://docs.sentry.io/platforms/python/tracing/troubleshooting__v2.x.md)
