Learn how to set metadata on your traces
Metadata is a key-value pair that you can add to your traces to provide additional context.
It is provided as a catch-all for arbitrary information or JSON you might want to add to your traces.
The following steps will show you how to set metadata on the entire session.
You have already set tracing for your code as described in our quickstart guide.
You can set on both the trace level or the span level. If the applies to the entire trace, then set it on the trace level. If the applies to a specific span, then set it on the span level. For more details, refer to the enrich traces documentation.
In Python, you can use the enrich_session
function to set on the trace level.
To pass to HoneyHive, pass it to the param in the enrich_session
function. This function is used to enrich the session with additional information. Remember that enrich_session
will update, not overwrite, the existing object on the trace.
Read more about the enrich_session
function in the Python SDK reference.
Here’s an example of how to set on the trace level in Python:
In Python, you can use the enrich_session
function to set on the trace level.
To pass to HoneyHive, pass it to the param in the enrich_session
function. This function is used to enrich the session with additional information. Remember that enrich_session
will update, not overwrite, the existing object on the trace.
Read more about the enrich_session
function in the Python SDK reference.
Here’s an example of how to set on the trace level in Python:
In Python, you can use the enrich_span
function to set on the span level.
To pass to HoneyHive, pass it to the param in the enrich_span
function. This function is used to enrich the span with additional information. Remember that enrich_span
will update, not overwrite, the existing object linked to the span.
Read more about the enrich_span
function in the Python SDK reference.
Here’s an example of how to set on the span level in Python:
Alternatively, you can also enrich the field on the decorator in addition to using the enrich_span
function.
You can find the complete documentation for this in the Python SDK reference.
In Python, you can use the enrich_session
function to set on the trace level.
To pass to HoneyHive, pass it to the param in the enrich_session
function. This function is used to enrich the session with additional information. Remember that enrich_session
will update, not overwrite, the existing object on the trace.
Read more about the enrich_session
function in the Python SDK reference.
Here’s an example of how to set on the trace level in Python:
In Python, you can use the enrich_session
function to set on the trace level.
To pass to HoneyHive, pass it to the param in the enrich_session
function. This function is used to enrich the session with additional information. Remember that enrich_session
will update, not overwrite, the existing object on the trace.
Read more about the enrich_session
function in the Python SDK reference.
Here’s an example of how to set on the trace level in Python:
In Python, you can use the enrich_span
function to set on the span level.
To pass to HoneyHive, pass it to the param in the enrich_span
function. This function is used to enrich the span with additional information. Remember that enrich_span
will update, not overwrite, the existing object linked to the span.
Read more about the enrich_span
function in the Python SDK reference.
Here’s an example of how to set on the span level in Python:
Alternatively, you can also enrich the field on the decorator in addition to using the enrich_span
function.
You can find the complete documentation for this in the Python SDK reference.
In TypeScript, you can use the tracer.enrichSession
function to set on the trace level.
To pass to HoneyHive, pass it to the param in the tracer.enrichSession
function. This function is used to enrich the session with additional information. Remember that tracer.enrichSession
will update, not overwrite, the existing object linked to the trace.
Read more about the tracer.enrichSession
function in the TypeScript SDK reference.
Here’s an example of how to set on the trace level in TypeScript:
In TypeScript, you can use the tracer.enrichSession
function to set on the trace level.
To pass to HoneyHive, pass it to the param in the tracer.enrichSession
function. This function is used to enrich the session with additional information. Remember that tracer.enrichSession
will update, not overwrite, the existing object linked to the trace.
Read more about the tracer.enrichSession
function in the TypeScript SDK reference.
Here’s an example of how to set on the trace level in TypeScript:
In TypeScript, you can use the tracer.enrichSpan
function to set on the span level.
To pass to HoneyHive, pass it to the param in the tracer.enrichSpan
function. This function is used to enrich the span with additional information. Remember that tracer.enrichSpan
will update, not overwrite, the existing object linked to the span.
Read more about the tracer.enrichSpan
function in the TypeScript SDK reference.
Here’s an example of how to set on the span level in TypeScript:
Alternatively, you can also enrich the field on the decorator in addition to using the enrichSpan
function.
You can find the complete documentation for this in the TypeScript SDK reference.
Previously, tracing and enrichment involved calling methods directly on the tracer
instance (e.g., tracer.traceFunction()
, tracer.enrichSpan()
, tracer.enrichSession()
). While this pattern still works, it is now deprecated and will be removed in a future major version.
Please update your code to use the imported functions (traceTool
, enrichSpan
, enrichSession
) along with the tracer.trace()
wrapper as shown in the examples above. This new approach simplifies usage within nested functions by not requiring the tracer
instance to be passed around.
Example of the deprecated pattern:
Metadata is anything that doesn’t describe the quality of inputs / outputs or the system’s behavior. This metadata can be used to filter and group traces in HoneyHive.
Examples include
The following metadata fields are reserved and treated specially by HoneyHive:
total_tokens
: Total tokens used in the session/eventcompletion_tokens
: Completion tokens used in the session/eventprompt_tokens
: Prompt tokens used in the session/eventcost
: Cost of the session/eventnum_events
: Number of events in the sessionnum_model_events
: Number of model events in the sessionhas_feedback
: Whether the session has feedback on any of the eventsrun_id
: Evaluation run ID used to group sessions for an evaluation runRead more about the enrich_session
function in the Python SDK reference.