Overview
Thehoneyhive_logger provides a lightweight, dependency-free way to send session and event data to HoneyHive. It directly wraps HoneyHive’s /session/start and /events API endpoints.
This SDK has no external dependencies beyond built-in Python packages, making it ideal for:
- Serverless execution environments (like AWS Lambda, Google Cloud Functions).
- Highly regulated environments with strict security requirements where adding dependencies is difficult.
- Situations where you need simple, stateless logging without the overhead of a full tracing implementation.
Installation
Basic Usage
API Reference
start()
Starts a new session in HoneyHive. A session acts as a container for related events.
Parameters:
- api_key (
str, optional): Your HoneyHive API key. If not provided, the logger checks theHH_API_KEYenvironment variable. Required either as an argument or environment variable. - project (
str, optional): The name of your project in HoneyHive. If not provided, the logger checks theHH_PROJECTenvironment variable. Required either as an argument or environment variable. - session_name (
str, optional): An optional name or tag for the session (e.g., “v1.2”, “user_chat_abc”, commit hash). Helps in filtering sessions later. Defaults to theprojectname if not provided. - source (
str, optional): Identifier for the environment or component where the session originates (e.g., “production”, “staging”, “sdk_test”). Defaults to theHH_SOURCEenvironment variable or “dev”. - config (
dict, optional): Dictionary containing configuration details relevant to the entire session (e.g., system prompts, global settings). Defaults to{}. - inputs (
dict, optional): Dictionary containing initial input parameters for the session. Defaults to{}. - metadata (
dict, optional): Dictionary for additional arbitrary metadata associated with the session. Defaults to{}. - user_properties (
dict, optional): Dictionary for user-defined properties associated with the session. Defaults to{}. - session_id (
str, optional): A specific UUIDv4 string to use as the session ID. Useful for correlating with external logs or resuming sessions. If not provided, a new UUIDv4 is generated automatically. - server_url (
str, optional): The URL of the HoneyHive API server. Defaults to theHH_API_URLenvironment variable or"https://api.honeyhive.ai". - verbose (
bool, optional): IfTrue, prints detailed debug information, including request data and error messages, to the console. Defaults toFalse. - ca_bundle_path (
str, optional): Path to a custom Certificate Authority (CA) bundle file for SSL verification. IfNone, uses the system’s default CA store. See SSL Certificate Handling. Defaults toNone.
str: The unique session ID (UUIDv4 format) for the created session. This ID is needed to log events within this session or to update the session later.
Exception: Ifapi_keyorprojectis missing (and not set via environment variables).Exception: If the API call fails after retries (e.g., network error, invalid API key, server error). More details are printed ifverbose=True.
log()
Logs a specific event (like a model call, tool usage, or a step in a chain) within a session to HoneyHive.
Parameters:
- api_key (
str, optional): Your HoneyHive API key. Defaults toHH_API_KEYenv var. Required. - project (
str, optional): Your project name. Defaults toHH_PROJECTenv var. Required. - source (
str, optional): Environment identifier. Defaults toHH_SOURCEenv var or “dev”. - event_name (
str): A descriptive name for the event being logged (e.g., “generate_summary”, “vector_db_lookup”). Required. - event_type (
str, optional): The type of the event. Must be one of"model","tool", or"chain"(case-insensitive). Defaults to"tool". - config (
dict, optional): Configuration details specific to this event (e.g., model parameters like temperature, tool parameters). Defaults to{}. - inputs (
dict, optional): Input parameters for this specific event (e.g., prompt for a model, query for a tool). Defaults to{}. - outputs (
dict, optional): Output data generated by this event (e.g., model response, tool result). Defaults to{}. - metadata (
dict, optional): Additional arbitrary metadata for this event. Defaults to{}. - session_id (
str): The ID of the session this event belongs to (obtained fromstart()). Required. - duration_ms (
int, optional): The duration of the event execution in milliseconds. If not provided, defaults to10. - server_url (
str, optional): HoneyHive API server URL. Defaults toHH_API_URLenv var or"https://api.honeyhive.ai". - verbose (
bool, optional): Enable detailed debug logging. Defaults toFalse. - ca_bundle_path (
str, optional): Path to a custom CA bundle file. Defaults toNone.
str: The unique event ID (UUIDv4 format) for the logged event. This ID can be used withupdate()to add feedback or metrics later.
Exception: Ifapi_key,project,event_name, orsession_idis missing.Exception: Ifevent_typeis not one of the valid types (“model”, “tool”, “chain”).Exception: If the API call fails after retries. More details ifverbose=True.
update()
Updates an existing event or session with additional data, such as feedback, metrics, or updated metadata/outputs.
Parameters:
- api_key (
str, optional): Your HoneyHive API key. Defaults toHH_API_KEYenv var. Required. - event_id (
str): The ID of the item to update. This must be either:- A
session_idreturned fromstart()to update the session. - An
event_idreturned fromlog()to update a specific event. Required.
- A
- metadata (
dict, optional): Dictionary of metadata to add or update. Existing keys will be overwritten. - feedback (
dict, optional): Dictionary containing user feedback (e.g., ratings, corrections, comments). - metrics (
dict, optional): Dictionary containing computed metrics (e.g., latency, token counts, evaluation scores). - config (
dict, optional): Dictionary of configuration settings to add or update. - outputs (
dict, optional): Dictionary of output data to add or update. - user_properties (
dict, optional): Dictionary of user properties to add or update (typically used when updating a session). - duration_ms (
int, optional): Update the duration of the event in milliseconds. - server_url (
str, optional): HoneyHive API server URL. Defaults toHH_API_URLenv var or"https://api.honeyhive.ai". - verbose (
bool, optional): Enable detailed debug logging. Defaults toFalse. - ca_bundle_path (
str, optional): Path to a custom CA bundle file. Defaults toNone.
None
Exception: Ifapi_keyorevent_idis missing.Exception: Ifevent_idis not a valid UUID.Exception: If the API call fails after retries. More details ifverbose=True.
Error Handling
Withoutverbose set to True, all errors are swallowed.
If true, the logger will raise exceptions for:
- Invalid API keys
- Network errors
- Invalid parameters
- Server errors
- Missing required parameters
- Invalid event types
- API key or project not found
- Network connectivity issues
- Server-side errors
SSL Certificate Handling
The logger uses HTTPS for secure communication. If you operate in an environment with specific SSL/TLS requirements (like behind a corporate proxy with custom certificates), you might encounter SSL certificate verification errors.Using a Custom CA Bundle
The recommended solution is to provide a path to a custom Certificate Authority (CA) bundle file using theca_bundle_path parameter available in start(), log(), and update():
urllib library to use your specified file for verifying the server’s certificate.
Other Potential Solutions
-
Update System Certificates:
- On macOS:
brew install ca-certificates - On Ubuntu/Debian:
sudo apt-get install ca-certificates - On CentOS/RHEL:
sudo yum install ca-certificates
- On macOS:
-
Environment Variable:
Set the
REQUESTS_CA_BUNDLEorCURL_CA_BUNDLEenvironment variable: -
Corporate Proxy/VPN:
- Export your proxy’s root certificate and add it to your system’s trust store
- Or use the custom CA bundle approach with your proxy’s certificate
- Ensure your VPN is properly configured to handle HTTPS traffic

