OpenTelemetry OpenTelemetry instrumentation OpenTelemetry Environment Variables
Open source

OpenTelemetry Environment Variables

OpenTelemetry specifies standard environment variables for configuring exporters. These environment variables are supported across multiple programming languages and SDKs.

The most relevant environment variables are:

  • OTEL_SERVICE_NAME: The name of your application. The service name will be available as attributes for traces, metrics, and logs.
  • OTEL_RESOURCE_ATTRIBUTES: Additional metadata on the service such as service.version=1.1,deployment.environment=production.
  • OTEL_EXPORTER_OTLP_PROTOCOL: Can be http/protobuf or grpc.
  • OTEL_EXPORTER_OTLP_ENDPOINT: The endpoint to send the data to.

For example, if you run the OpenTelemetry Collector with the OTLP receiver accepting HTTP on localhost port 4318, you can configure your application as follows:

export OTEL_SERVICE_NAME="my-test-application"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"

If you want to send OpenTelemetry data directly to the Grafana Cloud, you need an additional authorization header with your Grafana instance ID and API key. The authentication header can be set using the OTEL_EXPORTER_OTLP_HEADERS variable.

The content of the Authorization header is the base64 encoded string <instance-id>:<api-key>. See Grafana Cloud docs for how to get your instance ID and API key. Let’s say the base64 encoded data looks like 123456abc123456abc, then you can set the authentication header like this:

export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic 123456abc123456abc"