Skip to main content

A production-grade OpenTelemetry logger for Coralogix gRPC endpoints.

Reason this release was yanked:

Coralogix UI mismatches

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:

  1. Additive Handler Architecture: Instead of forcing you to manage two separate logging pipelines (one for stdout and one for Coralogix), this SDK seamlessly injects itself into any existing standard Python logger.
  2. 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 native extra mechanism.
  3. 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 (with block). This ensures high-throughput execution and guarantees a synchronous network flush before the container dies.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coralogix_otel_logger-1.0.1.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coralogix_otel_logger-1.0.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file coralogix_otel_logger-1.0.1.tar.gz.

File metadata

  • Download URL: coralogix_otel_logger-1.0.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coralogix_otel_logger-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a905886f67c180fc382bf33f868e865c4656dbd765591caaab56df02557c4d65
MD5 6228788f3469d0760fd4e54f63c8c48f
BLAKE2b-256 2baf69db23b4d7b34258fd8d403f9b586bd4119148604a4e1530c5c5ccb2703f

See more details on using hashes here.

Provenance

The following attestation bundles were made for coralogix_otel_logger-1.0.1.tar.gz:

Publisher: publish.yml on nix-power/coralogix-otel-logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coralogix_otel_logger-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for coralogix_otel_logger-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 047225f81e029fd62fd252663069bb4225151f3089ee16ac8e2db07dee3f567c
MD5 d1e293c05f4996d35e762550a73f556e
BLAKE2b-256 aefcdd2fa49ba07879815c51d9d6ec52641f84cbff152c174d6d160d422383a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for coralogix_otel_logger-1.0.1-py3-none-any.whl:

Publisher: publish.yml on nix-power/coralogix-otel-logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page