Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentelemetry-maven-extension] NoClassDefFoundError while running package #1391

Open
vicziani opened this issue Jul 23, 2024 · 3 comments
Open

Comments

@vicziani
Copy link

Component(s)

maven-extension

What happened?

Description

Maven throws a NoClassDefFoundError while running package. No trace in Zipkin.

[WARNING] Problem stopping: public synchronized void io.opentelemetry.maven.OpenTelemetrySdkService.close()
java.lang.NoClassDefFoundError: io/opentelemetry/sdk/common/CompletableResultCode           

Windows 11, Java version "21.0.1" 2023-10-17 LTS, Maven 3.9.8, extension 1.37.0-alpha.

Same in1.36.0-alpha.

It works with 1.35.0-alpha (it sends an exception, but there is a trace in Zipkin).

Exception in thread "OkHttp TaskRunner" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Ref$IntRef
	at okhttp3.internal.http2.Http2Connection.shutdown(Http2Connection.kt:419)
	at okhttp3.internal.http2.Http2Connection.close$okhttp(Http2Connection.kt:449)
	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:627)
	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:609)
	at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce(TaskQueue.kt:98)
	at okhttp3.internal.concurrent.TaskRunner.runTask(TaskRunner.kt:116)
	at okhttp3.internal.concurrent.TaskRunner.access$runTask(TaskRunner.kt:42)
	at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:65)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Ref$IntRef
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:225)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:210)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:205)
	... 11 more

Steps to Reproduce

Use an empty project with only a pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>training</groupId>
	<artifactId>helloworld</artifactId>
	<version>1.0.0</version>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>21</maven.compiler.source>
		<maven.compiler.target>21</maven.compiler.target>
	</properties>

  <build>

    <extensions>
      <extension>
        <groupId>io.opentelemetry.contrib</groupId>
        <artifactId>opentelemetry-maven-extension</artifactId>
        <version>1.37.0-alpha</version>
      </extension>
    </extensions>


  </build>

</project>

Expected Result

Succesfull build without exception, and trace in Zipkin.

Actual Result

Exception, no trace in Zipkin.

Component version

1.37.0-alpha

Log output

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< training:helloworld >-------------------------
[INFO] Building helloworld 1.0.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ helloworld ---
[INFO] skip non existing resourceDirectory C:\iviczian\Downloads\mvn\helloworld\src\main\resources
[INFO] 
[INFO] --- compiler:3.13.0:compile (default-compile) @ helloworld ---
[INFO] No sources to compile
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ helloworld ---
[INFO] skip non existing resourceDirectory C:\iviczian\Downloads\mvn\helloworld\src\test\resources
[INFO] 
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ helloworld ---
[INFO] No sources to compile
[INFO] 
[INFO] --- surefire:3.2.5:test (default-test) @ helloworld ---
[INFO] No tests to run.
[INFO] 
[INFO] --- jar:3.4.1:jar (default-jar) @ helloworld ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\iviczian\Downloads\mvn\helloworld\target\helloworld-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.789 s
[INFO] Finished at: 2024-07-23T12:57:45+02:00
[INFO] ------------------------------------------------------------------------
[WARNING] Problem stopping: public synchronized void io.opentelemetry.maven.OpenTelemetrySdkService.close()
java.lang.NoClassDefFoundError: io/opentelemetry/sdk/common/CompletableResultCode
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.shutdown (BatchSpanProcessor.java:301)
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.access$200 (BatchSpanProcessor.java:162)
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor.shutdown (BatchSpanProcessor.java:117)
    at io.opentelemetry.sdk.trace.TracerSharedState.shutdown (TracerSharedState.java:104)
    at io.opentelemetry.sdk.trace.SdkTracerProvider.shutdown (SdkTracerProvider.java:123)
    at io.opentelemetry.sdk.OpenTelemetrySdk.shutdown (OpenTelemetrySdk.java:111)
    at io.opentelemetry.maven.OpenTelemetrySdkService.close (OpenTelemetrySdkService.java:84)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.eclipse.sisu.bean.BeanLifecycle.stop (BeanLifecycle.java:133)
    at org.eclipse.sisu.bean.LifecycleManager.unmanage (LifecycleManager.java:85)
    at org.eclipse.sisu.plexus.PlexusLifecycleManager.unmanage (PlexusLifecycleManager.java:177)
    at org.codehaus.plexus.DefaultPlexusContainer.dispose (DefaultPlexusContainer.java:592)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:296)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: java.lang.ClassNotFoundException: io.opentelemetry.sdk.common.CompletableResultCode
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:225)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:210)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:205)
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.shutdown (BatchSpanProcessor.java:301)
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.access$200 (BatchSpanProcessor.java:162)
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor.shutdown (BatchSpanProcessor.java:117)
    at io.opentelemetry.sdk.trace.TracerSharedState.shutdown (TracerSharedState.java:104)
    at io.opentelemetry.sdk.trace.SdkTracerProvider.shutdown (SdkTracerProvider.java:123)
    at io.opentelemetry.sdk.OpenTelemetrySdk.shutdown (OpenTelemetrySdk.java:111)
    at io.opentelemetry.maven.OpenTelemetrySdkService.close (OpenTelemetrySdkService.java:84)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.eclipse.sisu.bean.BeanLifecycle.stop (BeanLifecycle.java:133)
    at org.eclipse.sisu.bean.LifecycleManager.unmanage (LifecycleManager.java:85)
    at org.eclipse.sisu.plexus.PlexusLifecycleManager.unmanage (PlexusLifecycleManager.java:177)
    at org.codehaus.plexus.DefaultPlexusContainer.dispose (DefaultPlexusContainer.java:592)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:296)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)

Additional context

docker-compose.yaml

services:
  zipkin:
    image: openzipkin/zipkin:3.4.0
    ports:
      - "9411:9411"
  collector:
    image: otel/opentelemetry-collector-contrib:0.105.0
    volumes:
      - ./collector-config.yaml:/etc/otelcol-contrib/config.yaml
    ports:
      - "4317:4317"
      - "4318:4318"
    depends_on:
      - zipkin

collector-config.yaml

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

exporters:
  zipkin:
    endpoint: "http://zipkin:9411/api/v2/spans"

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [zipkin]
@cyrille-leclerc
Copy link
Member

cyrille-leclerc commented Aug 13, 2024

Sorry for the regression.
Problem reproduced with Maven 3.9.8 and https://github.com/cyrille-leclerc/my-war/tree/364ed7c5fc295ea63b85f7fc6c26cba36a20f5a8

@vicziani A workaround is to declare the Maven OpenTelemetry Extension through .mvn/extensions.xml rather than through the pom.xml.

.mvn/extensions.xml would look like

<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
    <extension>
        <groupId>io.opentelemetry.contrib</groupId>
        <artifactId>opentelemetry-maven-extension</artifactId>
        <version>1.37.0-alpha</version>
  </extension>
</extensions>

The cause may be the adoption of JSR 330 in replacement to the deprecated Nexus DI mechanisms:

Environment to reproduce:

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /opt/homebrew/Cellar/maven/3.9.8/libexec
Java version: 22.0.2, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/22.0.2/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"

@cyrille-leclerc
Copy link
Member

@hboutemy FYI I created MNG-8217 - ClassNotFoundException in @PreDestroy method when Maven extension declared in pom.xml.
Herve, I'll workaround using another event of the Maven lifecycle to teardown the OTel SDK but it would be great to fix this hard to identify bug.

@cyrille-leclerc
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants