Skip to main content
This page describes attributes for functions traced with the @weave.op decorator. If you instrument an agent with the Weave agent SDK, set attributes and events on agent spans (Turn, LLM, Tool, and SubAgent) instead. See Set attributes and events on agent spans.
Attributes in Weave let you attach custom metadata to your traces and evaluations. This metadata can include information like environment names, model versions, experiment IDs, user IDs, or other contextual information to help you organize, filter, and analyze your Weave data. Attributes are especially helpful for grouping or filtering traces by:
  • Deployments
  • Tenants
  • Experiments
Weave provides two ways to add attributes:
  • Per-call attributes: Use the weave.attributes() context manager to add metadata to specific operations or code blocks.
  • Global attributes: Use the global_attributes field to set attributes at initialization that apply to all traces and evaluations in your project.
You can view all attributes logged during traces and evaluations in the UI. You can then use them to filter and group data. This guide is for Weave users who want to enrich their traces and evaluations with custom metadata. It covers how to attach attributes to individual calls, set project-wide defaults at initialization, combine the two approaches, and read the current attribute set during execution.

Per-call attributes

The weave.attributes() context manager lets you add metadata to specific traced operations. Use it to tag particular function calls or evaluation runs with contextual information.
You can’t modify call.attributes once the call starts. Use this context manager to set any metadata before invoking the op.
The function attaches the attributes to all traced operations within the context manager block (Python) or callback function (TypeScript). You can also nest weave.attributes() contexts. Inner contexts override outer contexts for the same keys:

Global attributes

When you set global attributes during Weave initialization, they automatically apply to all traces and evaluations in your project. This is useful for propagating project-wide metadata like environment, deployment version, or team information.

Combine global and per-call attributes

You can use global attributes and per-call attributes together. Per-call attributes with the same key override global attributes:

Get attributes during execution

At runtime, you can inspect the attributes in effect for a Call. This is useful when you want to debug which metadata Weave attaches, or when your code needs to branch on contextual information set by an outer caller.
The following example sets the Weave decorator to log the process_data function, configures attributes to log, and then returns them on execution.
This outputs:
weave.get_current_call() only works inside a @weave.op decorated function. Outside of an op, it returns None.