Opencensus GCP class tried to access private field

If you getting these opencensus errors in GCP from time to time:

java.lang.IllegalAccessError: class io.grpc.internal.CensusTracingModule$TracingClientInterceptor tried to access private field io.opencensus.trace.unsafe.ContextUtils.CONTEXT_SPAN_KEY (io.grpc.internal.CensusTracingModule$TracingClientInterceptor and io.opencensus.trace.unsafe.ContextUtils are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @1753acfe)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor.interceptCall(CensusTracing Module.java:384)
java.lang.IllegalAccessError: class io.opencensus.implcore.tags.CurrentTagContextUtils tried to access private field io.opencensus.tags.unsafe.ContextUtils.TAG_CONTEXT_KEY (io.opencensus.implcore.tags.CurrentTagContextUtils and io.opencensus.tags.unsafe.ContextUtils are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @1753acfe)
at io.opencensus.implcore.tags.CurrentTagContextUtils.getCurrentTagContext(CurrentTagContextUtils.java:37)

It worth to recheck dependency version of each opencensus component, that actually presented in your final jar:

  • io.opencensus:opencensus-api
  • io.opencensus:opencensus-exporter-trace-stackdriver
  • io.opencensus:opencensus-impl
  • io.opencensus:opencensus-contrib-spring

You may have opencensus-api version 0.19.2, and opencensus-impl version 0.15.0. Thus solution is to equalize all these versions.

You can review your dependency versions with following commands:

./gradlew dependencies
mvn dependency:tree

And keep in mind, that in case you’re using Gradle, it may set version constraints for some artifacts.
If some dependency set constraint for this artifact, gradle will show (c) symbol ader version number like this:

io.opencensus:opencensus-api:0.15.0 (c)

That’s all.

Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *