Skip to main content

A Python logger for HoneyHive

Project description

HoneyHive Logger

A Python logger for HoneyHive that helps you track and monitor your AI applications.

Installation

pip install honeyhive-logger

Usage

from honeyhive_logger import start, log, update

# Start a new session
session_id = start(
    api_key="your-api-key",
    project="your-project"
)

# Log an event
event_id = log(
    session_id=session_id,
    event_name="model_inference",
    event_type="model",
    inputs={"prompt": "Hello world"},
    outputs={"response": "Hi there!"}
)

# Update an event with additional data
update(
    event_id=event_id, # Can also pass session_id to update a session
    feedback={"rating": 5},
    metrics={"latency": 100}
)

API Reference

start()

Starts a new session with HoneyHive.

Parameters:

  • api_key (str, optional): Your HoneyHive API key. Must be provided or set via HH_API_KEY env var.
  • project (str, optional): The project name. Must be provided or set via HH_PROJECT env var.
  • session_name (str, optional): Optional tag to filter sessions on "v1", "au1i249c" (commit hash), etc. Defaults to project name.
  • source (str, optional): Environment where the code is running. Defaults to "dev" or HH_SOURCE env var.
  • config (dict, optional): Configuration details for the session like experiment versions, model names, etc.
  • inputs (dict, optional): Input parameters for the session.
  • metadata (dict, optional): Additional metadata for the session.
  • user_properties (dict, optional): User-defined properties for the session.
  • session_id (str, optional): A valid UUIDv4 for the session to correlate with your logs. If not provided, one will be generated.
  • server_url (str, optional): HoneyHive API server URL. Defaults to "https://api.honeyhive.ai" or HH_API_URL env var.
  • verbose (bool, optional): Print detailed error messages for debugging. Defaults to False.

Returns:

  • str: The session ID (UUIDv4)

Example:

session_id = start(
    api_key="your-api-key",
    project="your-project",
    session_name="v1",
    source="prod",
    config={
        "model": "gpt-4",
        "temperature": 0.7
    }
)

log()

Logs an event to HoneyHive.

Parameters:

  • api_key (str, optional): Your HoneyHive API key. Must be provided or set via HH_API_KEY env var.
  • project (str, optional): The project name. Must be provided or set via HH_PROJECT env var.
  • source (str, optional): Environment where the code is running. Defaults to "dev" or HH_SOURCE env var.
  • event_name (str): Name of the event being logged. Required.
  • event_type (str, optional): Type of event - "model", "tool", or "chain". Defaults to "tool".
  • config (dict, optional): Configuration details for the event like model name, vector index name, etc.
  • inputs (dict, optional): Input parameters for the event.
  • outputs (dict, optional): Output data from the event.
  • metadata (dict, optional): Additional metadata for the event.
  • session_id (str): The ID of the session to log the event under. If not provided, a session is automatically created.
  • duration_ms (int, optional): Duration of the event in milliseconds. If not provided, will be set to 10.
  • server_url (str, optional): HoneyHive API server URL. Defaults to "https://api.honeyhive.ai" or HH_API_URL env var.
  • verbose (bool, optional): Print detailed error messages for debugging. Defaults to False.

Returns:

  • str: The event ID (UUIDv4)

Example:

event_id = log(
    session_id="your-session-id",
    event_name="model_inference",
    event_type="model",
    config={
        "model": "gpt-4",
        "temperature": 0.7
    },
    inputs={
        "prompt": "Hello world"
    },
    outputs={
        "response": "Hi there!"
    }
)

update()

Updates an event or session with additional data.

Parameters:

  • api_key (str, optional): Your HoneyHive API key. Must be provided or set via HH_API_KEY env var.
  • event_id (str): The ID to update. This can be either:
    • A session_id returned from start()
    • An event_id returned from log()
  • metadata (dict, optional): Additional metadata for the event/session.
  • feedback (dict, optional): User feedback for the event/session.
  • metrics (dict, optional): Metrics computed for the event/session.
  • config (dict, optional): Configuration used in the event/session.
  • outputs (dict, optional): Output data from the event/session.
  • user_properties (dict, optional): User-defined properties for the event/session.
  • duration_ms (int, optional): Duration of the event in milliseconds.
  • server_url (str, optional): HoneyHive API server URL. Defaults to "https://api.honeyhive.ai" or HH_API_URL env var.
  • verbose (bool, optional): Print detailed error messages for debugging. Defaults to False.

Returns:

  • None

Example:

# Update a session
update(
    event_id=session_id,
    metadata={
        "status": "completed"
    }
)

# Update an event
update(
    event_id=event_id,
    feedback={
        "rating": 5,
        "comment": "Great response!"
    },
    metrics={
        "latency": 100,
        "tokens": 50
    }
)

Error Handling

Without verbose set to True, all errors are swallowed.

If true, the logger will raise exceptions for:

  • Invalid API keys
  • Network errors
  • Invalid parameters
  • Server errors

Each error includes detailed information about what went wrong and how to fix it. For example:

  • 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 with the HoneyHive API. If you encounter SSL certificate verification errors, here are some solutions:

Using a Custom CA Bundle

You can specify a custom certificate authority (CA) bundle file when making requests:

start(
    api_key="your-api-key",
    project="your-project",
    ca_bundle_path="/path/to/custom/ca-bundle.crt"
)

This is useful when:

  • You're behind a corporate proxy that uses custom certificates
  • Your system's certificate store is outdated
  • You need to trust specific self-signed certificates

Other Solutions

  1. 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
  2. Environment Variable: Set the REQUESTS_CA_BUNDLE or CURL_CA_BUNDLE environment variable:

    export REQUESTS_CA_BUNDLE=/path/to/custom/ca-bundle.crt
    
  3. 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

Documentation

For detailed documentation, please visit https://docs.honeyhive.ai

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

honeyhive_logger-0.0.10.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

honeyhive_logger-0.0.10-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file honeyhive_logger-0.0.10.tar.gz.

File metadata

  • Download URL: honeyhive_logger-0.0.10.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for honeyhive_logger-0.0.10.tar.gz
Algorithm Hash digest
SHA256 6b39f85825f5af316f38cae95453a32e029de2c81c037ddfacb29b6c8f902fc4
MD5 5ea977162e32340716a49a5e5ad03dd5
BLAKE2b-256 8990c7257ca8bdd6d0313969e0a218e7aff259065803b0367a7709b6672ebb70

See more details on using hashes here.

File details

Details for the file honeyhive_logger-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for honeyhive_logger-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 100242a5a208cb8a35e993844f4fa722ee7b07a469c987dd24b41469f07336c0
MD5 8ec92b0934cbf338f129c6129d2cc1f7
BLAKE2b-256 17f64a5602f7cfc888d919b8d94816a2153efe60a48783087ed0f851ce93e78c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page