Skip to content

Support OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES environment variablesΒ #43712

@mmanciop

Description

@mmanciop

The OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES environment variables are a fundamental mechanic of configuring applications that generate OpenTelemetry data [^1].

The OpenTelemetryAutoConfiguration however, does not honor these env vars. Instead, it sets the service.name attribute to be the Spring Application name (which, by the way, is a pretty solid default), and additionally sets the non-standard service.group attribute (which does not exist in the OpenTelemetry semantic conventions for the service.* namespace [^2]) using the application group (if anything, the right attribute to set is service.namespace).

The behavior of OpenTelemetryAutoConfiguration should be changed as follows:

  1. The resource attributes coming in through the management.opentelemetry should be right-merged with (i.e., should override in case of attribute key conflict) the default resource. (this is already current behavior)
  2. Right-merge the OTEL_RESOURCE_ATTRIBUTES
  3. Right-merge the service.name attribute if OTEL_SERVICE_NAME is set
  4. If no service.name and service.namespace are set, right-merge the current Spring Boot-specific attributes.

For explanatory purposes, I prepared this branch: https://github.com/mmanciop/spring-boot/tree/opentelemetry-resource-env-vars

I am happy to finalize it (mostly: write the missing tests) if there is interest.

Note: I initially raised the issue on Micrometer Tracing (Issue #931).

[^1] https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration
[^2] https://opentelemetry.io/docs/specs/semconv/resource/#service

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions