micronaut-gcp icon indicating copy to clipboard operation
micronaut-gcp copied to clipboard

ClassNotFoundException: brave.http.HttpClientHandler when running in certain environments

Open jamesdh opened this issue 3 years ago • 2 comments

Task List

  • [x] Steps to reproduce provided
  • [x] Stacktrace (if present) provided
  • [ ] Example that reproduces the problem uploaded to Github
  • [x] Full description of the issue provided (see below)

Steps to Reproduce

I was working through the Micronaut GCP docs to get logging + tracing working correctly on an app deployed to a GKE Autopilot cluster. The logging I was able to get configured but have not had much luck getting tracing working correctly. When I eventually pushed my changes, my automated tests ran via GitHub Actions, at which point I would get a failure due to a ClassNotFoundException that appears to be related to brave:

Caused by: java.lang.ClassNotFoundException: brave.http.HttpClientHandler
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 84 more

But when running tests locally, I have no such issue. I tried disabling both zipkin tracing and gcp tracing in application.yml, but it made no difference.

However, after taking a look at the release notes, it appears beginning with Brave v5.13 they made some changes to their maven BOM which could be the cause of any such transitive dependency issues:

End users can opt-in to io.zipkin.brave:brave-bom to pin our versions, but we will no longer use tools like BOMs for internal convenience.

I'm afraid I'm too inexperienced with both GCP/GKE and Brave to understand what's going on here, but I'm guessing it's somehow related to the fact that GitHub Actions are themselves running in a cloud environment, which in turn is incorrectly being detected and thus it tries to run brave?

Manually adding runtimeOnly("io.zipkin.brave:brave-instrumentation-http:5.13.3") to build.gradle got around this testing quirk, but I'm guessing that isn't the expected behavior...

Environment Information

  • Operating System: GitHub Actions Linux runner
  • Micronaut Version: 2.4.2
  • JDK Version: Java_Adopt_jdk/11.0.10-9/x64

jamesdh avatar Apr 05 '21 17:04 jamesdh

I am facing the same problem here.

My test fails only on GitHub Actions, but locally it works.

  • Operating System: GitHub Actions Linux runner
  • Micronaut Version: 3.1.3
  • JDK Version: OpenJDK 16 64-Bit
io.micronaut.context.exceptions.BeanInstantiationException: 
Error instantiating bean of type  [io.micronaut.http.server.RouteExecutor]

Message: brave/http/HttpClientHandler
Path Taken: NettyEmbeddedServer.buildDefaultServer(NettyHttpServerConfiguration configuration) --> new DefaultNettyEmbeddedServerFactory(ApplicationContext applicationContext,[RouteExecutor routeExecutor],MediaTypeCodecRegistry mediaTypeCodecRegistry,StaticResourceResolver staticResourceResolver,ThreadFactory nettyThreadFactory,HttpCompressionStrategy httpCompressionStrategy,EventLoopGroupFactory eventLoopGroupFactory,EventLoopGroupRegistry eventLoopGroupRegistry) --> new RouteExecutor([Router router],BeanContext beanContext,RequestArgumentSatisfier requestArgumentSatisfier,HttpServerConfiguration serverConfiguration,ErrorResponseProcessor errorResponseProcessor,ExecutorSelector executorSelector)
Caused by: java.lang.NoClassDefFoundError: brave/http/HttpClientHandler
Caused by: java.lang.ClassNotFoundException: brave.http.HttpClientHandler

caiolopes avatar Nov 08 '21 18:11 caiolopes

I've just ran into this same problem. Unfortunately I can't add brave-instrumentation-http to the classpath as it replaces the OpenTracingServerFilter bean from micronaut-trace.

Running locally is working as expected but fails on GCP.

Strangely it seems that enabling metrics in application.yml fixes the issue.

  • Micronaut Version: 3.5.3

danielmatthews84 avatar Jul 26 '22 11:07 danielmatthews84