Skip to main content

A simple, user-friendly Python client for sending events and traces to Honeycomb, with decorator support for timing and custom fields.

Project description

Honeycomb Python Client

A simple, user-friendly wrapper for sending events to Honeycomb using libhoney, for use across any Python codebase.

Installation

Copy the honeycomb_client.py file (and __init__.py) into your project, or install as a public package if set up.

Usage

from capture_hc.honeycomb_client import HoneycombClient

# Initialize the client (use your own writekey and dataset)
honey = HoneycombClient(writekey="<YOUR_WRITE_KEY>", dataset="<YOUR_DATASET>")

# Send an event (fields as a dictionary)
honey.send_event({
    "alert_name": "Test Alert",
    "priority": "P1",
    "message": "Something happened!",
    "duration_ms": 123.4
})

# Use the timed decorator to automatically measure and send duration
@honey.timed({"alert_name": "important_task"})
def important_task(x, y, event=None):
    # ... your code ...
    event.add_field("result", x + y)
    return x + y

important_task(1, 2)

# You can also customize the event variable name
@honey.timed({"alert_name": "custom_var"}, event_arg='track')
def another_task(x, y, track=None):
    track.add_field("custom_field", x * y)
    return x * y

another_task(2, 3)

Features

  • Only initialize once per process.
  • Simple send_event(dict) interface.
  • All fields are added to the event.
  • Handles flush automatically.
  • @honey.timed({...}) decorator to measure and send function execution time automatically.

Advanced

You can pass debug=True

Integration Example

Set your environment variables and run the script to send a test event and a timed event:

export HONEYCOMB_WRITEKEY=your_writekey
export HONEYCOMB_DATASET=your_dataset
python -m integration_example

This will:

  • Send a simple event to Honeycomb
  • Use the @honey.timed decorator to send a timed event with custom fields

Example from integration_example.py:

@honey.timed({'alert_name': 'decorator_test'})
def test_func(event=None):
    event.add_field('custom_field', 123)
    return 'decorator event sent!'

Lazy decorator (module or class)

Use a one-liner lazy decorator that initializes at call-time and works with legacy functions:

from capture_hc import lazy_timed

@lazy_timed(extra_fields={'alert_name': 'legacy_task'}, event_arg=None)
def legacy_task(x, y):
    return x + y

Or use it via the class for discoverability:

from capture_hc import HoneycombClient

@HoneycombClient.lazy_timed(extra_fields={'alert_name': 'legacy_task'}, event_arg=None)
def legacy_task(x, y):
    return x + y
  • Credentials resolve from env by default (HONEYCOMB_WRITEKEY, HONEYCOMB_DATASET).
  • Set event_arg=None if your function can't accept the event kwarg.

Airflow note

  • Prefer lazy decorators or initialize the client inside the task function to avoid DAG-parse-time side effects.

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

capture_hc-0.1.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

capture_hc-0.1.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file capture_hc-0.1.2.tar.gz.

File metadata

  • Download URL: capture_hc-0.1.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for capture_hc-0.1.2.tar.gz
Algorithm Hash digest
SHA256 290541f5fb117f7bdb5e015b57564d13abe23e62a55bc851b0405b9caa2b6225
MD5 beb242c7bf9ed362d134f24605e7a4e9
BLAKE2b-256 13193a7bd1951f6653017462b962d5af2f716705122042e47a69608e99a37ae9

See more details on using hashes here.

File details

Details for the file capture_hc-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: capture_hc-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for capture_hc-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4838444a17e6572c91020dc674a25dd5e2507cebd9dc6755ebc758de684017ed
MD5 f5d1fb1a4f2cdcd8d4a2bc8daba251c3
BLAKE2b-256 1b469010e70502f007622f2dfedb192af6b67c88097c841e5998b9312751a194

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