open-telemetry / open-telemetry/opentelemetry-java-instrumentation
Application startup failure with disableShadowRelocate=true
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1.2k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 214
Description
Describe the bug
I disabled the shadow renaming for local builds by adding disableShadowRelocate=true to ~/.gradle/gradle.properties before building. It introduced by https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/debugging.md#shadow-renaming
My application got following startup failure:
[otel.javaagent 2025-09-19 16:03:40:665 +0800] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.21.0-SNAPSHOT
OpenTelemetry Javaagent failed to start
java.lang.NullPointerException: Cannot invoke "io.opentelemetry.api.OpenTelemetry.meterBuilder(String)" because "openTelemetry" is null
at io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsUtil.getMeter(JmxRuntimeMetricsUtil.java:28)
at io.opentelemetry.instrumentation.runtimemetrics.java8.Classes.registerObservers(Classes.java:48)
at io.opentelemetry.instrumentation.runtimemetrics.java8.Classes.registerObservers(Classes.java:43)
at io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsFactory.buildObservables(JmxRuntimeMetricsFactory.java:27)
at io.opentelemetry.instrumentation.runtimemetrics.java17.RuntimeMetricsBuilder.build(RuntimeMetricsBuilder.java:97)
at io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RuntimeMetricsConfigUtil.configure(RuntimeMetricsConfigUtil.java:50)
at io.opentelemetry.instrumentation.javaagent.runtimemetrics.java17.Java17RuntimeMetricsInstaller.afterAgent(Java17RuntimeMetricsInstaller.java:23)
at io.opentelemetry.javaagent.tooling.AgentInstaller.runAfterAgentListeners(AgentInstaller.java:363)
at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:225)
at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:112)
at io.opentelemetry.javaagent.tooling.AgentStarterImpl.start(AgentStarterImpl.java:104)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer$2.run(AgentInitializer.java:66)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer$2.run(AgentInitializer.java:60)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer.execute(AgentInitializer.java:82)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer.initialize(AgentInitializer.java:59)
at io.opentelemetry.javaagent.OpenTelemetryAgent.startAgent(OpenTelemetryAgent.java:59)
at io.opentelemetry.javaagent.OpenTelemetryAgent.premain(OpenTelemetryAgent.java:46)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:560)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:572)
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class io.opentelemetry.context.LazyStorage
at io.opentelemetry.context.ContextStorage.get(ContextStorage.java:72)
at io.opentelemetry.context.Context.current(Context.java:92)
at io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext(Java8BytecodeBridge.java:23)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:255)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.log(Logger.java:765)
at org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog.error(LogAdapter.java:433)
at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:826)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:801)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.example.demo.CPDemoApplication.main(CPDemoApplication.java:110)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NullPointerException [in thread "main"]
at io.opentelemetry.context.Context.root(Context.java:105)
at io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage.getWrappedRootContext(AgentContextStorage.java:82)
at io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage.<init>(AgentContextStorage.java:51)
at io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage.lambda$wrap$0(AgentContextStorage.java:113)
at io.opentelemetry.context.LazyStorage.<clinit>(LazyStorage.java:86)
at io.opentelemetry.context.ContextStorage.get(ContextStorage.java:72)
at io.opentelemetry.context.Context.current(Context.java:92)
at io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext(Java8BytecodeBridge.java:23)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:255)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.log(Logger.java:765)
at org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog.info(LogAdapter.java:454)
at org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:55)
at org.springframework.boot.SpringApplication.logStartupInfo(SpringApplication.java:637)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:373)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
... 3 more
Steps to reproduce
Disable the shadow renaming for local builds by adding disableShadowRelocate=true to ~/.gradle/gradle.properties. Start an application by corresponding java agent.
Expected behavior
Application can start up normally
Actual behavior
Application can't start up normally
Javaagent or library instrumentation version
2.21.0-SNAPSHOT
Environment
JDK:
OS:
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with docs/contributing/debugging.md and reproduce the failure using disableShadowRelocate=true with the Java agent. Trace the startup path through AgentInstaller.runAfterAgentListeners and Java17RuntimeMetricsInstaller.afterAgent, then inspect JmxRuntimeMetricsUtil.getMeter and the reported Context initialization errors. Done means the application starts normally with shadow relocation disabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- observability-sre, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100