Registry / observability / libhoney

libhoney

JSON →
library2.4.0pypypi✓ verified 22d ago

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 libhoney
INSTALL
IMPORT
SIG · LIBHONEY
L
libhoney
observabilitypythonv2.4.0
Install
2.4s avg
Import
99ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.106s · 21.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.092s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

libhoney
import libhoney

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.

import libhoney import os import time # Initialize libhoney with your API key and dataset name. # It's recommended to retrieve these from environment variables. libhoney.init( writekey=os.environ.get('HONEYCOMB_API_KEY', 'YOUR_API_KEY'), dataset=os.environ.get('HONEYCOMB_DATASET', 'my-python-app'), service_name='my-python-app' ) try: # Create a new event ev = libhoney.new_event() # Add fields to the event ev.add_field('event_type', 'example_event') ev.add_field('request.method', 'GET') ev.add_field('request.path', '/api/v1/data') ev.add_field('duration_ms', 123.45) ev.add_field('user.id', 'user-123') # Send the event asynchronously ev.send() print("Event sent successfully (asynchronously).") # For demonstration, wait a bit for asynchronous send time.sleep(0.1) finally: # It's crucial to call libhoney.close() on application shutdown # to ensure all buffered events are sent. libhoney.close() print("libhoney closed, all events flushed.")
Debug
Known issues
breakingPython 2.7 support was dropped in v2.0.0. If you are on an older Python 2.x environment, you must upgrade Python or use an older libhoney version.
fix
Upgrade to Python 3.7+ and libhoney v2.3.0+ for continued support.
affects: <2.0.0
breakingThe minimum supported Python version was raised to 3.5 in v2.0.0, and further to 3.7 in v2.3.0. Versions of Python older than 3.7 are no longer supported.
fix
Ensure your Python environment is 3.7 or newer.
affects: <2.3.0
gotchaEvents are sent asynchronously in batches. Not calling `libhoney.close()` upon application shutdown can result in buffered events not being sent to Honeycomb, leading to data loss.
fix
Always call `libhoney.close()` as part of your application's graceful shutdown logic. Consider monitoring the responses queue for delivery confirmation.
affects: All versions
gotchaFor new applications requiring tracing, Honeycomb recommends using OpenTelemetry Python SDK instead of libhoney for its standardized, vendor-agnostic, and future-proof approach to telemetry (traces, logs, and metrics).
fix
Evaluate OpenTelemetry for new instrumentation. Use libhoney for structured events/logs when OpenTelemetry is not suitable or for existing libhoney integrations.
affects: All versions
gotchaHoneycomb API keys have different types and permissions. 'Classic-flavored' ingest keys are now explicitly supported in v2.4.0, but general ingest keys can have permissions like 'Can create datasets'. Ensure your API key has the necessary permissions and is the correct type for your use case.
fix
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.
affects: All versions
gotchaResponses from Honeycomb (e.g., status codes) are placed in an internal queue. If this queue is not actively read from, responses may be dropped if the queue becomes full. By default, sending threads are not blocked by the response queue being full.
fix
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()`.
affects: All versions
deprecatedThe `send_now` method was deprecated in favor of `new_event().send()`, which batches events for more efficient transmission.
fix
Use `libhoney.new_event()` to create an event and then call `.send()` on the event object.
affects: <1.6.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'libhoney'
The 'libhoney' package has not been installed in the current Python environment.
fix
pip install libhoney
libhoney events not sending
Events sent via libhoney are buffered and will not be flushed to Honeycomb until the client is explicitly closed or flushed, especially in short-lived scripts or on premature program exit.
fix
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
```
ModuleNotFoundError: No module named 'honey'
The user attempted to import a non-existent module named 'honey' instead of the correct package name, 'libhoney'.
fix
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")
```
TypeError: Event field keys must be strings
The `add_field()` or `add_fields()` method was called with a non-string value for an event field key.
fix
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()
```
AttributeError: module 'libhoney' has no attribute 'send_event'
The `libhoney` module does not have a top-level function named `send_event()`; events are created via `libhoney.new_event()` and then sent using the `send()` method on the resulting event object.
fix
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()
```
Upgrade
Version history
2.4.0latest on PyPI · released Mar 6, 2024
Audit
Dependencies
pythonrequiredRequires Python 3.7 or newer.
Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
2
Resources
libhoney — pip install libhoney · libregistry