Registry / observability / logdna

logdna

JSON →
library1.18.12pypypi✓ verified 84d ago

A Python package for sending logs to LogDNA (now Mezmo). This library provides both a standard logging handler and a custom LogDNA logger class. Current version: 1.18.12. Release cadence is irregular, primarily bugfixes.

pip install logdna
INSTALL
IMPORT
SIG · LOGDNA
L
logdna
observabilitypythonv1.18.12
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

LogDNAHandler
from logdna import LogDNAHandler
from logdna.handler import LogDNAHandler
LogDNAHandler is not a submodule; the correct import is from the top-level package.
LogDNALogger
from logdna import LogDNALogger
from logdna.logger import LogDNALogger
LogDNALogger is exported directly from logdna package.
StreamHandler
from logging import StreamHandler
from logdna import StreamHandler
StreamHandler is a standard library class, not part of logdna.

Minimal setup for sending logs to LogDNA using LogDNAHandler. Replace LOGDNA_INGESTION_KEY with your actual key.

import os import logging from logdna import LogDNAHandler # Use environment variables for credentials key = os.environ.get('LOGDNA_INGESTION_KEY', '') # If you have a custom ingestion host, set LOGDNA_URL url = os.environ.get('LOGDNA_URL', 'https://logs.logdna.com/logs/ingest') logger = logging.getLogger('logdna') logger.setLevel(logging.INFO) handler = LogDNAHandler( key=key, url=url, index_meta=True, # Optional: index metadata as searchable fields tags=['python', 'test'], app='myapp', env='production', level=logging.INFO, ) logger.addHandler(handler) logger.info('Hello from LogDNA Python logger!', {"custom": "metadata"}) # Ensure logs are flushed before exit import atexit atexit.register(handler.flush)
Debug
Known issues
breakingIn version 1.18.10, authentication was changed to use the 'apikey' HTTP header instead of the 'Authorization' header. Older versions used 'Authorization: Bearer <key>'. This breaks compatibility with setups that relied on the old header format.
fix
Upgrade to >= 1.18.10 or ensure your network config allows the 'apikey' header. The library automatically uses the new header; no code change required if using the same key parameter.
affects: < 1.18.10
gotchaLogDNAHandler.flush() must be called explicitly on program exit to avoid losing buffered logs. The library does not auto-flush on shutdown.
fix
Register an atexit handler: `atexit.register(handler.flush)` or flush manually before exit.
affects: all
gotchaThe LogDNAHandler's 'index_meta' parameter defaults to False. If you pass metadata as a dictionary and expect it to be searchable, set index_meta=True explicitly.
fix
When creating the handler, include `index_meta=True` to index metadata fields.
affects: all
deprecatedThe 'log_error_response' option was introduced in v1.18.3 for debugging but is not officially documented. It silences errors when set to False, which may hide connectivity issues.
fix
Avoid using this option in production. If you must, set it to True (default) to see errors.
affects: >= 1.18.3
Errors
Common errors & fixes
AttributeError: module 'logging' has no attribute 'LogDNAHandler'
Trying to import LogDNAHandler as a standard library class.
fix
Use `from logdna import LogDNAHandler` instead of `from logging import LogDNAHandler`.
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='logs.logdna.com', port=443): Max retries exceeded with url: /logs/ingest
Network/firewall blocking outbound HTTPS to LogDNA ingestion endpoint, or invalid URL.
fix
Verify your LOGDNA_URL is correct and network allows outbound traffic to logs.logdna.com:443. If using a proxy, configure it via environment variables (e.g., HTTP_PROXY, HTTPS_PROXY).
logdna.exceptions.LogDNAError: 401 Unauthorized
Invalid or missing ingestion key.
fix
Set LOGDNA_INGESTION_KEY environment variable to a valid key. Check that the key is not expired.
Upgrade
Version history
1.18.12latest on PyPI · released Jul 27, 2023
Audit
Dependencies
requestsrequiredUsed for HTTP communication with LogDNA ingestion endpoint
certifirequiredProvides SSL certificate bundle for secure connections
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
2
Resources
logdna — pip install logdna · libregistry