Custom Spans
How to trace custom spans with HoneyHive.
While the HoneyHive tracer automatically instruments all of the most common LLM application components, you might sometimes want to trace parts of your code beyond the automated coverage.
To do this, you can use HoneyHive’s manual tracing tools, which we’ll walk through in this guide.
Prerequisites
Please complete the Quickstart and make sure you have initialized your tracer using HoneyHiveTracer.init()
.
Overview
HoneyHive gives you full customizability over your traces.
You can trace any function in your code and see its inputs, outputs, errors, duration, etc. by decorating it with the @trace
decorator.
@atrace
decorator is identical in functionality to the @trace
decorator, but is used for async functions.Enriching Custom Spans
You can enrich your custom spans with additional properties to provide more context to your traces.
There are 2 ways to enrich spans in HoneyHive - before execution and during execution.
- Enriching before execution
The decorator-based enrichment below shows how you can enrich static properties before the code executes.
- Enriching during execution
Please refer to the Enrich Traces documentation for more details on enrichment during execution.
Decorator-based Enrichments
Here is an example of how to enrich the Configuration, Metadata, and Event Type fields on the decorator:
You can also enrich the Configuration, Metadata, and Event Type fields on the decorator in addition to using the enrich_span
function.
You can find the complete documentation for this in the Python SDK reference.
Best practices
- Use descriptive function names, as they will be used as span names in your traces
- Be mindful of sensitive data when tracing functions - avoid capturing passwords or other secrets
By strategically adding the @trace
decorator to key functions in your application, you can gain valuable insights into your custom code’s performance and behavior, complementing HoneyHive’s automatic instrumentation of LLM components.
Visualizing Your Traces
All traces can be visualized in the HoneyHive web app under Data Store in the session’s specified project. The session tree view shows you the execution flow of your trace, as well all the automatically captured and manually enriched attributes.
Next Steps
Here are some ways in which you can enrich your traces:
Metrics & Evaluations
Add metrics, scores, or evaluations to your traces
User Feedback
Enrich traces with feedback or additional annotations
Configuration Details
Include config details, model hyperparameters, or prompt templates
User Properties
Add user properties or tracking IDs to your traces
Custom Metadata
Enrich traces with arbitrary metadata or JSON