A production-grade OpenTelemetry logger for Coralogix gRPC endpoints.
Reason this release was yanked:
Wrong app metadata collected
Project description
Coralogix OTel Logger
A production-grade, highly resilient OpenTelemetry (OTel) logger for Python applications sending structured data to Coralogix via gRPC.
Based on Official Coralogix Documentation
This package is designed to solve the common pitfalls of enterprise OTel deployments, acting as a drop-in integration that natively complements standard structured telemetry workflows.
Why This Exists
When deploying OTel in corporate environments, engineers typically run into three major roadblocks. This logger handles them automatically:
- Global State Conflicts: The OTel
LoggerProviderrequires strict singleton management. This class safely guards initialization, cleanly reusing an existing provider if found, to prevent duplicate providers and broken pipelines inside containerized architectures. - Corporate SSL / Proxy MITM: Built-in support for passing custom SSL certificates (
cert_path) when operating behind strict corporate firewalls that perform deep packet SSL inspection. - Eliminating UI Rendering Ambiguity: Logging systems often drop data or break dashboard layouts when dynamic data structures vary. By routing all calls through an internal data transformation layer, this SDK maps an explicit plaintext summary headline to the root
"message"key while cleanly formatting and nesting complex metadata structures below it. This eliminates platform-side heuristic guessing games entirely.
Installation
pip install coralogix-otel-logger
Environment Configuration
Instead of hardcoding sensitive tokens or routing domains in your code, you can leverage native infrastructure environment variables to configure the SDK automatically:
| Environment Variable | Expected Values | Behavior |
|---|---|---|
CORALOGIX_API_KEY |
str (e.g., cx-...) |
The private Send-Your-Data administrative token. Used automatically if api_key is omitted in the constructor. |
CORALOGIX_REGION |
eu1, eu2, us1, us2, us3, ap1, ap2, ap3 |
Automatically standardizes and resolves the target endpoint to https://ingress.{region}.coralogix.com:443. Case-insensitive. |
Note: Explicitly passing code parameters (api_key or domain) in the class constructor will always take priority and override environment variables.
Tuning the Telemetry Transport
Under the hood, this logger implements the OpenTelemetry BatchLogRecordProcessor. To protect the gRPC network transport boundary and prevent memory blowouts (like hitting Coralogix's 32KB per-log or 2MB per-batch limits), structural safety boundaries are strictly hardcoded:
max_export_batch_size=50max_queue_size=2048
However, export latency is fully under your control via the flush_delay_ms parameter in the constructor (defaults to 5000 ms).
- For long-running Daemons/Microservices: Leave the default (
5000). It optimizes network bandwidth by batching logs together over 5-second intervals. - For ephemeral CI/CD automation scripts: Set it low (e.g.,
200). This ensures high-throughput, low-latency execution without waiting for background timers.
Quick Start
Initialize the logger once in your application entry point.
import os
from cxlogger import CoralogixOTelLogger
# 1. Initialize the logger
# Leaving api_key empty makes the SDK look for os.environ["CORALOGIX_API_KEY"]
coralogix_logger = CoralogixOTelLogger(
app_name="ldap-manager",
subsystem_name="dynamic-secrets",
log_level="info", # Optional: defaults to "info"
flush_delay_ms=5000 # Optional: defaults to 5000ms
)
# 2. Prepare structured dictionary data
audit_data = {
"event_type": "New Event Type",
"context": {
"one": "45345",
"two": "JLrffsd",
"pass": True
}
}
# 3. Ship it cleanly using standard pythonic logging signatures
coralogix_logger.info("GitLab MR Security Audit Event", payload=audit_data)
Flushing the Pipeline (CI/CD Safety)
OpenTelemetry utilizes unmanaged background worker threads to transmit data over the network. If you are running short-lived automation scripts (like a GitLab CI runner), the Python interpreter will often exit and kill these background threads before they have time to transmit your logs, resulting in silent data loss.
While this package provides an atexit fallback hook, you should always explicitly flush the logger in ephemeral environments.
Option A: The Context Manager (Recommended)
Using a with block guarantees that the memory queue is flushed exactly when the block concludes, gracefully handling application errors along the way.
with CoralogixOTelLogger(app_name="auth", subsystem_name="audit", flush_delay_ms=200) as logger:
logger.info("Pipeline started.")
# Do work...
logger.info("Pipeline finished.", payload={"status": "success"})
# <-- The gRPC pipeline is fully and safely drained the moment execution leaves the block.
Option B: Explicit Flush
If you are passing the logger around multiple files and cannot use a context manager, manually call .flush() right before your script issues a sys.exit() or return.
logger.info("Final log entry.")
# Force OpenTelemetry to block and transmit all background queues immediately
logger.flush()
Fail-Safe Typing Enforcement
To maintain perfectly predictable schemas across your team, the payload argument strictly expects a Python dictionary (dict).
If a developer mistakenly passes an invalid type (such as a raw string or list) into the payload parameter, the SDK safeguards your cluster: it will not crash your runtime environment. Instead, it intercepts the error, automatically flags the log severity to ERROR, and routes a high-visibility structural misuse notification to your Coralogix dashboard containing the raw rejected chunk so you can catch the bug instantly in staging.
Features
- Pristine Public Interface: Exposes only standard pythonic logger methods (
.debug(),.info(),.warning(),.error(), and.critical()), preventing developer friction and code complexity. - Unified UI Alignment: Automatically positions your string message to the root
"message"field, providing a reliable summary headline in the log grid while rendering your payload as a clean, expandable JSON tree. - Credential Masking: Overrides native internal
__repr__bindings. Inspecting or printing the logger instance inside terminal prompts (IPython), stack traces, or environment outputs automatically masks your private administrative keys as'***'. - Isolated Serialization Guards: Heavy JSON encoding processes are fully wrapped inside isolated exception blocks, ensuring logging subsystems never trigger unexpected fatal thread panics.
- PEP 8 Compliant: Clean, predictable class design.
License
Apache 2.0 License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coralogix_otel_logger-1.0.0.tar.gz.
File metadata
- Download URL: coralogix_otel_logger-1.0.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a7845ad2719066d38f6ac94b6ecfe9df37fff2968d0b27435892ce42ea23295
|
|
| MD5 |
e47ef9cb4433e506401f7eca93ab88bd
|
|
| BLAKE2b-256 |
27bb008a0c30bc73e72f8cd611fa5c779b27a295c439b120174939c3f2c199fa
|
Provenance
The following attestation bundles were made for coralogix_otel_logger-1.0.0.tar.gz:
Publisher:
publish.yml on nix-power/coralogix-otel-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coralogix_otel_logger-1.0.0.tar.gz -
Subject digest:
7a7845ad2719066d38f6ac94b6ecfe9df37fff2968d0b27435892ce42ea23295 - Sigstore transparency entry: 1872955510
- Sigstore integration time:
-
Permalink:
nix-power/coralogix-otel-logger@e5bcdc3eccd54bea1e7e1db9a1c473c0e4a085eb -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/nix-power
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e5bcdc3eccd54bea1e7e1db9a1c473c0e4a085eb -
Trigger Event:
release
-
Statement type:
File details
Details for the file coralogix_otel_logger-1.0.0-py3-none-any.whl.
File metadata
- Download URL: coralogix_otel_logger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20e6b59afa3f909597fcca7c53953a419f47e9391df565f7ef83275242e70f39
|
|
| MD5 |
a59b3f1bd36f12ffbb4248d2f0e7f5a3
|
|
| BLAKE2b-256 |
3207a59ed2b96bab97375402a4b2002955e1e0b98e1df95f90bc2bd11052e24a
|
Provenance
The following attestation bundles were made for coralogix_otel_logger-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on nix-power/coralogix-otel-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coralogix_otel_logger-1.0.0-py3-none-any.whl -
Subject digest:
20e6b59afa3f909597fcca7c53953a419f47e9391df565f7ef83275242e70f39 - Sigstore transparency entry: 1872955673
- Sigstore integration time:
-
Permalink:
nix-power/coralogix-otel-logger@e5bcdc3eccd54bea1e7e1db9a1c473c0e4a085eb -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/nix-power
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e5bcdc3eccd54bea1e7e1db9a1c473c0e4a085eb -
Trigger Event:
release
-
Statement type: