This folder contains examples to use OpenTelemetry integration with Grafana, and with Azure Application Insights.
Important
This example includes code that can be used to integrate OpenTelemetry telemetries with
versions of the framework before 2.3.2. Since 2.3.2, vendor-agnostic code from this
example have been included in the BlackSheep framework.
For more information, refer to the documentation at https://www.neoteroi.dev/blacksheep/opentelemetry/
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap --action=installFor Azure Application Insights, also install:
pip install azure-monitor-opentelemetry-exporterTo test, install also blacksheep and an ASGI server of your choice. For instance, uvicorn.
pip install blacksheep uvicorn- Install the dependencies like documented above, including
azure-monitor-opentelemetry-exporter. - Configure an environment variable
APP_INSIGHTS_CONNECTION_STRINGcontaining the connection string of an Azure Application Insights service. - Run the application with
uvicorn azureexample:app. - Generate some web requests to the example endpoints
/,/bad-request,/crash,/example. - Observe how logs appear in the Azure Application Insights service.
- Install the dependencies like documented above, including
azure-monitor-opentelemetry-exporter. - Obtain the necessary environment variables from the Grafana interface.
- Configure the environment variables. These variables can also be configured
in a
.envfile. - Run the application with
uvicorn grafanaexample:app. - Generate some web requests to the example endpoints
/,/bad-request,/crash,/example. - Observe how logs appear in the Azure Application Insights service.
Environment variables look like the following:
OTEL_RESOURCE_ATTRIBUTES="service.name=my-app,service.namespace=my-application-group,deployment.environment=production"
OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-north-0.grafana.net/otlp"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20******"
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
- The
otelpackage contains reusable code. otel.otlpcontains generic code that can be used with many services adhering to the OpenTelemetry standard, including Grafana.

