Java

The Dash0 distribution of the OpenTelemetry Java agent, as a DEB and RPM package.

The Dash0 distribution of the OpenTelemetry Java agent, packaged so the OpenTelemetry injector can load it into JVM processes on a host.

Compatibility

RequirementSupported
Java8 or later
ArchitecturesAny
Distribution requirementsSupported JVMs

Setup with the injector

This is the recommended setup: the injector instruments every JVM on the host when it starts, without changes to how you start your applications. There are two ways to install it.

With dash0-opentelemetry, install the metapackage. It brings the injector, the keyring and, as recommended packages, the language packages for all runtimes, Java included.

On Debian or Ubuntu:

sudo apt-get install dash0-opentelemetry

On Fedora, RHEL or Amazon Linux 2023:

sudo dnf install dash0-opentelemetry

With only the packages you need, install this package and the injector by name.

On Debian or Ubuntu:

sudo apt-get install dash0-injector dash0-java-autoinstrumentation

On Fedora, RHEL or Amazon Linux 2023:

sudo dnf install dash0-injector dash0-java-autoinstrumentation

In both cases, the package's drop-in at /etc/opentelemetry/injector/conf.d/java.conf tells the injector where the agent jar is. The injector then appends -javaagent:/usr/lib/opentelemetry/java/opentelemetry-javaagent.jar to JAVA_TOOL_OPTIONS for every JVM that starts, and applies default_env.conf to it. JVMs that are already running are instrumented only after they restart.

Then set the endpoint and the auth token in default_env.conf, as described under Configuration.

Setup without the injector

Install only this package.

On Debian or Ubuntu:

sudo apt-get install dash0-java-autoinstrumentation

On Fedora, RHEL or Amazon Linux 2023:

sudo dnf install dash0-java-autoinstrumentation

On its own, the package instruments nothing. It only suggests the injector, and apt and dnf do not install suggested packages. Load the instrumentation yourself when you start the process:

java -javaagent:/usr/lib/opentelemetry/java/opentelemetry-javaagent.jar -jar app.jar

Without the injector, default_env.conf is not applied: set the endpoint and the auth token in the environment of the process instead, as described under Configuration.

Configuration

All setups need the same settings, as environment variables:

VariableSets
OTEL_EXPORTER_OTLP_ENDPOINTThe Dash0 OTLP endpoint to send telemetry to
OTEL_EXPORTER_OTLP_HEADERSThe auth token and the dataset
OTEL_SERVICE_NAMEOptional: the service name, which otherwise is derived from the jar file name, the jar manifest or the Spring Boot application name; see How the service name is chosen

With the injector, set them in /etc/opentelemetry/injector/default_env.conf, which the injector applies to every process it instruments:

OTEL_EXPORTER_OTLP_ENDPOINT=https://ingress.eu-west-1.aws.dash0.com
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20auth_...,Dash0-Dataset=default

Without the injector, set them in the environment of the process, for example in the [Service] section of its systemd unit:

Environment=OTEL_EXPORTER_OTLP_ENDPOINT=https://ingress.eu-west-1.aws.dash0.com
Environment=OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20auth_...,Dash0-Dataset=default

In both setups, the declarative configuration file this package ships reads these variables, so they are the only settings most hosts need.

Note that white spaces in OTEL_EXPORTER_OTLP_HEADERS, like in Bearer <token>, must be written %20. Set the endpoint without a trailing slash, since the signal paths such as /v1/traces are appended to it.

A variable in default_env.conf replaces the value a process sets itself, so set OTEL_SERVICE_NAME and other per-application settings in the environment of the application, not in default_env.conf.

DASH0_OTEL_COLLECTOR_BASE_URL is the endpoint when OTEL_EXPORTER_OTLP_ENDPOINT is unset or empty, as in the other Dash0 distributions. A trailing slash is removed. With the shipped file and OTEL_EXPORTER_OTLP_ENDPOINT unset, every endpoint resolves to the specification default, http://localhost:4318 plus the signal path, and the distribution replaces an endpoint equal to that default with DASH0_OTEL_COLLECTOR_BASE_URL, logging the replacement at INFO. An endpoint that differs from the default in any way, including a trailing slash or another port, is kept. So a host that runs a collector beside the JVM on the default port while the base URL points elsewhere exports to the base URL; set OTEL_EXPORTER_OTLP_ENDPOINT on that workload to keep the local collector.

DASH0_DISABLE=true leaves processes uninstrumented without uninstalling the package. It beats OTEL_SDK_DISABLED, so no other setting can cancel it. The distribution trims the value and compares it case-insensitively against true, so 1, yes and on leave the distribution enabled.

With the injector, the DASH0_ variables reach the process only through dash0-injector, because upstream's opentelemetry-injector forwards only OTEL_-prefixed names.

Declarative configuration

Like the upstream Java package, this package ships /etc/opentelemetry/java/otel-config.yaml, an OpenTelemetry declarative configuration file. Unlike the upstream package, the distribution reads it whenever OTEL_CONFIG_FILE is unset or empty, so it configures every instrumented JVM by default. Configuration on the overview describes how to use a file of your own, the propagators every shipped file declares, and what happens to an edited file on upgrade, on removal and when replacing the upstream package.

The file uses OpenTelemetry declarative configuration , the standard YAML configuration format of the OpenTelemetry project, whose schema is defined in open-telemetry/opentelemetry-configuration . ${VARIABLE:-default} takes the value of an environment variable, with a default for when it is unset. This excerpt of the shipped file shows the propagators, the resource detectors and the export of traces; metrics and logs are exported in the same way:

file_format: "1.0"
propagator:
  composite:
    - tracecontext: {}
    - baggage: {}
    - xray: {}
resource:
  detection/development:
    detectors:
      - host: {}
      - process: {}
      - jar: {}
      - manifest: {}
      - spring: {}
      - service: {}
      - container: {}
  attributes_list: ${OTEL_RESOURCE_ATTRIBUTES:-}
tracer_provider:
  sampler:
    always_on: {}
  processors:
    - thread_details: {}
    - batch:
        exporter:
          otlp_http:
            endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/traces
            headers_list: ${OTEL_EXPORTER_OTLP_HEADERS:-}
            compression: ${OTEL_EXPORTER_OTLP_COMPRESSION:-none}

The shipped file keeps two things the agent does on its own without a configuration file:

  • thread.name and thread.id on every span, through the thread_details span processor the file lists. Without that entry, spans lose both attributes and nothing is logged.
  • The always_on sampler. Removing tracer_provider.sampler does not return to a sampling ratio: the distribution then writes always_on into the file, and the SDK's own fallback ignores a ratio just the same. Name the sampler you want instead.

Supported environment variables

With a configuration file in effect, the Java SDK reads no OTEL_ variable of its own. The shipped file interpolates these, so default_env.conf stays the one place to set them:

VariableDefault in the file
OTEL_EXPORTER_OTLP_ENDPOINThttp://localhost:4318
OTEL_EXPORTER_OTLP_HEADERSempty
OTEL_EXPORTER_OTLP_COMPRESSIONnone
OTEL_RESOURCE_ATTRIBUTESempty
OTEL_METRIC_EXPORT_INTERVAL60000, in milliseconds without a unit
OTEL_METRIC_EXPORT_TIMEOUT30000, in milliseconds without a unit

A configuration file of your own has to carry the same interpolations to keep them.

Write the two metric export variables as a number of milliseconds, such as 30000. Without a configuration file the SDK also accepts a unit, such as 30s, but the file substitutes the value into a field the schema types as an integer, so 30s makes the SDK reject the whole file, and the JVM exports nothing.

OTEL_SERVICE_NAME keeps working through the service detector the file lists. DASH0_OTEL_COLLECTOR_BASE_URL keeps working too, as described under Configuration.

Unsupported environment variables

  • OTEL_INSTRUMENTATION_*, and its otel.instrumentation.* system property spelling. An instrumentation turned off that way, including every one of them through OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED=false, runs anyway under the shipped file, silently. The file turns one instrumentation off with a disabled entry under distribution.javaagent.instrumentation, and turns the lot off with default_enabled: false in the same place. A per-instrumentation setting that is not an enablement switch, such as an MDC attribute selector, goes under instrumentation/development.java instead. That node takes one key per language, so the java level is what makes the setting reach the agent; without it the key is read as another language's and ignored, with nothing logged. Within it, each hyphen of the property name becomes an underscore and an experimental. segment becomes a /development suffix on the node it qualifies.
  • The distribution's otel.semconv-stability.opt-in default of database,code,rpc,messaging. A JVM running the shipped file reports the superseded attribute names for those four domains. The agent reads OTEL_SEMCONV_STABILITY_OPT_IN and -Dotel.semconv-stability.opt-in whatever the configuration source, so setting either on the workload still works. The file expresses the same choice as instrumentation/development.general.stability_opt_in_list.
  • OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER and OTEL_LOGS_EXPORTER. The file declares a provider for all three signals. Delete the tracer_provider, meter_provider or logger_provider block to stop one.
  • OTEL_EXPORTER_OTLP_PROTOCOL. The file declares otlp_http for all three signals, so a host set to grpc with an endpoint on port 4317 starts posting HTTP at a gRPC listener and loses everything. Swap the three otlp_http keys for otlp_grpc, and drop the /v1/... suffixes, which a gRPC endpoint does not take.
  • The per-signal endpoint variables, such as OTEL_EXPORTER_OTLP_TRACES_ENDPOINT. Only the base OTEL_EXPORTER_OTLP_ENDPOINT is interpolated; edit an exporter's endpoint to move one signal.
  • OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG. The file pins the sampler to always_on, so a workload sampled at a ratio starts exporting every span. Edit tracer_provider.sampler instead.
  • OTEL_PROPAGATORS. Edit the file's propagator list instead.
  • OTEL_BSP_*, OTEL_BLRP_* and OTEL_EXPORTER_OTLP_TIMEOUT. The batch processors and the exporters take the SDK's own defaults.

Resource detectors

The shipped file lists the upstream host, process, jar, manifest, spring, service and container detectors. service comes after the three that derive a service name, so that OTEL_SERVICE_NAME wins when it is set. The distribution adds each of host, process and service that a file does not name, so a file of your own loses only the others when it omits them: container.id, and the service names derived by jar, manifest and spring. Resource detection describes what each detector adds.

Unlike the Dash0 Node.js, Python and Ruby files, the Java file lists no dash0_ detectors, and a copy of it must not gain one. A detector name the SDK does not know stops the agent from starting, as described under Conditional instrumentation.

Resource attributes

Every instrumented process reports the package it came from:

AttributeValue
dash0.package.namedash0-java-autoinstrumentation
dash0.package.versionThe installed package version, packaging revision included

The dash0.package.* attributes come from a file this package installs next to the jar, with or without a configuration file. A value in OTEL_RESOURCE_ATTRIBUTES overrides them.

The distribution adds the other resource attributes, such as service.name and telemetry.distro.*. Resource detection in the distribution docs describes them, and how the service name is chosen, with and without a configuration file.

Conditional instrumentation

The JVM keeps running in every case below, without telemetry. The agent writes its messages to stderr.

  • DASH0_DISABLE=true: the agent logs one line at INFO.
  • OTEL_SDK_DISABLED=true: the distribution does not load the shipped file, and the SDK is disabled. When OTEL_CONFIG_FILE names a file, it has no effect; use DASH0_DISABLE.
  • OTEL_JAVAAGENT_ENABLED=false: the agent does not attach at all.
  • A Java version below the minimum, or one the injector cannot determine: the injector skips the JVM. The injector checks the Java version of every JVM against jvm_auto_instrumentation_minimum_java_major_version, whose default is 8, and skips a JVM whose version it cannot determine, such as one started through jsvc or embedded in a native launcher. To turn the check off, set the value to 0 in a later-sorting conf.d file, as described under Installed files.
  • The agent is already attached: the injector skips a JVM whose JAVA_TOOL_OPTIONS already loads the same agent jar. Another Java agent, or an OpenTelemetry SDK bundled in the application, is not detected.
  • A configuration file the SDK cannot build: the agent logs OpenTelemetry Javaagent failed to start with a stack trace, and the JVM runs uninstrumented and exits zero, so it looks healthy to anything watching it. This happens with a file that is not valid, with a detector name the SDK does not know, such as a dash0_ one, and with OTEL_METRIC_EXPORT_INTERVAL or OTEL_METRIC_EXPORT_TIMEOUT set with a unit, as described under Supported environment variables.

With the injector, the injector itself logs why it skipped a process on stderr with OTEL_INJECTOR_LOG_LEVEL=info. See the Injector page.

The agent logs Configuration file_format '1.0' does not exactly match expected version '1.2' for the shipped file. That warning is expected and changes nothing; the file upstream's own Java package ships declares 1.0 as well.

Installed files

PathPurpose
/usr/lib/opentelemetry/java/opentelemetry-javaagent.jarThe agent, loaded with -javaagent:
/usr/lib/opentelemetry/java/dash0-resource-attributes.propertiesThe dash0.package.* resource attributes, replaced on upgrade
/etc/opentelemetry/injector/conf.d/java.confTells the injector where the agent jar is
/etc/opentelemetry/java/otel-config.yamlThe declarative configuration file, read whenever OTEL_CONFIG_FILE is unset or empty; a conffile, so an edited copy is kept on upgrade
/usr/share/man/man8/opentelemetry-java.8.gzThe manual page, for man opentelemetry-java
/usr/share/doc/dash0-java-autoinstrumentation/README.mdThe installed copy of this page
/usr/share/doc/dash0-java-autoinstrumentation/copyrightThe license statement and the notice, DEB only
/usr/share/licenses/dash0-java-autoinstrumentation/LICENSEThe license, RPM only
/usr/share/licenses/dash0-java-autoinstrumentation/NOTICEThe notice, RPM only

Local overrides belong in a conf.d file that sorts after the package-managed one. The injector reads conf.d in byte order and the last setting wins, so a digit prefix such as 99- sorts before java.conf; use a name such as zz-local-java.conf. Edits to java.conf itself are replaced on upgrade.

Dependencies

PackageRelationWhy
dash0-keyringDependsEvery Dash0 package depends on it, so the signing certificate is owned by a package that upgrades it
dash0-injectorSuggestsInstruments processes with this package; apt and dnf do not install suggested packages, so install the injector by name, as described under Setup with the injector
opentelemetry-java-autoinstrumentationConflicts, and Replaces on DEB or Obsoletes on RPMTakes the place of the upstream package; see Reverting to the upstream package

Versioning

The package version is the version of the bundled distribution, followed by a packaging revision: 0.3.0-1 is the first package built from distribution 0.3.0, 0.3.0-2 a later package built from the same distribution. On RPM distributions the revision is the Release field, so rpm -q shows 0.3.0-1 as version 0.3.0, release 1.

Reverting to the upstream package

On Debian and Ubuntu:

sudo apt-get install opentelemetry-java-autoinstrumentation

On RPM distributions, this package declares Obsoletes on the upstream name, so a plain dnf install of it redirects back here. Ask for the swap explicitly:

sudo dnf swap --setopt=obsoletes=0 dash0-java-autoinstrumentation opentelemetry-java-autoinstrumentation

The upstream agent reads no configuration file by default, so after the switch every JVM is configured from the environment until something sets OTEL_CONFIG_FILE, and a host that kept the Dash0 file at the path keeps a file nothing reads. That loses the always_on sampler and the xray propagator, which are Dash0 defaults. The jar, manifest, spring and container detectors and the thread_details span processor come back on their own, because the upstream agent loads them without a configuration file. Once OTEL_CONFIG_FILE does name a file, the upstream agent reads it as written, and nothing fills in what the file leaves out, such as an endpoint, the propagators or the host, process and service detectors.

Source

https://github.com/dash0hq/opentelemetry-java-distribution 

Last updated: