Attributes

Attributes automatically enrich logs and metrics with typed key-value data. Use them to add business context that you can filter and search in Sentry.

Available since: v6.7.0

Attributes are key-value pairs you can attach to your telemetry. Unlike tags, which are indexed string pairs attached to events, attributes are designed for logs and metrics.

Common uses include subscription tiers, feature flags, and other business context that helps you filter and query your telemetry. Attribute values can be strings, integers, floats, booleans, or values that can be serialized as JSON.

Use Sentry.set_attribute to add an attribute to the current scope. Sentry includes scope attributes on logs and metrics for the current request or session:

Copied
Sentry.set_attribute("subscription.tier", "pro")
Sentry.set_attribute("feature.new_checkout", true)
Sentry.set_attribute("order.item_count", 3)

You can set multiple attributes at once with Sentry.set_attributes:

Copied
Sentry.set_attributes(
  "org_id" => user.org_id,
  "user_tier" => user.tier,
  "service" => "checkout"
)

Attributes set on the scope are used as defaults. Attributes passed directly to a log or metric take precedence when they use the same key:

Copied
Sentry.set_attribute("checkout.step", "payment")

Sentry.logger.info(
  "Payment processed",
  "checkout.step" => "confirmation"
)

To attach a measurement unit to a numeric value, pass the unit: keyword argument. Sentry sends the value and unit as a typed attribute:

Copied
Sentry.set_attribute("checkout.duration", 3600, unit: "second")

You can also provide the value and unit as a hash. This is useful when building attributes dynamically:

Copied
Sentry.set_attribute(
  "checkout.duration",
  value: 3600,
  unit: "second"
)

Remove an attribute from the current scope when it no longer applies:

Copied
Sentry.remove_attribute("checkout.step")

Scope attributes enrich logs and metrics. To add searchable context to error events, use tags or structured contexts instead.

Was this helpful?
Help improve this content
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").