SDK configuration

You are viewing the English version of this page because it has not yet been fully translated. Interested in helping out? See Contributing.

This spring starter supports configuration metadata, which means that you can see and autocomplete all available properties in your IDE.

General configuration

The OpenTelemetry Starter supports all the SDK Autoconfiguration (since 2.2.0).

You can update the configuration with properties in the application.properties or the application.yaml file, or with environment variables.

application.yaml example:

otel:
  propagators:
    - tracecontext
    - b3
  resource:
    attributes:
      deployment.environment: dev
      service:
        name: cart
        namespace: shop

Environment variables example:

export OTEL_PROPAGATORS="tracecontext,b3"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=dev,service.name=cart,service.namespace=shop"

SDK-level settings (resources, propagators, exporters) use the standard declarative configuration schema directly in application.yaml. System properties and environment variables still work to override values — see Environment variable overrides.

otel:
  file_format: '1.0'

  resource:
    attributes:
      - name: deployment.environment
        value: dev
      - name: service.name
        value: cart
      - name: service.namespace
        value: shop

  propagator:
    composite:
      - tracecontext:
      - b3:

Overriding Resource Attributes

As usual in Spring Boot, you can override properties in the application.properties and application.yaml files with environment variables.

For example, you can set or override the deployment.environment resource attribute (not changing service.name or service.namespace) by setting the standard OTEL_RESOURCE_ATTRIBUTES environment variable:

export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=prod"

Alternatively, you can use the OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_ENVIRONMENT environment variable to set or override a single resource attribute:

export OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_ENVIRONMENT="prod"

The second option supports SpEL expressions.

Note that DEPLOYMENT_ENVIRONMENT gets converted to deployment.environment by Spring Boot’s Relaxed Binding.

Disable the OpenTelemetry Starter

Set otel.sdk.disabled to true to disable the starter, e.g. for testing purposes:

otel:
  sdk:
    disabled: true

Set otel.disabled to true to disable the starter, e.g. for testing purposes.

Note: with declarative configuration, the property name is otel.disabled, not otel.sdk.disabled.

otel:
  file_format: '1.0'
  disabled: true

Programmatic configuration

See Programmatic configuration.

Resource Providers

The OpenTelemetry Starter includes the same resource providers as the Java agent:

In addition, the OpenTelemetry Starter includes the following Spring Boot specific resource providers:

Distribution Resource Provider

FQN: io.opentelemetry.instrumentation.spring.autoconfigure.resources.DistroVersionResourceProvider

AttributeValue
telemetry.distro.nameopentelemetry-spring-boot-starter
telemetry.distro.versionversion of the starter

Spring Resource Provider

FQN: io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringResourceProvider

AttributeValue
service.namespring.application.name or build.name from build-info.properties (see Service name)
service.versionbuild.version from build-info.properties

With declarative configuration, resource providers are configured explicitly as detectors under resource.detection/development.detectors. Only listed detectors are active — nothing is auto-discovered via SPI.

otel:
  resource:
    detection/development:
      detectors:
        - container: # container.id
        - host: # host.name, host.arch
        - host_id: # host.id
        - os: # os.type, os.description
        - process: # process.pid, process.executable.path, process.command_line
        - process_runtime: # process.runtime.name/version/description
        - service: # service.name, service.instance.id
        - spring: # service.name (from spring.application.name), service.version (from build-info)

The telemetry.distro.name and telemetry.distro.version attributes are always added automatically by the starter for troubleshooting purposes.

Service name

Using these resource providers, the service name is determined by the following precedence rules, in accordance with the OpenTelemetry specification:

  1. otel.service.name spring property or OTEL_SERVICE_NAME environment variable (highest precedence)
  2. service.name in otel.resource.attributes system/spring property or OTEL_RESOURCE_ATTRIBUTES environment variable
  3. spring.application.name spring property
  4. build-info.properties
  5. Implementation-Title from META-INF/MANIFEST.MF
  6. The default value is unknown_service:java (lowest precedence)

The service name depends on which resource detectors you include (see Resource Providers):

  1. service.name in otel.resource.attributes (highest precedence):

    otel:
      resource:
        attributes:
          - name: service.name
            value: my-spring-app
    
  2. The service detector — if included, auto-detects from OTEL_SERVICE_NAME:

    otel:
      resource:
        detection/development:
          detectors:
            - service:
    
  3. The spring detector — if included, detects from spring.application.name and build-info.properties:

    otel:
      resource:
        detection/development:
          detectors:
            - spring:
    
  4. The default value is unknown_service:java (lowest precedence)

Use the following snippet in your pom.xml file to generate the build-info.properties file:

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
springBoot {
  buildInfo {
  }
}