Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fintegrations%2Fsdks%2Fpython-sdk.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fintegrations%2Fsdks%2Fpython-sdk.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

Warning

**Deprecation Notice**: The Coralogix Python SDK (`coralogix_logger`) will be 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 [end-of-life notice](https://docs-docusaurus.kinsta.page/user-guides/latest-updates/deprecations/python-logger-sdk/.md) for migration details.

# Python

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[​](#package-dependencies-setup "Direct link to 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://docs-docusaurus.kinsta.page/user-guides/account-management/account-settings/coralogix-domain/.md) using the domain selector at the top of the page.

## Application implementation[​](#application-implementation "Direct link to 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[​](#worker-processes-with-uwsgi "Direct link to 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[​](#logging-output "Direct link to Logging output")

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

#### OpenTelemetry Collector[​](#opentelemetry-collector "Direct link to OpenTelemetry Collector")

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

[![](/assets/images/otel_screenshot-30e0fac7b04573c9d7efe22c3fffcbcf.webp)](https://docs-docusaurus.kinsta.page/assets/images/otel_screenshot-30e0fac7b04573c9d7efe22c3fffcbcf.webp)

#### Coralogix OpenTelemetry endpoint[​](#coralogix-opentelemetry-endpoint "Direct link to Coralogix OpenTelemetry endpoint")

Authenticate with your [Send-Your-Data API key](https://docs-docusaurus.kinsta.page/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"
```

[![](/assets/images/coralogix_screenshot-82d20562fe0e7d208465aeff57b2bf44.webp)](https://docs-docusaurus.kinsta.page/assets/images/coralogix_screenshot-82d20562fe0e7d208465aeff57b2bf44.webp)

### Additional resources[​](#additional-resources "Direct link to Additional resources")

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