Java
The Dash0 distribution of the OpenTelemetry Java agent, packaged so the OpenTelemetry injector can load it into JVM processes on a host.
Compatibility
| Requirement | Supported |
|---|---|
| Java | 8 or later |
| Architectures | Any |
| Distribution requirements | Supported 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-opentelemetryOn Fedora, RHEL or Amazon Linux 2023:
sudo dnf install dash0-opentelemetryWith 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-autoinstrumentationOn Fedora, RHEL or Amazon Linux 2023:
sudo dnf install dash0-injector dash0-java-autoinstrumentationIn 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-autoinstrumentationOn Fedora, RHEL or Amazon Linux 2023:
sudo dnf install dash0-java-autoinstrumentationOn 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.jarWithout 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:
| Variable | Sets |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | The Dash0 OTLP endpoint to send telemetry to |
OTEL_EXPORTER_OTLP_HEADERS | The auth token and the dataset |
OTEL_SERVICE_NAME | Optional: 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=defaultWithout 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=defaultIn 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.nameandthread.idon every span, through thethread_detailsspan processor the file lists. Without that entry, spans lose both attributes and nothing is logged.- The
always_onsampler. Removingtracer_provider.samplerdoes not return to a sampling ratio: the distribution then writesalways_oninto 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:
| Variable | Default in the file |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | http://localhost:4318 |
OTEL_EXPORTER_OTLP_HEADERS | empty |
OTEL_EXPORTER_OTLP_COMPRESSION | none |
OTEL_RESOURCE_ATTRIBUTES | empty |
OTEL_METRIC_EXPORT_INTERVAL | 60000, in milliseconds without a unit |
OTEL_METRIC_EXPORT_TIMEOUT | 30000, 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 itsotel.instrumentation.*system property spelling. An instrumentation turned off that way, including every one of them throughOTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED=false, runs anyway under the shipped file, silently. The file turns one instrumentation off with adisabledentry underdistribution.javaagent.instrumentation, and turns the lot off withdefault_enabled: falsein the same place. A per-instrumentation setting that is not an enablement switch, such as an MDC attribute selector, goes underinstrumentation/development.javainstead. That node takes one key per language, so thejavalevel 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 anexperimental.segment becomes a/developmentsuffix on the node it qualifies.- The distribution's
otel.semconv-stability.opt-indefault ofdatabase,code,rpc,messaging. A JVM running the shipped file reports the superseded attribute names for those four domains. The agent readsOTEL_SEMCONV_STABILITY_OPT_INand-Dotel.semconv-stability.opt-inwhatever the configuration source, so setting either on the workload still works. The file expresses the same choice asinstrumentation/development.general.stability_opt_in_list. OTEL_TRACES_EXPORTER,OTEL_METRICS_EXPORTERandOTEL_LOGS_EXPORTER. The file declares a provider for all three signals. Delete thetracer_provider,meter_providerorlogger_providerblock to stop one.OTEL_EXPORTER_OTLP_PROTOCOL. The file declaresotlp_httpfor all three signals, so a host set togrpcwith an endpoint on port 4317 starts posting HTTP at a gRPC listener and loses everything. Swap the threeotlp_httpkeys forotlp_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 baseOTEL_EXPORTER_OTLP_ENDPOINTis interpolated; edit an exporter'sendpointto move one signal. OTEL_TRACES_SAMPLERandOTEL_TRACES_SAMPLER_ARG. The file pins the sampler toalways_on, so a workload sampled at a ratio starts exporting every span. Edittracer_provider.samplerinstead.OTEL_PROPAGATORS. Edit the file'spropagatorlist instead.OTEL_BSP_*,OTEL_BLRP_*andOTEL_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:
| Attribute | Value |
|---|---|
dash0.package.name | dash0-java-autoinstrumentation |
dash0.package.version | The 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 atINFO.OTEL_SDK_DISABLED=true: the distribution does not load the shipped file, and the SDK is disabled. WhenOTEL_CONFIG_FILEnames a file, it has no effect; useDASH0_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 throughjsvcor embedded in a native launcher. To turn the check off, set the value to0in a later-sortingconf.dfile, as described under Installed files. - The agent is already attached: the injector skips a JVM whose
JAVA_TOOL_OPTIONSalready 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 startwith 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 adash0_one, and withOTEL_METRIC_EXPORT_INTERVALorOTEL_METRIC_EXPORT_TIMEOUTset 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
| Path | Purpose |
|---|---|
/usr/lib/opentelemetry/java/opentelemetry-javaagent.jar | The agent, loaded with -javaagent: |
/usr/lib/opentelemetry/java/dash0-resource-attributes.properties | The dash0.package.* resource attributes, replaced on upgrade |
/etc/opentelemetry/injector/conf.d/java.conf | Tells the injector where the agent jar is |
/etc/opentelemetry/java/otel-config.yaml | The 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.gz | The manual page, for man opentelemetry-java |
/usr/share/doc/dash0-java-autoinstrumentation/README.md | The installed copy of this page |
/usr/share/doc/dash0-java-autoinstrumentation/copyright | The license statement and the notice, DEB only |
/usr/share/licenses/dash0-java-autoinstrumentation/LICENSE | The license, RPM only |
/usr/share/licenses/dash0-java-autoinstrumentation/NOTICE | The 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
| Package | Relation | Why |
|---|---|---|
dash0-keyring | Depends | Every Dash0 package depends on it, so the signing certificate is owned by a package that upgrades it |
dash0-injector | Suggests | Instruments 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-autoinstrumentation | Conflicts, and Replaces on DEB or Obsoletes on RPM | Takes 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-autoinstrumentationOn 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-autoinstrumentationThe 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
Last updated: