Metadata

Adding metadata to your traces for additional information

Overview

With Confident AI, you can attach additional metadata to both traces and spans. 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
1from deepeval.tracing import observe, update_current_span, update_current_trace
2
3@observe()
4async def llm_app(query: str):
5 # Add span-level metadata
6 update_current_span(
7 metadata={
8 "source": "knowledge_base_1",
9 "retrieved_documents": 3
10 }
11 )
12
13 # Add trace-level metadata
14 update_current_trace(
15 metadata={
16 "user_id": "user-456",
17 "app_version": "1.2.3",
18 }
19 )
20
21llm_app("Test Metadata")