Skip to Content

Python App Instrumentation

Follow the steps below to auto-instrument your Python service. When complete, your service will start emitting logs, metrics, and traces to Lakerunner.

Local Testing

  1. Get a Cardinal API key.

    Follow the steps in the Overview to mint an ingest API key.

  2. Install the OpenTelemetry dependencies:

    pip install opentelemetry-distro pip install opentelemetry-exporter-otlp
  3. Enable auto-instrumentation:

    opentelemetry-bootstrap --action=install
  4. Export the following environment variables:

    export OTEL_SERVICE_NAME="your-service-name" # Set your service name export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=local" # local/dev/staging/prod export OTEL_METRICS_EXPORTER="otlp" export OTEL_LOGS_EXPORTER="otlp" export OTEL_TRACES_EXPORTER="otlp" export OTEL_EXPORTER_OTLP_ENDPOINT="https://otelhttp.intake.<your-region>.aws.cardinalhq.io" export OTEL_EXPORTER_OTLP_HEADERS="x-cardinalhq-api-key=<your-api-key>" # Set your API key
  5. Run your application:

    opentelemetry-instrument python <your-app.py>
  6. Validate that Lakerunner is receiving data.

    Exercise the service by calling some API endpoints or causing some logs and metrics to be emitted. Wait a few minutes, then query for your service in the Cardinal dashboard.

Docker

Set the environment variables outlined above in your Docker container runtime configuration.

  • Update OTEL_RESOURCE_ATTRIBUTES to set deployment.environment.name for your environment.
  • If you run an OpenTelemetry Collector, set OTEL_EXPORTER_OTLP_ENDPOINT to your Collector’s OTLP receiver endpoint, and forward to Lakerunner from the Collector. See Already running an OpenTelemetry Collector?.

Kubernetes

Set the environment variables outlined above in your Deployment or StatefulSet manifest.

  • Update OTEL_RESOURCE_ATTRIBUTES to set deployment.environment.name for your environment.
  • If you run an OpenTelemetry Collector, set OTEL_EXPORTER_OTLP_ENDPOINT to your Collector’s OTLP receiver endpoint, and forward to Lakerunner from the Collector. See Already running an OpenTelemetry Collector?.

Reach out to support@cardinalhq.io for support or to ask questions not answered in our documentation.

Last updated on