A production-grade OpenTelemetry logger for Coralogix gRPC endpoints.
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 without breaking existing console or file logs.
Why This Exists
When deploying OTel in corporate environments, engineers typically run into critical infrastructure roadblocks. This logger handles them automatically:
- Additive Handler Architecture: Instead of forcing you to manage two separate logging pipelines (one for
stdoutand one for Coralogix), this SDK seamlessly injects itself into any existing standard Python logger. - Deterministic Schemas via
extra: Raw JSON dumped to standard out causes mapping conflicts in database backends. This logger preserves clean, human-readable terminal output while routing deep structured metadata as OpenTelemetry attributes via Python's nativeextramechanism. - Accurate Caller Metadata: Solves the common "wrapper trap" by dynamically traversing execution stacks to bypass the SDK wrapper methods. Logs will accurately report the exact file, function, and line number of your application code, completely immune to interactive shells like Jupyter/IPython.
- Global State Conflicts: Safely guards OpenTelemetry singletons to prevent network leaks and duplication in containerized environments.
Installation
pip install coralogix-otel-logger
Environment Configuration
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. |
CORALOGIX_REGION |
eu1, eu2, us1, us2, us3, ap1, ap2, ap3 |
Automatically standardizes and resolves the target endpoint to https://ingress.{region}.coralogix.com:443. |
Integration Patterns
Because this wrapper is non-destructive, your development team can adopt it using either a clean abstraction or pure zero-dependency Python code.
Pattern 1: The Unified Wrapper (Clean Syntax)
Initialize the SDK targeting your application's existing logger name. The wrapper will safely adopt it. Your terminal stays clean, and Coralogix gets the rich payload.
import logging
from cxlogger import CoralogixOTelLogger
# 1. Your standard corporate logging setup
logger = logging.getLogger("auth_service")
logger.addHandler(logging.StreamHandler())
# 2. Additive initialization targeting your exact logger
with CoralogixOTelLogger(
app_name="ldap-mgr",
subsystem_name="audit",
logger_name="auth_service"
) as cx_logger:
audit_data = {"user": "alex_admin", "status": "verified"}
# Outputs clean text to terminal: "[INFO] Auth process completed"
# Streams structured JSON to Coralogix containing the audit_data attributes
cx_logger.info("Auth process completed", payload=audit_data)
Pattern 2: Pure Native Python Logging (Downstream Modules)
You only need to import and initialize the cxlogger SDK once at your application's entry point. Once the OTel handler is bound to Python's global registry, developers working in other files across the codebase can write standard native Python code without needing to import the SDK into their specific files.
1. At the Application Entry Point (e.g., main.py):
import logging
from cxlogger import CoralogixOTelLogger
# Set up your standard corporate logging
logger = logging.getLogger("auth_service")
logger.addHandler(logging.StreamHandler())
# Initialize the SDK exactly ONCE to equip the global logger with the Coralogix handler
cx_plugin = CoralogixOTelLogger(
app_name="auth",
subsystem_name="api",
logger_name="auth_service"
)
2. Deep inside another project file (e.g., lib/database.py):
import logging
# Notice: No cxlogger import needed here!
# Grabs the exact same logger object equipped during startup
logger = logging.getLogger("auth_service")
# By using Python's native `extra` keyword, the OpenTelemetry background worker
# automatically translates this into rich Coralogix JSON attributes!
logger.info(
"Data processed securely",
extra={"payload": {"bytes": 4096, "latency_ms": 120}}
)
Tuning the Telemetry Transport
OpenTelemetry utilizes unmanaged background worker threads to transmit data over the network. 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) and wrap the execution in a Context Manager (withblock). This ensures high-throughput execution and guarantees a synchronous network flush before the container dies.
Coralogix UI Rendering & Schema Alignment
OpenTelemetry maps log messages directly to the OTLP protocol body block. However, when an OTel packet contains rich key-value lists, the Coralogix frontend UI column template bypasses the native protocol body and scans the custom attribute tree searching for a root-level key string to render as the main dashboard headline.
To guarantee crisp row readability out of the box, this SDK intentionally injects a root-level "message" key inside your attributes.payload namespace.
A Note on Custom Infrastructure Schemas
message is the standard anchor for string headers. However, user-defined metadata spaces in Coralogix are dynamic. If your enterprise infrastructure team has manually deleted or renamed the "message" field mapping inside your Coralogix account's Schema Manager settings, the Coralogix column template will fail to resolve the path. It will fall back to an automated guessing heuristic, causing your main grid layout to randomly alternate text.
Ensure "message" is preserved as a designated String field in your account's schema configuration to lock down uniform layout fidelity across your logs.
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 list) into the payload parameter, the SDK safeguards your cluster: it will not crash your runtime environment. Instead, it intercepts the error, flags the log severity to ERROR, and routes a high-visibility structural misuse notification to your Coralogix dashboard.
License
Apache 2.0 License.
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.3.tar.gz.
File metadata
- Download URL: coralogix_otel_logger-1.0.3.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 |
8adafcaa75c0d669f5e348773727ac0ee928dd6d50fb2291557b82a6e1d31c67
|
|
| MD5 |
915cb9bb6b9be4057ab9535a1b592017
|
|
| BLAKE2b-256 |
d93bb290724d25aaa2d705f9a2f389b31e8e0dc6849c6d5bf3df380d8afd505e
|
Provenance
The following attestation bundles were made for coralogix_otel_logger-1.0.3.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.3.tar.gz -
Subject digest:
8adafcaa75c0d669f5e348773727ac0ee928dd6d50fb2291557b82a6e1d31c67 - Sigstore transparency entry: 1895265136
- Sigstore integration time:
-
Permalink:
nix-power/coralogix-otel-logger@a921a005a11e40d2c54ab29e2f2d8ffeed80b40d -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/nix-power
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a921a005a11e40d2c54ab29e2f2d8ffeed80b40d -
Trigger Event:
release
-
Statement type:
File details
Details for the file coralogix_otel_logger-1.0.3-py3-none-any.whl.
File metadata
- Download URL: coralogix_otel_logger-1.0.3-py3-none-any.whl
- Upload date:
- Size: 12.1 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 |
ea6e25e9f351fb285bd00d3eb48a5aa1aa14700f39dbc4b6ecc869ed3be697a0
|
|
| MD5 |
1521c01a1fa9bbdcfa05ed080042cc3e
|
|
| BLAKE2b-256 |
3e4ed9254050a65e49872311ee7124563657e729cca0b0d73cd9558557387458
|
Provenance
The following attestation bundles were made for coralogix_otel_logger-1.0.3-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.3-py3-none-any.whl -
Subject digest:
ea6e25e9f351fb285bd00d3eb48a5aa1aa14700f39dbc4b6ecc869ed3be697a0 - Sigstore transparency entry: 1895265231
- Sigstore integration time:
-
Permalink:
nix-power/coralogix-otel-logger@a921a005a11e40d2c54ab29e2f2d8ffeed80b40d -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/nix-power
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a921a005a11e40d2c54ab29e2f2d8ffeed80b40d -
Trigger Event:
release
-
Statement type: