Grafana Cloud RSS

Set up production instrumentation for Python

Follow these steps set up production Application Observability with a telemetry collector:

  1. Install the instrumentation library
  2. Configure an application
  3. Set up a telemetry data collector
  4. Run the application
  5. Observe the service in Application Observability


For a quick and easy local development setup, consult the quickstart documentation.

Application Observability - Architecture

Install the instrumentation library

Install the latest release of the OpenTelemetry Python package:

pip install opentelemetry-distro[otlp]
opentelemetry-bootstrap -a install


A number of popular Python libraries are auto-instrumented, including Flask and Django. You can find the full list here.


If you use a web server that spawns multiple processes to serve requests in parallel, follow the gunicorn guide. Other web servers, such as uWSGI, require a similar setup.

Configure an application

Next, customize the following shell script to configure an application:


Logs have to be enabled explicitly with OTEL_LOGS_EXPORTER=otlp and OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true, because it is still experimental.


Tracing can create a significant overhead in Python applications. Please adjust the sampling rate if you experience performance issues.

export OTEL_SERVICE_NAME=<Service Name> export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=<Environment>,service.namespace=<Namespace>,service.version=<Version>,<Instance>

export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true export OTEL_LOGS_EXPORTER=otlp opentelemetry-instrument flask run -p 8080

  1. Choose a Service Name to identify the service, for example cart
  2. Add attributes to filter data:
    • deployment.environment: Name of the deployment environment (staging or production)
    • service.namespace: A namespace to group similar services (e.g. shop would create shop/cart in Application Observability)
    • service.version: The application version, to see if a new version has introduced a bug
    • The unique instance, for example the Pod name (a UUID is generated by default)
  1. Replace flask run -p 8080 with the start command that runs the application to instrument

Set up a telemetry data collector

In production environments, a robust and flexible observability setup needs to process telemetry data before ingestion into databases. Follow the collector setup documentation to set up a collector to process and send telemetry data to Application Observability.

Finally, set the following environment variables from the exporter configuration:

export OTEL_EXPORTER_OTLP_ENDPOINT=<host>http://localhost:4318, remote host addressThe default local host address, or a remote host address.
export OTEL_EXPORTER_OTLP_PROTOCOL=<protocol>grpc, http/protobufThe default http/protobuf protocol or grpc

For example, for a local Grafana Alloy:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

Run the application

Finally, run the application with the shell script and make some requests to the service to send data to Grafana Cloud.

Observe the service in Application Observability

Open Application observability:

  1. Navigate to a stack https://<your-stack-name.>
  2. Expand the top left menu below the Grafana logo
  3. Click on Application

Activate metrics generation

Application Observability relies on metrics generated from traces already sent to Grafana Cloud Traces.

Metrics generation is self-serve, and can be enabled during onboarding and disabled from Application Observability configuration.

To complete the setup, click Activate Application Observability to enable metrics generation.

Enable metrics generation


After activating Application Observability and enabling metrics generation, it might take up to five minutes to generate metrics and show graphs.

Visualize and discover

Discover more about Application Observability in the documentation:

  • Service Inventory: filter, and search services and view RED metrics.
  • Service Overview: traces, logs, RED metrics, operations, and runtime information.
  • Service Map: graph of connected services, service dependencies, and data flow.

Example application

See the Rolldice service for a complete example setup.