Use this file to discover all available pages before exploring further.
Python
TypeScript
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.
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.
The @atrace decorator is identical in functionality to the @trace decorator, but is used for async functions.
from honeyhive import trace@tracedef my_function(param1, param2): # Code here return result
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:-
Enriching before execution: The decorator-based enrichment below shows how you can enrich static properties before the code executes.
Enriching during execution: You can enrich dynamic properties on a session/trace or event/span level using enrich_session and enrich_span functions. Please refer to the Enrich Traces documentation for more details on enrichment during execution.
Enriching During Execution Using enrich_span or enrich_session
You can also enrich your traces and custom spans with various propertires during execution using the enrich_span or enrich_session functions.Please refer to the Enrich Traces documentation for more details on enrichment during execution. You can find the complete documentation for this in the Python SDK reference.
For async functions in Python, use the @atrace decorator instead of @trace. The @atrace decorator is specifically designed to handle async functions properly:
from honeyhive import atrace@atraceasync def my_async_function(param1: str) -> str: # Async operations here result = await some_async_operation(param1) return result# The function can be called with await as normalresult = await my_async_function("test")
The @atrace decorator supports the same enrichment options as @trace:
@atrace( config={"event_type": "my_event_type"}, metadata={"key": "value"}, event_type="chain")async def my_async_function(param1: str) -> str: result = await some_async_operation(param1) return result
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.
All traces can be visualized in the HoneyHive web app under Log 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.
Here are some ways in which you can enrich your traces:
Enrichments Overview
An overview of the types of enrichments available for your traces and spans
Logging Client-Side Evaluations
Add client-side metrics, guardrail results, or evaluations to your traces
Logging User Feedback
Enrich traces with feedback or additional annotations
Logging Configuration Details
Include config details, model hyperparameters, or prompt templates
Logging User Properties
Add user properties or tracking IDs to your traces
Logging Custom Metadata
Enrich traces with arbitrary metadata or JSON
While HoneyHive automatically instruments many common LLM application components, you may sometimes want to trace specific parts of your code beyond the automated coverage. HoneyHive provides flexible tracing methods including the general-purpose traceFunction as well as event-specific methods (traceModel, traceTool, traceChain) that allow you to easily add custom spans to your TypeScript application. These methods capture function inputs, outputs, and additional metadata, providing deeper insights into your application’s behavior.
Unlike our auto-tracer, this approach works with ESModules automatically.
Then you can use the traceFunction method to wrap any function you want to trace:
const myFunction = tracer.traceFunction()( function processParameters(param1: string, param2: number): string { // Your function code here return `Result with ${param1} and ${param2}`; });// Call the traced functionmyFunction("test", 42);
This will automatically create a span for the function, capturing its inputs and outputs.
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:-
Enriching before execution: The decorator-based enrichment below shows how you can enrich static properties before the code executes.
Enriching during execution: You can enrich dynamic properties on a session/trace or event/span level using enrich_session and enrich_span functions. Please refer to the Enrich Traces documentation for more details on enrichment during execution.
Enriching During Execution Using enrich_span or enrich_session
You can also enrich your traces and custom spans with various propertires during execution using the enrich_span or enrich_session functions.Please refer to the Enrich Traces documentation for more details on enrichment during execution. You can find the complete documentation for this in the TypeScript SDK reference.
While traceFunction provides a general-purpose solution for tracing any function, HoneyHive also offers specialized tracing methods for different types of events: traceModel, traceTool, and traceChain.
These methods are designed to trace specific operations in your application, such as LLM requests, deterministic functions, or pipelines, and automatically set the appropriate event type for the span.
The traceModel method is used to trace operations involving LLM requests. It automatically sets the event type to model and allows you to capture inputs, outputs, and metadata specific to the model operation.
In this example, the traceModel method captures the function’s inputs (e.g., the prompt), outputs (e.g., the generated text), and additional metadata (e.g., the model name and configuration).
The traceTool method is used to trace deterministic operations, such as database queries, API requests, or regex parsing. It automatically sets the event type to tool and allows you to enrich the span with relevant metadata.
async function searchDatabase(query: string): Promise<any> { const result = await DatabaseSearch(query); return result;}// Trace the pre-defined functionconst toolFunction = tracer.traceTool(searchDatabase, { metadata: { tool_type: "database_search" }});
The traceChain method is used to trace pipelines or workflows that group multiple model and tool events into a single composable unit. It automatically sets the event type to chain and allows you to capture the overall behavior of the pipeline.
Use named functions when possible, 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
Use the config parameter for settings that might affect the function’s behavior
Use the metadata parameter for additional context that could be useful for analysis
By strategically using the traceFunction, traceModel, traceTool, and traceChain methods on 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.
All traces can be visualized in the HoneyHive web app under Log 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.