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
-
Get a Cardinal API key.
Follow the steps in the Overview to mint an ingest API key.
-
Install the OpenTelemetry dependencies:
pip install opentelemetry-distro pip install opentelemetry-exporter-otlp -
Enable auto-instrumentation:
opentelemetry-bootstrap --action=install -
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 -
Run your application:
opentelemetry-instrument python <your-app.py> -
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_ATTRIBUTESto setdeployment.environment.namefor your environment. - If you run an OpenTelemetry Collector, set
OTEL_EXPORTER_OTLP_ENDPOINTto 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_ATTRIBUTESto setdeployment.environment.namefor your environment. - If you run an OpenTelemetry Collector, set
OTEL_EXPORTER_OTLP_ENDPOINTto 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.