add_span_attributes
add_span_attributes
Adds custom span-level attributes to a specific runnable component’s metadata.
Span attributes are key-value pairs that apply to a specific component (LLM, tool, or retriever) and are included in the OpenTelemetry spans created when that component executes. Use this to add metadata that describes the component’s configuration, purpose, or operational context.
Unlike session attributes (which apply to all spans in a context), span attributes are scoped to individual components. This is useful for:
Identifying which model or tool is being used
Tagging components by purpose or category
Adding version information or deployment metadata
Tracking A/B test variants or experimental configurations
The attributes are stored in the component’s metadata dictionary under the key ‘_fiddler_attributes’ and will be automatically included in spans when the component executes. Attributes persist for the lifetime of the component instance.
Supported component types:
BaseLanguageModel: LLM calls (ChatOpenAI, ChatAnthropic, etc.)
BaseRetriever: Document retrieval operations
BaseTool: Tool/function calls in agent workflows
Parameters
node
BaseLanguageModel | BaseRetriever | BaseTool
✓
-
The LangChain component to annotate with custom attributes. The component’s metadata will be modified in place.
Returns
None
Return type: None
Examples
Tagging an LLM with model information:
Adding version and environment metadata:
Tagging tools in a multi-tool agent:
A/B testing different retrievers:
Combining with session attributes:
Attributes are stored in the component’s metadata dictionary, which persists for the lifetime of the component instance
If the component doesn’t have a metadata attribute, one will be created
Multiple calls to add_span_attributes on the same component will merge attributes
Later calls with the same key will overwrite previous values
This modifies the component in place - no need to reassign the return value
Last updated
Was this helpful?