Skip to content

Avoid eager GlobalTracer loading in OpenTracingOptions - #3240

Open
poblouin wants to merge 1 commit into
temporalio:mainfrom
poblouin:fix/lazy-global-tracer-opentracing-options
Open

poblouin wants to merge 1 commit into
temporalio:mainfrom
poblouin:fix/lazy-global-tracer-opentracing-options

Conversation

@poblouin

Copy link
Copy Markdown

What was changed

  • Lazily initialize OpenTracingOptions.DEFAULT_INSTANCE via a private static DefaultInstanceHolder class returned from OpenTracingOptions.getDefaultInstance().
  • Replace MoreObjects.firstNonNull(tracer, GlobalTracer.get()) in OpenTracingOptions.Builder.build() with tracer != null ? tracer : GlobalTracer.get() so GlobalTracer.get() is only evaluated when no explicit Tracer was configured, and remove the unused MoreObjects import.
  • Add OpenTracingOptionsTest verifying with a child-first URLClassLoader that building OpenTracingOptions with an explicit Tracer does not load io.opentracing.util.GlobalTracer, while getDefaultInstance() and newBuilder().build() without a tracer still lazily load it.

Why?

Previously, configuring temporal-opentracing with an explicit Tracer (for example, an OpenTelemetry-to-OpenTracing shim) still loaded and initialized io.opentracing.util.GlobalTracer in two places:

  1. OpenTracingOptions's static initializer eagerly built DEFAULT_INSTANCE = OpenTracingOptions.newBuilder().build(), calling GlobalTracer.get() as soon as OpenTracingOptions was initialized.
  2. Builder.build() called MoreObjects.firstNonNull(tracer, GlobalTracer.get()), which eagerly evaluated its second argument GlobalTracer.get() even when tracer was non-null.

With Java agents such as dd-trace-java when DD_TRACE_OTEL_ENABLED=true, merely loading io.opentracing.util.GlobalTracer activates the agent's OpenTracing integration even when an explicit OTel-shim Tracer is passed via setTracer(...), causing Both OpenTracing and OpenTelemetry integrations are enabled warnings.

Checklist

  1. How was this tested:

    • Added OpenTracingOptionsTest (explicitTracerDoesNotLoadGlobalTracer, buildWithoutExplicitTracerLoadsGlobalTracer, getDefaultInstanceLoadsGlobalTracerLazily, getDefaultInstanceReturnsSingleton).
    • Verified GlobalTracerTest and the full :temporal-opentracing module checks pass via ./gradlew :temporal-opentracing:check :temporal-opentracing:javadoc (28 tests passed, spotlessCheck, ErrorProne, and --release 8 compilation clean).
  2. Any docs updates needed?

    • No.

Co-authored-by: ws-yukon <ws-yukon@users.noreply.github.com>
@poblouin
poblouin requested a review from a team as a code owner November 27, 2026 18:24
@CLAassistant

CLAassistant commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

2 participants