Add Metadata to Traces
Adding metadata to your traces for additional information
Overview
With Confident AI, you can attach additional metadata to traces, spans, and threads. This information can be used for filtering, grouping, and analyzing your traces in the observatory.
Add Metadata
Use the update current span and update current trace functions to add span-level and trace-level metadata.
Each metadata argument is a dictionary whose keys are strings and whose values are any JSON-serializable type.
from deepeval.tracing import observe, update_current_span, update_current_trace
@observe()
async def llm_app(query: str):
# Add span-level metadata
update_current_span(
metadata={
"source": "knowledge_base_1",
"retrieved_documents": 3
}
)
# Add trace-level metadata
update_current_trace(
metadata={
"user_id": "user-456",
"app_version": "1.2.3",
}
)
llm_app("Test Metadata")import { observe, updateCurrentSpan, updateCurrentTrace } from 'deepeval/tracing';
const llmApp = (query: string) => {
// Add span-level metadata
updateCurrentSpan({
metadata: {
source: "knowledge_base_1",
retrieved_documents: 3
}
});
// Add trace-level metadata
updateCurrentTrace({
metadata: {
user_id: "user-456",
app_version: "1.2.3",
}
});
};
const observedLlmApp = observe({fn: llmApp});
observedLlmApp("Test Metadata");Thread-Level Metadata
You can also attach metadata to threads — useful for tagging production conversations with attributes like DVA version, client, or agent ID. See Set Thread Metadata for the payload shape.
Ready to monitor AI in production?Connect traces, alerts, dashboards, and evals in one production workflowBook a demoLast updated on