---
title: Python SDK
description: Send Python logs to Coralogix with the OpenTelemetry Python SDK, a `LoggingHandler`, and OTLP/gRPC, replacing the deprecated `coralogix_logger`.
url: https://coralogix.com/docs/integrations/sdks/python-sdk/
product: ingress
feature: Logs Ingress
feature_id: logs.ingress
feature_identifier: ingress/logs.ingress
last_updated: '2026-10-29'
---

Warning

**Deprecation Notice**: The Coralogix Python SDK (`coralogix_logger`) is deprecated in favor of the [OpenTelemetry SDK](https://opentelemetry.io/docs/languages/python/) and will no longer be supported after **June 30, 2026**. See the [Python OpenTelemetry instrumentation](https://coralogix.com/docs/opentelemetry/instrumentation-options/python-opentelemetry-instrumentation.md) guide for setup options and the [end-of-life notice](https://coralogix.com/docs/user-guides/latest-updates/deprecations/python-logger-sdk.md) for migration details.

# PythonDeprecated

This guide shows how to send Python logs to Coralogix using the [OpenTelemetry Python SDK](https://opentelemetry.io/docs/languages/python/) with the OTLP/gRPC log exporter and a [`LoggingHandler`](https://opentelemetry-python.readthedocs.io/en/latest/sdk/_logs.html#opentelemetry.sdk._logs.LoggingHandler) attached to the standard library `logging` module. This replaces shipping logs through the legacy `coralogix_logger` package.

## Package dependencies setup

Install the OpenTelemetry SDK and OTLP gRPC exporter (versions are examples; use the latest compatible releases from PyPI):

```
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-grpc
```

A minimal `requirements.txt` can look like this:

```
opentelemetry-sdk

opentelemetry-exporter-otlp-proto-grpc
```

Select the <!-- -->https\://ingress. endpoint that corresponds to your Coralogix [domain](https://coralogix.com/docs/user-guides/account-management/account-settings/coralogix-domain.md) using the domain selector at the top of the page.

## Application implementation

1. Build a `LoggerProvider` with a `Resource` that sets `service.name`, `cx.application.name`, and `cx.subsystem.name`.
2. Add a `BatchLogRecordProcessor` with an `OTLPLogExporter` pointing at your OTLP/gRPC endpoint (the sample uses local port `4317` by default).
3. Call `set_logger_provider`, attach `LoggingHandler` to your application loggers, and optionally configure `TracerProvider` so logs inside spans pick up trace context.

```
import logging

import os

import time



from opentelemetry import trace

from opentelemetry._logs import set_logger_provider

from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter

from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler

from opentelemetry.sdk._logs.export import BatchLogRecordProcessor

from opentelemetry.sdk.resources import Resource

from opentelemetry.sdk.trace import TracerProvider





def create_logger_provider(endpoint: str) -> LoggerProvider:

    resource = Resource.create(

        {

            "service.name": os.getenv("OTEL_SERVICE_NAME", "python-otel-logs-sample"),

            "cx.application.name": os.getenv("CORALOGIX_APPLICATION", "python-otel-app"),

            "cx.subsystem.name": os.getenv("CORALOGIX_SUBSYSTEM", "worker"),

        }

    )



    provider = LoggerProvider(resource=resource)

    provider.add_log_record_processor(BatchLogRecordProcessor(OTLPLogExporter(endpoint=endpoint)))

    return provider





def main() -> None:

    endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4317")



    logger_provider = create_logger_provider(endpoint)

    set_logger_provider(logger_provider)



    handler = LoggingHandler(level=logging.NOTSET, logger_provider=logger_provider)

    app_logger = logging.getLogger("python-otel-example")

    app_logger.setLevel(logging.INFO)

    app_logger.addHandler(handler)



    tracer_provider = TracerProvider()

    trace.set_tracer_provider(tracer_provider)

    tracer = trace.get_tracer("python-otel-example")



    app_logger.info("hello python logging with OpenTelemetry")



    with tracer.start_as_current_span("manual-span"):

        app_logger.warning("python log with trace correlation")



    time.sleep(1.5)

    logger_provider.force_flush()

    logger_provider.shutdown()

    tracer_provider.shutdown()

    print("Done: flush + shutdown completed")





if __name__ == "__main__":

    main()
```

**Notes**

* Call `force_flush()` / `shutdown()` on the `LoggerProvider` before exit so batched OTLP payloads are delivered.
* The example imports `LoggingHandler` and related types from `opentelemetry.sdk._logs`, matching the current OpenTelemetry Python package layout. If you upgrade packages, follow the [OpenTelemetry Python logs documentation](https://opentelemetry.io/docs/languages/python/instrumentation/#logs) for any API moves.

### Worker processes with uWSGI

If you use uWSGI without threads, the Python runtime might not allow background export threads used by the SDK. Turn on threading (for example `uwsgi ... --enable-threads` or `enable-threads = true` in your uWSGI configuration file). When you fork workers, initialize the `LoggerProvider` and handlers **after** the fork (for example with uWSGI’s `@postfork` hook) so each worker has its own provider instance.

### Logging output

With the OpenTelemetry SDK, you can send logs either to a local [OpenTelemetry Collector](https://coralogix.com/docs/opentelemetry/kubernetes-observability/kubernetes-observability-using-opentelemetry.md) or directly to Coralogix using an OTLP endpoint.

#### OpenTelemetry Collector

Set `OTEL_EXPORTER_OTLP_ENDPOINT` to your collector’s OTLP/gRPC address (often `http://localhost:4317` or `http://collector:4317`).

[![](/docs/assets/images/otel_screenshot-30e0fac7b04573c9d7efe22c3fffcbcf.webp)](https://coralogix.com/docs/assets/images/otel_screenshot-30e0fac7b04573c9d7efe22c3fffcbcf.webp)

#### Coralogix OpenTelemetry endpoint

Authenticate with your [Send-Your-Data API key](https://coralogix.com/docs/user-guides/account-management/api-keys/send-your-data-api-key.md) and point the OTLP exporter at your Coralogix endpoint.

```
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingress.eu2.coralogix.com:443

OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer send_your_data_key"

OTEL_RESOURCE_ATTRIBUTES="service.name=python-otel-logs-sample,cx.application.name=AppName,cx.subsystem.name=SubName"
```

[![](/docs/assets/images/coralogix_screenshot-82d20562fe0e7d208465aeff57b2bf44.webp)](https://coralogix.com/docs/assets/images/coralogix_screenshot-82d20562fe0e7d208465aeff57b2bf44.webp)

### Additional resources

|                      |                                                                                       |
| -------------------- | ------------------------------------------------------------------------------------- |
| OpenTelemetry Python | [OpenTelemetry Python docs](https://opentelemetry.io/docs/languages/python/)          |
| Coralogix Endpoints  | [Coralogix Endpoints](https://coralogix.com/docs/integrations/coralogix-endpoints.md) |
