Attributes
Attributes automatically enrich your telemetry with typed key-value data. Use them to add business context that you can filter and search in Sentry.
Available since: v10.61.0
Attributes are key-value pairs you can attach to your telemetry (like spans, logs, and metrics). Unlike tags, which only accept string values, attributes support string, number and boolean values.
Common uses include subscription tier, feature flags, or any business context that helps you filter and query your telemetry. Check out Sending Span Metrics for an example of how to use attributes to enrich your spans.
Setting attributes will bind them to the isolation scope. This ensures they'll automatically be included on future telemetry for the current request or page view:
Sentry.setAttribute("is_admin", true);
Sentry.setAttributes({
"user.num_orders": user.numOrders,
"subscription.tier": "pro",
});
Sentry.setAttribute("is_admin", true);
Sentry.setAttributes({
"user.num_orders": user.numOrders,
"subscription.tier": "pro",
});
To attach attributes to a broader or narrower context, you can set them on a specific scope instead. Use the global scope for attributes that should appear on all telemetry across the entire application, and withScope for a single operation only:
// Applied to everything across the entire application
Sentry.getGlobalScope().setAttributes({
"app.version": "1.2.3",
});
// Applied to a single operation only
Sentry.withScope((scope) => {
scope.setAttribute("checkout.step", "payment");
Sentry.logger.info("Processing payment");
});
// Applied to everything across the entire application
Sentry.getGlobalScope().setAttributes({
"app.version": "1.2.3",
});
// Applied to a single operation only
Sentry.withScope((scope) => {
scope.setAttribute("checkout.step", "payment");
Sentry.logger.info("Processing payment");
});
Learn more about how scope data is applied to events in Scopes.
The scope APIs above are the easiest way to enrich everything at once. But you can also attach attributes to a single span, log, or metric directly. Useful when the data only makes sense for that one item.
Add attributes to the currently active span with setAttribute or setAttributes. See Sending Span Metrics for more.
const span = Sentry.getActiveSpan();
if (span) {
span.setAttributes({
"checkout.step": "payment",
"cart.item_count": 3,
});
}
const span = Sentry.getActiveSpan();
if (span) {
span.setAttributes({
"checkout.step": "payment",
"cart.item_count": 3,
});
}
Pass attributes as the second argument to any Sentry.logger call. See Logs for more.
Sentry.logger.info("Order created", {
"order.id": order.id,
"subscription.tier": "pro",
});
Sentry.logger.info("Order created", {
"order.id": order.id,
"subscription.tier": "pro",
});
Pass attributes in the attributes option of any metric. See Metrics for more.
Sentry.metrics.count("orders_created", 1, {
attributes: {
"subscription.tier": "pro",
region: "us-west",
},
});
Sentry.metrics.count("orders_created", 1, {
attributes: {
"subscription.tier": "pro",
region: "us-west",
},
});
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").