opentelemetry-java-instrumentation icon indicating copy to clipboard operation
opentelemetry-java-instrumentation copied to clipboard

JDK 25 Support?

Open grcevski opened this issue 9 months ago • 2 comments

Describe the bug

Running the javaagent with SpringBoot 3 application on JDK 25 causes an error on start. I'm wondering if this is a known issue, looks like ByteBuddy related, or am I doing something wrong?

Here's the output I get when I try loading the agent:

/jdk-25/bin/java -javaagent:./opentelemetry-javaagent.jar -jar target/greeting-service-1.0.0-SNAPSHOT.jar
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[otel.javaagent 2025-02-21 15:50:29:541 -0500] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.13.1
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction (file:/javatestserver/opentelemetry-javaagent.jar)
WARNING: Please consider reporting this to the maintainers of class net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.1)

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:95)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.NoSuchFieldError: Class ch.qos.logback.classic.spi.LoggingEvent does not have member field 'java.lang.Object __opentelemetryVirtualField$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context'
	at ch.qos.logback.classic.spi.LoggingEvent.__set__opentelemetryVirtualField$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context(LoggingEvent.java)
	at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context.realPut(VirtualFieldImplementationsGenerator.java)
	at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context.set(VirtualFieldImplementationsGenerator.java:285)
	at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
	at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:386)
	at ch.qos.logback.classic.Logger.log(Logger.java:780)
	at org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog.error(LogAdapter.java:431)
	at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:855)
	at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:819)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:347)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1358)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1347)
	at de.fstab.demo.greeting.Application.main(Application.java:14)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	... 5 more

/jdk-25/bin/java -version
openjdk version "25-ea" 2025-09-16
OpenJDK Runtime Environment (build 25-ea+11-1205)
OpenJDK 64-Bit Server VM (build 25-ea+11-1205, mixed mode, sharing)

Steps to reproduce

  1. Build any simple SpringBoot 3.x application, e.g. using the SpringBoot starter.
  2. Run OpenJDK 25 with the java instrumentation by loading the agent on the command line: /jdk-25/bin/java -javaagent:./opentelemetry-javaagent.jar -jar target/my-service-1.0.0-SNAPSHOT.jar

Expected behavior

The SpringBoot application should start and it should be instrumented.

Actual behavior

The SpringBoot application fails to start

Javaagent or library instrumentation version

v2.13.1

Environment

JDK: OpenJDK 25 openjdk version "25-ea" 2025-09-16 OpenJDK Runtime Environment (build 25-ea+11-1205) OpenJDK 64-Bit Server VM (build 25-ea+11-1205, mixed mode, sharing) OS: Linux x86-64 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Additional context

No response

grcevski avatar Feb 21 '25 21:02 grcevski

well, let's start with 24-ea šŸ˜„ #13376

trask avatar Feb 22 '25 03:02 trask

well, let's start with 24-ea šŸ˜„ #13376

Thanks for the quick response @trask! I tested locally with the 24-rc1 and it works well, at least in my limited tests that I did for HTTP+Postgresql.

This is the 24 version I tried:

openjdk version "24" 2025-03-18
OpenJDK Runtime Environment (build 24+36-3646)
OpenJDK 64-Bit Server VM (build 24+36-3646, mixed mode, sharing)

I see the same message:

WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release

so I think it's maybe something else, or perhaps a JVM bug. I'll dig more into this.

grcevski avatar Feb 22 '25 15:02 grcevski

WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release

@grcevski It's not a JVM bug. JEP 498 is in preview mode in Java 24, and the warning arises because some dependencies are using Unsafe methods. You can explicitly hide this warning using the option --sun-misc-unsafe-memory-access={allow|warn|debug|deny}.

sureshg avatar Apr 04 '25 01:04 sureshg

We see the same warning on Amazon Corretto 25, when the OTEL Java agent (v2.20.0) is run:

WARNING: sun.misc.Unsafe::objectFieldOffset has been called by net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction (file:/path/to/otel/agent.jar)

I think this may be relevant: https://github.com/raphw/byte-buddy/issues/1803, and in particular, this comment.

jpalomaki avatar Sep 22 '25 08:09 jpalomaki

Is JDK 25 officially supported in the OTel Java agent? I am still getting the same error reported in the first post.

Exception in thread "main" java.lang.NoSuchFieldError: Class ch.qos.logback.classic.spi.LoggingEvent does not have member field 'java.lang.Object __opentelemetryVirtualField$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context'
        at ch.qos.logback.classic.spi.LoggingEvent.__set__opentelemetryVirtualField$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context(LoggingEvent.java)
        at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context.realPut(VirtualFieldImplementationsGenerator.java)
        at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context.set(VirtualFieldImplementationsGenerator.java:285)
        at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
        at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
        at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:386)

@jpalomaki apart from that warning, could you able to run the agent on JDK 25?

sureshg avatar Oct 09 '25 16:10 sureshg

Is JDK 25 officially supported in the OTel Java agent? I am still getting the same error reported in the first post.

Exception in thread "main" java.lang.NoSuchFieldError: Class ch.qos.logback.classic.spi.LoggingEvent does not have member field 'java.lang.Object __opentelemetryVirtualField$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context'
        at ch.qos.logback.classic.spi.LoggingEvent.__set__opentelemetryVirtualField$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context(LoggingEvent.java)
        at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context.realPut(VirtualFieldImplementationsGenerator.java)
        at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$ch$qos$logback$classic$spi$ILoggingEvent$io$opentelemetry$javaagent$shaded$io$opentelemetry$context$Context.set(VirtualFieldImplementationsGenerator.java:285)
        at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
        at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
        at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:386)

@jpalomaki apart from that warning, could you able to run the agent on JDK 25?

Yes, we are able to run the agent, only a warning is emitted.

jpalomaki avatar Oct 09 '25 18:10 jpalomaki

Is the exception with NoSuchFieldError __opentelemetryVirtualField fixed in latest version of OTEL Java Instrumentation? We are also seeing this with older version of OTEL Java Instrumentation and Java 25, so will the update fix the issue for us?

oldium avatar Oct 13 '25 14:10 oldium

hi @oldium! we are now running all of our tests against Java 25, so it will be officially supported in the upcoming release (scheduled for later this week). If you still see an issue in that release, please open a new issue with a repro that we can use to troubleshoot what you're seeing. thanks!

trask avatar Oct 13 '25 15:10 trask

Is the exception with NoSuchFieldError __opentelemetryVirtualField fixed in latest version of OTEL Java Instrumentation? We are also seeing this with older version of OTEL Java Instrumentation and Java 25, so will the update fix the issue for us?

Please try it out. If the issue persists create a new issue and include a minimal sample application that reproduce the issue.

laurit avatar Oct 13 '25 16:10 laurit

It seems working. Thanks everyone.

oldium avatar Oct 13 '25 17:10 oldium

it will be officially supported in the upcoming release

@trask so officially supported in in 2.21.0? It might be worth mentioning it in the release notes šŸ˜‰ BTW, is there some kind of tracking matrix between instrumentation version and supported JVM version?

(as a side note, I’m also looking for an upgrade guide from 1.x)

DidierLoiseau avatar Nov 04 '25 17:11 DidierLoiseau