libhoney is a Python library for sending structured events to Honeycomb, an observability platform for debugging software in production. It is a low-level library designed for direct interaction with Honeycomb's Events API. The library is actively maintained, with a recent major release (2.4.0) in March 2024, and maintains a regular release cadence.
pip install libhoneyVerified import paths — ran on the pinned version, not inferred.
Initializes the libhoney library, creates a new event, adds various fields, and sends it to Honeycomb. It demonstrates best practices for API key handling via environment variables and proper shutdown procedures to ensure all events are flushed.
Upgrade to Python 3.7+ and libhoney v2.3.0+ for continued support.
Ensure your Python environment is 3.7 or newer.
Always call `libhoney.close()` as part of your application's graceful shutdown logic. Consider monitoring the responses queue for delivery confirmation.
Evaluate OpenTelemetry for new instrumentation. Use libhoney for structured events/logs when OpenTelemetry is not suitable or for existing libhoney integrations.
Verify the type and permissions of your Honeycomb API key in your Honeycomb environment settings. For new datasets, ensure the key has 'Can create datasets' enabled.
If response processing is critical, you can set `block_on_response=True` during `libhoney.init()` or ensure you have a separate thread continuously reading from `libhoney.responses()`.
Use `libhoney.new_event()` to create an event and then call `.send()` on the event object.
pip install libhoney
Ensure `libhoney.close()` is called before the program exits, or `libhoney.flush()` is called periodically to force sending buffered events. ```python import libhoney libhoney.init(writekey="YOUR_API_KEY", dataset="YOUR_DATASET") # ... send events ... libhoney.close() # Ensure all events are sent ```
Use `import libhoney` instead of `import honey`, and replace subsequent `honey.` calls with `libhoney.`. ```python import libhoney libhoney.init(writekey="YOUR_API_KEY", dataset="YOUR_DATASET") ```
Ensure all keys used when adding fields to a `libhoney` event are strings.
```python
import libhoney
libhoney.init(writekey="YOUR_API_KEY", dataset="YOUR_DATASET")
ev = libhoney.new_event()
ev.add_field("valid_string_key", "some_value")
# ev.add_field(123, "some_value") # This would cause the TypeError
ev.send()
libhoney.close()
```First create an event object, add fields to it, and then call its `send()` method.
```python
import libhoney
libhoney.init(writekey="YOUR_API_KEY", dataset="YOUR_DATASET")
event = libhoney.new_event()
event.add_field("message", "This event will be sent.")
event.send() # Correct way to send
libhoney.close()
```