App Instrumentation
Python

Python App Instrumentation

Follow the steps below to auto-instrument your Python service. When completed, your service will appear in the Cardinal Service Catalog, and Chip will begin monitoring it.

Local Testing

  1. Get a Cardinal API key:

Sign in to your Cardinal account, and get an API key from the Organization Settings > API Keys section.

  1. Install the OpenTelemetry dependencies:
pip install opentelemetry-distro
pip install opentelemetry-exporter-otlp
  1. Enable auto-instrumentation:
opentelemetry-bootstrap --action=install
  1. 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.us-east-2.aws.cardinalhq.io"
export OTEL_EXPORTER_OTLP_HEADERS="x-cardinalhq-api-key=<your-api-key>" # Set your API key
  1. Run your application:
opentelemetry-instrument python <your-app.py>
  1. Validate that Cardinal is receiving data:

Exercise the service by calling some API endpoints, or causing some logs or metrics to be emitted. Wait for a few minutes, then visit the Service Catalog in the Cardinal UI to check that your service appears in the list.

Docker

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

  • Update OTEL_RESOURCE_ATTRIBUTES to set the deployment.environment.name value to your environment.
  • If you run an OpenTelemetry Collector, set the OTEL_EXPORTER_OTLP_ENDPOINT to your Collector's OTLP Receiver endpoint, and follow the steps in the OTLP Export to Cardinal section to forward data to Cardinal.

Kubernetes

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

  • Update OTEL_RESOURCE_ATTRIBUTES to set the deployment.environment.name value to your environment.
  • If you run an OpenTelemetry Collector, set the OTEL_EXPORTER_OTLP_ENDPOINT to your Collector's OTLP Receiver endpoint, and follow the steps in the OTLP Export to Cardinal section to forward data to Cardinal.