---
title: "Prettier API, better PII controls: Python SDK 3.0 is available"
description: "Python SDK 3.0 replaces transactions with a span-only tracing API, streams spans by default, and swaps send_default_pii for per-category data controls."
url: "https://blog.sentry.io/python-sdk-3/"
canonical_url: "https://blog.sentry.io/python-sdk-3/"
authors: ["Ivana Kellyer"]
published: "2026-12-03"
category: "Product Updates"
---

# Prettier API, better PII controls: Python SDK 3.0 is available

Ever felt like the custom tracing API of the Sentry Python SDK was a little peculiar? Ever needed more fine-grained controls over what data is collected? Version 3.0 has you covered. It replaces transactions with a simpler span-only API, and it swaps `send_default_pii` for per-category data collection settings.

## Spans are streamed now

In SDK versions before 3.0, spans were tightly bound to their parent transaction. The transaction first had to finish for its span tree to be collected, packaged and sent over the wire.

This had multiple undesirable consequences. To cap memory use, we had a limit on how many spans there could be in a transaction, and once we’d hit that, we would discard any additional spans. And in case your span tree was especially big, or if it contained spans with especially large data attached to them, the whole transaction envelope might have been getting dropped because of size limits.

In 3.0, we switched to streaming spans by default. As soon as a span finishes, it’s queued up for sending. The span tree is reconstructed on the server, freeing up resources on your machine.

To enable span streaming, you can either upgrade to 3.0, or if you’re on version 2.66+ of the Python SDK, you can opt in by setting `trace_lifecycle="stream"` in your SDK options.

## Custom tracing API without the cruft

Our custom tracing API grew over the years, and as with any organically grown API, its ergonomics suffered from features being tacked onto it. Starting in version 2.66 of the Python SDK, we shipped span streaming as an opt-in feature, and it came with its own overhauled API. In 3.0, this API is now the default.

The biggest change? There are no transactions and no `start_child()` anymore. The SDK automatically promotes spans that don’t have a parent span to top-level spans. You don’t have to think about what kind of span you want to start. You also don’t need to remember what arguments `start_span()` and `start_transaction()` take. `start_span()` is all you need.

Also, spans don’t carry multiple different buckets of information like data or tags anymore. Instead, everything is an attribute, just like on [logs](https://sentry.io/product/logs/) and [metrics](https://sentry.io/product/metrics/). You can set custom attributes either at span start, or later via `span.set_attribute()` or `span.set_attributes()`.

```py
import sentry_sdk
# checkout_span will be the top-level span here
with sentry_sdk.start_span(name="checkout") as checkout_span:
   # authorization_span is a child span of checkout_span
   with sentry_sdk.start_span(name="authorizing", attributes={"payment.provider": "provider"}) as authorization_span:
       authorize()
       authorization_span.set_attribute("payment.success", True)
```

The trace propagation API got some much-needed love as well. Ever wondered why `sentry_sdk.continue_trace()` returned a transaction that you then had to start manually? We did, too. In the span streaming world, `sentry_sdk.continue_trace()` is a function call that doesn’t return anything, but sets the inner state of the SDK’s propagation context so that any span you start after it will continue the incoming trace you’ve provided.

There’s now also a quality-of-life improvement in the form of `sentry_sdk.new_trace()`, in case you want to reset trace propagation data and have the next span be the head of its own trace.

```py
import sentry_sdk

sentry_sdk.continue_trace({
    "sentry-trace": "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0be902b7-1",
    "baggage": "sentry-trace_id=...",
})

with sentry_sdk.start_span(name="payment service") as payment_span:
    # payment_span continues the incoming trace
    ...

sentry_sdk.new_trace()

with sentry_sdk.start_span(name="custom span") as custom_span:
    # custom_span will be the head span of a brand new trace
```

Have a look at the [span streaming docs](https://docs.sentry.io/platforms/python/tracing/streamed-spans/) for the full rundown of the changes to the tracing API.

If you’re on version 2.x of the Python SDK, the above API is accessible under `sentry_sdk.traces.*`. In order to use it, you need to enable span streaming by setting `trace_lifecycle="stream"` in your SDK options.

## Granular PII controls instead of one magic boolean

With the SDK supporting all kinds of frameworks and libraries, the single `send_default_pii` toggle wasn’t cutting it anymore. The configuration was too broad with little possibility to adjust, with optional overrides scattered throughout the SDK in different integrations.

3.0 removes `send_default_pii` and replaces it with `data_collection`, which lets you control data capture per category. In categories where it makes sense, like headers or query parameters, you can apply targeted filtering rules, superseding the scrubber, which was removed in 3.0.

```py
import sentry_sdk

sentry_sdk.init(
    data_collection={
        "gen_ai": {"inputs": True, "outputs": True},
        "http_headers": {
            "request": {
                "mode": "denylist",
                "terms": ["forwarded", "-ip", "remote-", "via", "-user"],
            },
        },
    },
)
```

Check out the [data collection docs](https://docs.sentry.io/platforms/python/data-management/data-collected/) for all the possible knobs and buttons that can be tweaked.

## The rest: AWS improvements, better support for chained exceptions, and more

In 3.0, traces now carry over from boto3 calls into Lambda functions they invoke, and through SQS and SNS messages. Lambda spans include more context, such as the trigger type, account, region and function version. SQS and SNS handlers get a `queue.process` span, so they show up in the Queues view. Check out [AWS Lambda tracing with the Python SDK](https://blog.sentry.io/sentry-python-aws-lambda/) for additional details.

Chained exceptions are now reported more completely. Exception groups that appear inside a chain, as a `__cause__` or `__context__`, are fully expanded, whereas before they could come through incomplete.

## Getting started with 3.0

Install `sentry-sdk` version 3.x with your package manager of choice:

```sh
uv add 'sentry-sdk>=3'
```

If you’re upgrading from an older major version, have a look at the [migration guide](https://docs.sentry.io/platforms/python/migration/2.x-to-3.x) before bumping the package version. The release contains breaking changes, so adapting your code might be necessary.

If you’re setting up fresh, add this to your app, as early as possible. Make sure to replace `<YOUR DSN HERE>` with your actual DSN – you can find it in your Sentry organization settings.

```py
import sentry_sdk

sentry_sdk.init(
    dsn="<YOUR DSN HERE>",

    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },

    # Set to 1.0 to capture 100% of traces.
    # We recommend reducing this value in production.
    traces_sample_rate=1.0,

    # Set to 1.0 to profile 100% of sessions.
    profile_session_sample_rate=1.0,
    # Profiles are collected while there is an active span.
    profile_lifecycle="trace",
)
```

If you’re using one of [the frameworks and libraries we support out of the box](https://docs.sentry.io/platforms/python/integrations/), you’ll see traces, errors, and profiles collected once you run your app. Alternatively, you can trigger an error manually to see it in Sentry:

```py
import sentry_sdk

try:
    1 / 0
except:
    sentry_sdk.capture_exception()
```

Hit a problem while upgrading, or found a gap in the [migration guide](https://docs.sentry.io/platforms/python/migration/2.x-to-3.x)? Open [an issue on GitHub](https://github.com/getsentry/sentry-python/issues) and we’ll take a look. For anything else about the release, find us on [GitHub](https://github.com/getsentry/sentry-python/discussions) or [Discord](https://discord.com/invite/Ww9hbqr).
