
- Provide business context (order IDs, payment types) that makes traces searchable.
- Improve debugging by attaching relevant runtime details to an operation.
- Enable fine-grained alerting and aggregation (e.g., only alert on errors for a specific payment method).
- Support metric generation by aggregating attribute values across spans.
- Add
order_id,payment_method, orinventory_statusto theprocess_orderspan. - Use these attributes to filter traces (for example, all spans where
payment_methodis"Credit Card"), or to group and analyze failures for specific products.


- Business data:
order_id,payment_method,product_sku - User data:
user_id,account_tier - Technical data:
http.status_code,db.system, cachehit/miss

process_order span that contains order_id, payment_method, and inventory_status lets you filter and debug fulfillment issues by order attributes.

set_attribute on the span object:
set_attribute method (dot notation) to attach keys and values. Keys are strings and values must conform to supported types (see rules below). Add important attributes as early as possible so they are available for SDK-level sampling decisions.

| Rule | Recommendation |
|---|---|
| Key type | Keys must be non-null strings. Use concise, consistent naming. |
| Value types | Values may be string, boolean, integer, float, or arrays of these primitives. |
| Avoid nulls | Do not record null values; omit attributes when the value is unknown. |
| Key naming | Prefer short, stable keys; use semantic conventions for common technical attributes. |
| When to set | Add business-critical attributes early in execution to influence sampling and availability. |

Use semantic conventions (standardized attribute keys such as
http.method, db.system, messaging.operation) where possible. These conventions promote consistency across services and make cross-system analysis easier.http.method, http.url, etc.), so you often do not need to add them manually. Use manual attributes for business-specific metadata (e.g., order_id, payment_method) to make traces searchable and filterable by business context.
Summary — key takeaways
- Span attributes are key-value metadata attached to spans to provide contextual, queryable information.
- Keys must be non-null strings; values must be primitives (
string,boolean,integer,float) or arrays of primitives. - Use semantic conventions for technical attributes; use manual instrumentation for business attributes.
- Add attributes early so they are available to sampling and analysis.
- Attributes enable trace filtering, aggregation, and more precise alerting based on business context.

Span attributes are not propagated across spans. To propagate key-value pairs across process boundaries, use baggage instead.