Resource Detection

The resource attributes the Java distribution contributes, how they are ordered against the upstream agent's own, and which detectors it deliberately does not ship.

Note: This page is auto-generated from the opentelemetry-java-distribution  repository.

The distribution adds a few resource attributes of its own and keeps every detector the upstream agent ships, with the same defaults. This page describes configuration from environment variables. A host with a declarative configuration file is covered at the end.

Attributes the distribution adds

AttributeValue
telemetry.distro.namedash0-java
telemetry.distro.versionthe version of this distribution
dash0.package.namethe Dash0 Linux package that installed the agent, such as dash0-java-autoinstrumentation
dash0.package.versionthe version of that package

The two dash0.package.* attributes are present only when the agent was installed by a Dash0 Linux package. The package writes them to dash0-resource-attributes.properties in the directory of the agent jar, and the agent reads every key in that file. The extension jar does not read the file.

If you set the same name with OTEL_RESOURCE_ATTRIBUTES, your value wins.

Detectors that run by default

AttributesSource
container.idthe container runtime, when the JVM runs in a container
host.name, host.archthe host
os.type, os.description, os.versionthe operating system
process.pid, process.executable.path, process.command_argsthe JVM process
process.runtime.name, process.runtime.version, process.runtime.descriptionthe JVM
service.instance.ida random ID per process
service.name, service.versionsee below

process.command_args contains the full command line. The agent masks the values of system properties with names like password, so -Dpassword=hunter2 is exported as -Dpassword=***.

How the service name is chosen

The first of these that gives a name wins:

  1. OTEL_SERVICE_NAME, or service.name in OTEL_RESOURCE_ATTRIBUTES.
  2. A Spring application name. The agent looks for --spring.application.name= on the command line, the spring.application.name system property and SPRING_APPLICATION_NAME. It then looks in application.properties and application.yml in the working directory and on the class path, and in bootstrap files on the class path.
  3. Implementation-Title in the manifest of the jar started with java -jar.
  4. The file name of that jar, without .jar.
  5. Otherwise, unknown_service:java.

With a configuration file that reads OTEL_RESOURCE_ATTRIBUTES through attributes_list, a service.name in OTEL_RESOURCE_ATTRIBUTES wins over OTEL_SERVICE_NAME, because the agent applies attributes_list after every detector.

How the JVM is startedservice.name
java -cp … with nothing else setunknown_service:java
java -jar my-payments-service.jarmy-payments-service
the same, with Implementation-Title: payments in the manifestpayments
the same, plus -Dspring.application.name=my-spring-appmy-spring-app
any of these, plus OTEL_SERVICE_NAME=checkoutcheckout

The Spring sources are read even when the application does not use Spring. A spring.application.name meant for a different program in the same working directory becomes your service name.

Tomcat started with catalina.sh, the start scripts Gradle and Maven generate, and container images that run java -cp all end up with unknown_service:java. Set OTEL_SERVICE_NAME for those workloads.

service.version comes from build.version in a Spring Boot META-INF/build-info.properties, or else from Implementation-Version in the jar manifest.

Cloud detectors

The cloud detectors are off by default, as they are in the upstream agent. Turn on the group for the cloud a workload runs on:

VariableDetectors
OTEL_RESOURCE_PROVIDERS_AWS_ENABLED=trueEC2, ECS, EKS, Elastic Beanstalk, Lambda
OTEL_RESOURCE_PROVIDERS_AZURE_ENABLED=trueAzure VM, App Service, Functions
OTEL_RESOURCE_PROVIDERS_GCP_ENABLED=trueGoogle Cloud, including GCE, GKE, Cloud Run, Cloud Functions and App Engine
OTEL_RESOURCE_PROVIDERS_CLOUDFOUNDRY_ENABLED=trueCloud Foundry

The matching system property is -Dotel.resource.providers.aws.enabled=true, and so on for the others.

Enable only the group for the cloud you are on. The EC2, Azure VM and Google Cloud detectors call a metadata endpoint while the JVM starts, and the application waits for them. On a host where that traffic is silently dropped, we measured the aws group adding about 4 seconds to startup and the azure group about 5 seconds. The Google Cloud detector sets no timeout, so it can wait indefinitely when metadata.google.internal resolves but does not answer. The other detectors only read environment variables or local files.

Only one of the AWS, Azure and Google Cloud detectors applies per process. The first one that finds its cloud sets the cloud.* attributes, and the others are skipped.

On Azure App Service and Azure Functions, the azure group sets service.name from WEBSITE_SITE_NAME. That replaces a name the JVM would otherwise get from Spring, the manifest or the jar file. OTEL_SERVICE_NAME still wins.

Turning on part of a group

To use the ECS, Beanstalk and Lambda detectors without the EC2 metadata call, turn the group on and disable the EC2 detector:

export OTEL_RESOURCE_PROVIDERS_AWS_ENABLED=true
export OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS=io.opentelemetry.contrib.aws.resource.Ec2ResourceProvider

In a Kubernetes pod that is not on EKS, also add io.opentelemetry.contrib.aws.resource.EksResourceProvider to the list. That detector calls the Kubernetes API server, with a 2 second timeout, in every pod that mounts a service account token. For the azure group, the detector to disable is io.opentelemetry.contrib.azure.resource.AzureVmResourceProvider.

Do not use OTEL_JAVA_ENABLED_RESOURCE_PROVIDERS to turn on one detector. It runs only the detectors it names and switches off all others, including the ones that read OTEL_SERVICE_NAME and set telemetry.distro.name.

host.id

host.id is off by default. Turn it on with OTEL_RESOURCE_PROVIDERS_HOST_ID_ENABLED=true.

On Linux it is read from /etc/machine-id. That suits a host where a Dash0 Linux package installed the agent. Do not turn it on in containers. Every container built from the same image reports the same host.id, and some images, such as eclipse-temurin:21, have an empty /etc/machine-id and report none. On macOS and Windows the agent starts a subprocess to read the ID, which adds to startup time.

Kubernetes

The distribution has no Kubernetes detector. In a pod instrumented by the Dash0 operator, the operator sets k8s.namespace.name, k8s.pod.name, k8s.pod.uid and k8s.container.name through OTEL_RESOURCE_ATTRIBUTES. In a pod the operator does not instrument, set them yourself the same way, for example with the Kubernetes downward API.

Under a configuration file

When a declarative configuration file configures the SDK, none of the detectors above run and the OTEL_RESOURCE_PROVIDERS_* toggles have no effect. These run instead:

  • the detectors the file names under resource.detection/development, from the table below
  • host, process and service, which the distribution adds when the file does not name them
  • the agent's own detector for telemetry.distro.*, whose values the Dash0 ones replace

The attributes differ from the ones above in three ways:

  • The host detector adds host.id, and it cannot be turned off separately from host.name.
  • The process detector does not add process.command_args.
  • container.id is added only when the file names the container detector.
DetectorAttributes
hosthost.name, host.arch, host.id and the os.* attributes
processprocess.pid, process.executable.path and the process.runtime.* attributes
serviceservice.instance.id, and service.name from OTEL_SERVICE_NAME
jarservice.name from the name of the jar passed to java -jar
manifestservice.name and service.version from the jar manifest
springservice.name and service.version from Spring Boot
containercontainer.id

A later detector in the list overwrites an earlier one. List service after jar, manifest and spring, so that OTEL_SERVICE_NAME wins when it is set. Without jar, manifest and spring, a JVM that sets no OTEL_SERVICE_NAME reports unknown_service:java.

The distribution has no detector with a dash0_ name. A detector name the agent does not know stops it from starting.

OTEL_RESOURCE_ATTRIBUTES applies only when the file refers to it, as the file from the Dash0 Linux packages does. Values from the package's dash0-resource-attributes.properties win over detected values in this mode.

host.id is the contents of /etc/machine-id. To leave it out, add it to resource.detection/development.attributes.excluded. OTEL_JAVA_ENABLED_RESOURCE_PROVIDERS and OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS have no effect under a configuration file either.

Your own attributes

Add attributes with OTEL_RESOURCE_ATTRIBUTES, as comma-separated key=value pairs. A configuration file reads it only through attributes_list:

resource:
  attributes_list: ${OTEL_RESOURCE_ATTRIBUTES:-}

To drop a detected attribute under a configuration file, add a glob pattern matching its name to resource.detection/development.attributes.excluded.

Last updated: