---
title: "Attributes"
description: "Attributes automatically enrich your telemetry with typed key-value data. Use them to add business context that you can then filter and search in Sentry."
url: https://docs.sentry.io/platforms/python/enriching-events/attributes/
---

# Attributes | Sentry for Python

Available since: `v2.54.0`

**Attributes** are key-value pairs you can attach to your telemetry (like [spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md), [logs](https://docs.sentry.io/platforms/python/logs.md), and [metrics](https://docs.sentry.io/platforms/python/metrics.md)).

Common uses include subscription tier, feature flags, or any business context that helps you filter and query your telemetry.

Attribute values can be `str`, `int`, `float`, or `bool`, as well as arrays of these types.

Attributes on spans require [stream mode](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) (SDK version `2.62.0`+). In stream mode, spans have no contexts, data, or tags — everything is an attribute, so `set_data()`, `set_tag()`, and `set_context()` are replaced by `set_attribute()` and `set_attributes()`.

Attributes on logs and metrics don't require stream mode — they work regardless of your `trace_lifecycle` setting.

## [Add Attributes to a Scope](https://docs.sentry.io/platforms/python/enriching-events/attributes.md#add-attributes-to-a-scope)

Use `sentry_sdk.set_attribute` to attach attributes that are automatically included on all logs and metrics — and, in stream mode, on all spans. These write to the isolation scope, so they apply for the current request or session:

```python
import sentry_sdk

sentry_sdk.set_attribute("org_id", user.org_id)
sentry_sdk.set_attribute("user_tier", user.tier)
sentry_sdk.set_attribute("service", "checkout")
```

To attach attributes more broadly or more narrowly, set them on a specific scope instead:

```python
import sentry_sdk

# Global scope — applies to every event for the life of the app
sentry_sdk.get_global_scope().set_attribute("app.version", "1.2.3")

# Current scope — applies only within this block
with sentry_sdk.new_scope() as scope:
    scope.set_attribute("checkout.step", "payment")
    sentry_sdk.logger.info("Processing payment")
```

See [Scopes](https://docs.sentry.io/platforms/python/enriching-events/scopes.md) for more on the global, isolation, and current scopes.

## [Setting Attributes on Individual Telemetry](https://docs.sentry.io/platforms/python/enriching-events/attributes.md#setting-attributes-on-individual-telemetry)

You can also attach attributes to a single span, log, or metric directly, which is useful when the data only makes sense for that one item.

### [Spans](https://docs.sentry.io/platforms/python/enriching-events/attributes.md#spans)

In stream mode, you can set attributes when starting a span:

```python
import sentry_sdk

with sentry_sdk.traces.start_span(
    name="process-order",
    attributes={
        "sentry.op": "queue.process",
        "order.id": "abc-123",
        "order.item_count": 5,
        "order.priority": True,
    },
):
    process_order()
```

Or add them to an already running span:

```python
import sentry_sdk

with sentry_sdk.traces.start_span(name="handle-request") as span:
    span.set_attribute("http.response.status_code", 200)

    span.set_attributes({
        "http.route": "/api/users",
        "user.id": "user-42",
    })
```

See [Add Span Attributes](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md#add-span-attributes) for more.

### [Logs](https://docs.sentry.io/platforms/python/enriching-events/attributes.md#logs)

Pass attributes to any `sentry_sdk.logger` call via the `attributes` kwarg:

```python
sentry_sdk.logger.error(
    "Payment processing failed",
    attributes={
        "payment.provider": "stripe",
        "payment.method": "credit_card",
    }
)
```

See [Logs](https://docs.sentry.io/platforms/python/logs.md) for more.

### [Metrics](https://docs.sentry.io/platforms/python/enriching-events/attributes.md#metrics)

Pass attributes in the `attributes` parameter of any metric:

```python
import sentry_sdk

sentry_sdk.metrics.count(
    "button_click",
    5,
    attributes={
        "browser": "Firefox",
        "app_version": "1.0.0"
    },
)
```

See [Application Metrics](https://docs.sentry.io/platforms/python/metrics.md) for more.
