Skip to main content
When you instrument an agent with the CoreWeave Forge SDK, each span object (Turn, LLM, Tool, and SubAgent) lets you attach custom metadata as attributes. Attributes are key-value properties of a span. Use them to stamp contextual information such as user IDs, tenants, experiment names, or environment labels onto agent spans, and then filter and group agent activity by that metadata in the CoreWeave Agent Lens UI. You can set attributes on a single span with set_attributes() (Python) or setAttributes() (TypeScript), or set conversation-wide attributes that apply to every span a conversation emits. set_attributes mirrors the OpenTelemetry (OTel) span API method Span.set_attributes. The Agent Lens SDK emits OTel spans and stores all attributes, so they remain queryable in Agent Lens. The examples on this page assume you have installed the SDK and initialized it as described in Trace your agents.

Set attributes on a span

Use set_attributes() (Python) or setAttributes() (TypeScript) to stamp arbitrary attributes on a single span. Pass a dictionary or object whether you have one key or many. The method returns the span, so you can chain calls.
The same methods are available on every span class. For example, you can tag an individual tool call or LLM call:
Most attribute keys are arbitrary custom metadata, but Agent Lens reserves two prefixes for special handling. Keys under weave.* map to built-in Agent Lens fields, and keys under gen_ai.* map to OpenTelemetry GenAI semantic-convention fields. In the preceding example, weave.display_name is a reserved key that sets the span’s display name in the Agent Lens UI. For arbitrary metadata that you want to filter and group by, use your own keys such as user_id or tenant, which Agent Lens stores as filterable custom attributes.

Record what happens during a span

Attributes can also record something that happens while a span is running, such as a permission prompt or its outcome. Set the attributes when the moment occurs, while the span is still recording:
An attribute records a value, not the time it was set. If you need to know when something happened within a span, record the time as its own attribute, for example permission.granted_at.
The SDK’s add_event() (Python) and addEvent() (TypeScript) methods are deprecated, because OpenTelemetry is deprecating the Span Event API. Record this data with attributes instead.

Set attributes on every span in a conversation

Stamping attributes one span at a time works well for span-specific metadata, but some metadata applies to an entire conversation. To apply the same attributes to every span a conversation emits, pass attributes when you start the conversation. This is useful for propagating conversation-wide metadata such as a deployment name or environment.
As with per-span attributes, use your own custom keys for conversation attributes. Set semantic-convention fields, such as the agent name, conversation name, or model, through their typed parameters (agent_name, conversation_name, model) rather than through attributes. Avoid keys under the reserved gen_ai.* and weave.* prefixes. Agent Lens extracts those into typed fields during ingestion, so a custom value under a reserved key is unsupported.

When you can set attributes

Set attributes while the span is recording, that is, after the span starts and before it ends. In Python, this is inside the with block. In TypeScript, this is after start*() and before end(). If you call set_attributes(), or its TypeScript equivalent, on a span that hasn’t started yet or has already ended, the call is a no-op and logs a warning that names the fix. The call is silent (no warning) only when tracing hasn’t been initialized.
To attach attributes when logging completed agent activity in a single batch rather than during live execution, populate the span object’s declared fields directly and pass the object to log_turn or log_conversation. See Log agent activity in batches.

View and filter attributes in the UI

Adding attributes is only the first step. Their value comes from using them to analyze agent activity. After you stamp attributes on agent spans, you can filter and group agent conversations by those attributes in the Conversations tab of your Agent Lens project. For details, see View agent activity.
Last modified on September 29, 2026