trino icon indicating copy to clipboard operation
trino copied to clipboard

[Trino JDBC] NoClassDefFoundError io/opentelemetry/semconv/SemanticAttributes

Open gaeljw opened this issue 10 months ago • 1 comments

Preamble

I'm logging this as an issue to help other people facing it to find the explanation and solution but I believe the root cause is close to the one described in https://github.com/trinodb/trino/issues/21104.

Issue

Getting java.lang.NoClassDefFoundError: io/opentelemetry/semconv/SemanticAttributes when:

  • using trino-jdbc 445
  • having io.opentelemetry:opentelemetry-api (and optionally others OTEL dependencies) as a dependency in the classpath
  • BUT NOT having io.opentelemetry.semconv:opentelemetry-semconv as a dependency in the classpath

This is a regular setup when using the OpenTelemetry java agent: the classpath only contains the opentelemetry-api but all the SDK is in a separate classpath for the java agent.

Complete stacktrace:

[error] Caused by: java.lang.NoClassDefFoundError: io/opentelemetry/semconv/SemanticAttributes
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.api.semconv.http.HttpCommonAttributesExtractor.onStart(HttpCommonAttributesExtractor.java:61)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor.onStart(HttpClientAttributesExtractor.java:71)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.api.instrumenter.Instrumenter.doStart(Instrumenter.java:179)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.api.instrumenter.Instrumenter.startAndEnd(Instrumenter.java:158)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.api.instrumenter.Instrumenter$1.startAndEnd(Instrumenter.java:272)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.api.internal.InstrumenterUtil.startAndEnd(InstrumenterUtil.java:44)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.okhttp.v3_0.internal.ConnectionErrorSpanInterceptor.intercept(ConnectionErrorSpanInterceptor.java:47)
[error]     at io.trino.jdbc.$internal.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.okhttp.v3_0.ContextInterceptor.intercept(ContextInterceptor.java:28)
[error]     at io.trino.jdbc.$internal.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[error]     at io.trino.jdbc.$internal.okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
[error]     at io.trino.jdbc.$internal.okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
[error]     at io.trino.jdbc.$internal.opentelemetry.instrumentation.okhttp.v3_0.TracingCallFactory$TracingCall.execute(TracingCallFactory.java:100)
[error]     at io.trino.jdbc.$internal.client.JsonResponse.execute(JsonResponse.java:113)
[error]     at io.trino.jdbc.$internal.client.StatementClientV1.executeRequest(StatementClientV1.java:401)
[error]     at io.trino.jdbc.$internal.client.StatementClientV1.(StatementClientV1.java:132)
[error]     at io.trino.jdbc.$internal.client.StatementClientFactory.newStatementClient(StatementClientFactory.java:28)
[error]     at io.trino.jdbc.TrinoConnection.startQuery(TrinoConnection.java:771)
[error]     at io.trino.jdbc.TrinoStatement.internalExecute(TrinoStatement.java:252)
[error]     at io.trino.jdbc.TrinoStatement.execute(TrinoStatement.java:240)

Fix

Force to have a (recent) io.opentelemetry.semconv:opentelemetry-semconv dependency in the classpath.

gaeljw avatar Apr 24 '24 13:04 gaeljw

I reopen because it's actually a different issue than #21104: having trino-jdbc + opentelemetry-api in the classpath and using the opentelemetry java agent leads to this issue. It's not only a dependency version conflict. It's a missing needed dependency (not pulled via Maven POM declarations).

gaeljw avatar Apr 25 '24 07:04 gaeljw

Hitting the same issue

kaushik-revefi avatar Aug 13 '24 09:08 kaushik-revefi

I'm running into this as well. It appears to me that shading isn't done properly for various opentelemetry dependencies?

                <relocation>
                  <pattern>io.opentelemetry.extension</pattern>
                  <shadedPattern>${shadeBase}.opentelemetry.extension</shadedPattern>
                </relocation>
                <relocation>
                  <pattern>io.opentelemetry.instrumentation</pattern>
                  <shadedPattern>${shadeBase}.opentelemetry.instrumentation</shadedPattern>
                </relocation>
                <relocation>
                  <pattern>io.opentelemetry.api.incubator</pattern>
                  <shadedPattern>${shadeBase}.opentelemetry.api.incubator</shadedPattern>
                </relocation>

lukaseder avatar Aug 15 '24 11:08 lukaseder

OTEL shouldn't be shaded at all. I'll merge soon a change that excludes OTEL entirely so it will be provided only externally.

wendigo avatar Sep 17 '24 11:09 wendigo