Launch Week 02 wrapped — explore all five launches

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.

main.py
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")

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.

Last updated on

Built byConfident AI