Introduction

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.

Prerequisites

You have already set tracing for your code as described in our quickstart guide.

Setting

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:

Python
from honeyhive import HoneyHiveTracer, enrich_session

HoneyHiveTracer.init(
  api_key="my-api-key",
  project="my-project",
)

# ...

enrich_session(metadata={
  "experiment-id": 12345,
  # any other custom fields and values as you need
})

Concepts

What is Metadata?

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

  • Online Experiment IDs
  • Offline Experiment IDs
  • Token Usage
  • Cost
  • System-level information

Reserved Fields

The following metadata fields are reserved and treated specially by HoneyHive:

  1. Token Usage
    • total_tokens: Total tokens used in the session/event
    • completion_tokens: Completion tokens used in the session/event
    • prompt_tokens: Prompt tokens used in the session/event
  2. Cost
    • cost: Cost of the session/event
  3. Event Counts
    • num_events: Number of events in the session
    • num_model_events: Number of model events in the session
    • has_feedback: Whether the session has feedback on any of the events
  4. Evaluation Run ID
    • run_id: Evaluation run ID used to group sessions for an evaluation run

Learn more

SDK Reference

Read more about the enrich_session function in the Python SDK reference.