1. Introduction
- DatadogLogger
- LokiLogger
- NewRelicLogger
- LogstashLogger
Each sink inherits BaseSink and supports both synchronous (requests) and asynchronous (aiohttp) delivery modes.
2. Behavior and Context
These adapters are designed for vendor or collector HTTP ingestion endpoints. They follow a shared behavioral model:
- lazy session creation for async mode
- payload formatting per backend schema
- best-effort delivery (exceptions are swallowed)
- optional endpoint override fields for testing/custom routing
3. Purpose
- Vendor Integration: Native payload shape for common observability platforms.
- Operational Simplicity: Zero custom adapter code required by consumers.
- Runtime Flexibility: Sync and async APIs with common sink interface.
4. High-Level API & Examples
Example 1: Datadog Sink
python
from jazzmine.logging.sinks.http_sinks import DatadogLogger
sink = DatadogLogger(
sink_config={
"type": "datadog",
"api_key": "<dd_api_key>",
"site": "datadoghq.com",
"service": "chat-gateway",
},
logger_name="chat-gateway",
level="INFO",
use_json=True,
)
sink.initialize()
sink.info("request served", status=200)
sink.shutdown()Example 2: Loki Sink with Labels
python
from jazzmine.logging.sinks.http_sinks import LokiLogger
sink = LokiLogger(
sink_config={
"type": "loki",
"url": "http://localhost:3100/loki/api/v1/push",
"labels": {"job": "api", "env": "prod"},
},
logger_name="api",
level="INFO",
use_json=True,
)
sink.initialize()
sink.warning("rate limit near threshold", percentage=83)5. Detailed Class Functionality
DatadogLogger
- Config fields: api_key, site, service, optional url
- Endpoint default: https://http-intake.logs.<site>/api/v2/logs
- Payload includes: ddsource, service, message, uppercase level, extra kwargs
- Header includes DD-API-KEY
LokiLogger
- Config fields: url, labels
- Formats Loki push payload:
- streams list
- per-stream labels merged with runtime level
- nanosecond timestamp string
- Includes kwargs by appending JSON text to log line
NewRelicLogger
- Config fields: license_key, region, optional url
- Region-based endpoint default:
- US: https://log-api.newrelic.com/log/v1
- EU: https://log-api.eu.newrelic.com/log/v1
- Sends list payload with service/message metadata
- Header includes X-License-Key
LogstashLogger
- Config fields: url
- Payload includes @timestamp, message, level, logger name, kwargs
- Expected to target Logstash HTTP input pipeline
Shared Lifecycle
- initialize() sets endpoint/config and marks sink initialized.
- shutdown() closes async session via asyncio.create_task when present.
- log() uses requests.post (or equivalent) with timeout.
- alog() creates/reuses aiohttp.ClientSession and sends asynchronously.
6. Error Handling
- Network and serialization errors are swallowed (fail-open behavior).
- No explicit retry/backoff logic is implemented.
- Missing endpoint credentials typically cause upstream API rejection but do not raise to caller.
7. Remarks
- These sinks prioritize application continuity over guaranteed delivery.
- For compliance-critical pipelines, add retries and response auditing around these transports.
- Ensure credentials are provided via secure secret management, not hard-coded config.