OTEL_RESOURCE_ATTRIBUTES adds attributes to every span and metric at the resource level (set once, applies to the whole process). The APIs on this page let you go further - attach custom attributes globally from code, scope them to a specific block or function call, or tag spans with agent identity - without restarting your process or touching environment variables.
Global custom attributes
Passcustom_span_attributes and/or custom_metrics_attributes to openlit.init() to have every auto-instrumented span or metric include them:
Scope attributes to a block of code
using_attributes() attaches attributes only to spans created while it’s active - as a context manager or as a decorator:
with block or during the decorated function call - they don’t leak into unrelated spans elsewhere in your application.
Attach attributes to a single call
inject_additional_attributes() runs a callable with attributes attached for that call only, useful when you don’t want to wrap a whole block:
Tag spans with agent identity
agent_context() and agent_version_context() tag spans and metrics with gen_ai.agent.name and gen_ai.agent.version respectively. These are what power the Agents page’s per-agent grouping and version snapshots - use them if you want explicit control over agent identity instead of relying on inferred grouping from service.name.
Manual spans with custom attributes
For manually created spans (as opposed to attaching attributes to auto-instrumented ones), useopenlit.start_trace() and set custom metadata directly on the returned span - see Manual Tracing for the full @openlit.trace / start_trace() reference.
Tracing
Custom tracers, resource attributes, and manual tracing
Agents
How agent identity and versions surface in the product from these attributes
Guardrails
Redact sensitive data before it’s captured in spans at all

