Attributes
Overview
Attributes are like metadata but specific to different span types.
Setting attributes will make the tracing UI easier to navigate on Confident AI, but is by no means required. You also cannot set attributes for custom span types.
Set Attributes At Runtime
Attributes are set at runtime using update functions specific to each span type:
Python
TypeScript
update_llm_span-update_retriever_span
These functions update the attributes for the CURRENT span of the component to which the @observe decorator is applied. For example, update_retriever_span will update the attributes for inner_function.
Python
TypeScript
How attributes update asynchronously
The current span is determined using Python’s context manager, which automatically track the active span based on the execution context. This means you don’t need to manually pass span references around - the system knows which span you’re currently executing within, even in asynchronous contexts.
LLM attributes
LLM attributes track the model, prompt, and token usage and costs of language model calls. It is highly RECOMMENDED that you set the attributes for an LLM span.
Python
TypeScript
There are SIX optional parameters for update_llm_span:
- [Optional]
model: The model used, of typestr. - [Optional]
prompt: The prompt of typePrompt, which must be pulled prior to updating the span. - [Optional]
input_token_count: The number of tokens of typefloatin the input. - [Optional]
output_token_count: The number of tokens of typefloatin the generated response. - [Optional]
cost_per_input_token: The cost per input token of typefloat. - [Optional]
cost_per_output_token: The cost per output token of typefloat.
The model and per-token costs can be set in the @observe decorator, but will
be overridden if set in update_llm_span.
Retriever attributes
Retriever attributes track the embedder, top_k, and chunk_size in RAG pipelines. It is highly RECOMMENDED that you set the attributes for a retriever span.
Python
TypeScript
There are THREE optional parameters for update_retriever_span:
- [Optional]
embedder: The name of the embedding model used of typestr. - [Optional]
chunk_size: The size of the text chunks retrieved of typeintfrom the vector store. - [Optional]
top_k: The number of text chunks retrieved of typeintfrom the vector store.