Skip to content

Also catch ClassNotFoundException when trying to instantiate datadog.opentracing.jfr.openjdk.ScopeEventFactory.#1345

Closed
alacoste wants to merge 1 commit into
DataDog:masterfrom
alacoste:patch-1
Closed

Also catch ClassNotFoundException when trying to instantiate datadog.opentracing.jfr.openjdk.ScopeEventFactory.#1345
alacoste wants to merge 1 commit into
DataDog:masterfrom
alacoste:patch-1

Conversation

@alacoste
Copy link
Copy Markdown

I am getting an uncaught exception that seems to have been forgotten in the anticipated catch block:

java.lang.ClassNotFoundException: datadog.opentracing.jfr.openjdk.ScopeEventFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:340)
	at datadog.opentracing.DDTracer.createScopeEventFactory(DDTracer.java:560)
	at datadog.opentracing.DDTracer.access$000(DDTracer.java:55)
	at datadog.opentracing.DDTracer$DDTracerBuilder.config(DDTracer.java:121)
	at datadog.opentracing.DDTracer$DDTracerBuilder.withProperties(DDTracer.java:110)
	at ace.client.external.tracing.TracingClient$Companion.test(TracingClient.kt:71)
	at ace.ApplicationKt$main$4.invokeSuspend(Application.kt:210)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:271)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at ace.ApplicationKt.main(Application.kt:209)
	at ace.ApplicationKt.main(Application.kt)

…opentracing.jfr.openjdk.ScopeEventFactory.

I am getting an uncaught exception that seems to have been forgotten in the anticipated catch block:

```
java.lang.ClassNotFoundException: datadog.opentracing.jfr.openjdk.ScopeEventFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:340)
	at datadog.opentracing.DDTracer.createScopeEventFactory(DDTracer.java:560)
	at datadog.opentracing.DDTracer.access$000(DDTracer.java:55)
	at datadog.opentracing.DDTracer$DDTracerBuilder.config(DDTracer.java:121)
	at datadog.opentracing.DDTracer$DDTracerBuilder.withProperties(DDTracer.java:110)
	at ace.client.external.tracing.TracingClient$Companion.test(TracingClient.kt:71)
	at ace.ApplicationKt$main$4.invokeSuspend(Application.kt:210)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:271)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at ace.ApplicationKt.main(Application.kt:209)
	at ace.ApplicationKt.main(Application.kt)
```
@alacoste alacoste requested a review from a team as a code owner March 31, 2020 13:14
@mar-kolya
Copy link
Copy Markdown
Contributor

Hi @alacoste, thanks for PR.

Could you please clarify what kind of setup you have? Ideally would you be able to provide a simple reproducer that triggers the problem?

@alacoste
Copy link
Copy Markdown
Author

Hi @alacoste, thanks for PR.

Could you please clarify what kind of setup you have? Ideally would you be able to provide a simple reproducer that triggers the problem?

Hi @mar-kolya, I'll try to make a small & simple reproducer, but here's our setup in the big lines:

  • Kotlin project using gradle
  • I was trying to use only the opentracing APIs and setup the DDTracer entirely from code (no java-agent, no config file).

build.gradle.kts:

implementation("com.datadoghq:dd-trace-ot:0.47.0")
implementation("io.opentracing:opentracing-api:0.33.0")

Sample code to construct the DDTracer:

val properties = Properties()
properties.setProperty("trace.enabled", "true")
properties.setProperty("service.name", "backend")
properties.setProperty("trace.agent.unix.domain.socket", "/.../my_socket")
val tracer: Tracer = DDTracer.builder()
    .withProperties(properties)
    .defaultSpanTags(mapOf("env" to "myEnv"))
    .build()

@mar-kolya
Copy link
Copy Markdown
Contributor

@alacoste, thanks for the explanation for your setup.
This is indeed a bug and your suggested fix seems to be the right direction. Unfortunately it doesn't build - I'll create a separate PR to address this bug. Thank!

@alacoste
Copy link
Copy Markdown
Author

@alacoste, thanks for the explanation for your setup.
This is indeed a bug and your suggested fix seems to be the right direction. Unfortunately it doesn't build - I'll create a separate PR to address this bug. Thank!

I'm guessing it's a missing import for ClassNotFoundException, I went a bit quickly doing it from the github UI directly.

Thanks for taking care of it

@mar-kolya
Copy link
Copy Markdown
Contributor

@alacoste I've looked into this in a but more detail and it looks like ClassNotFoundException inherits from ReflectiveOperationException which is being caught and handled.

Could you please clarify: you see your app crash because of this - not just log an exception?
If it is crashing I guess we would need a reproducer because so far it is unclear.

@alacoste
Copy link
Copy Markdown
Author

alacoste commented Apr 3, 2020

@alacoste I've looked into this in a but more detail and it looks like ClassNotFoundException inherits from ReflectiveOperationException which is being caught and handled.

Could you please clarify: you see your app crash because of this - not just log an exception?
If it is crashing I guess we would need a reproducer because so far it is unclear.

Tracing was working, but it would log an exception with stacktrace which seems like too much for the "problem" here (if this is an expected behavior in some cases).

I'm not sure whether the exception is caught at some higher level by my application code, or if this log was originating from datadog's code (and I switched to using my custom implementation of ScopeManager() so I don't have the issue anymore to check easily)

@mar-kolya
Copy link
Copy Markdown
Contributor

Hmm. interesting, thanks for an update!

I think it would log this exception and stack trace if you have DEBUG logging for the tracer enabled. But that should not cause any real runtime problem - and normally this is not enabled.

@randomanderson
Copy link
Copy Markdown
Contributor

This has been addressed in #1417

@tylerbenson tylerbenson added this to the Closed milestone May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants