yandrey321 commented on code in PR #11723:
URL: https://github.com/apache/ozone/pull/11723#discussion_r4379266105


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java:
##########
@@ -191,11 +197,49 @@ private static void initialize(String serviceName, 
TracingConfig cfg, boolean is
       return;
     }
 
+    if (!tracingEnabled) {
+      // Application-aware only: spans are created only under a valid parent, 
which most client processes never have.
+      // Build Ozone's SDK (exporter, export thread, global registration) when 
the first such span needs it.
+      pendingSdkServiceName = serviceName;
+      pendingSdkConfig = cfg;
+      return;
+    }
+
     // No app-supplied global — build Ozone's SDK and always register it as 
the JVM global,
     // so any co-resident library observes the same tracer whenever tracing is 
valid.
     initOzoneSdk(serviceName, cfg, true);
   }
 
+  /**
+   * Completes application-aware initialization left pending by {@link 
#initialize}: adopts an application
+   * GlobalOpenTelemetry registered since then, or builds Ozone's SDK. Called 
before creating a span with a parent.
+   */
+  private static void initPendingSdk() {
+    if (pendingSdkConfig == null) {
+      return;
+    }
+    synchronized (TracingUtil.class) {
+      final TracingConfig cfg = pendingSdkConfig;
+      if (cfg == null) {
+        return;
+      }
+      try {
+        if (GlobalOpenTelemetry.isSet() && 
isRealGlobal(GlobalOpenTelemetry.get())) {
+          tracer = GlobalOpenTelemetry.get().getTracer(GLOBAL_TRACER_NAME);

Review Comment:
   fixed. In 1.67.0, GlobalOpenTelemetry.get() with nothing registered installs 
OpenTelemetry.noop() wrapped in ObfuscatedOpenTelemetry, which passed the 
identity check. isRealGlobal() now also rejects a global whose tracer provider 
is the no-op one. Since set() can't replace an existing global, initOzoneSdk() 
now registers Ozone's SDK only when none is set, and otherwise uses it 
unregistered. The same misdetection affected the eager path (tracing enabled 
after an early GlobalOpenTelemetry.get()), which this fixes too. New tests 
cover initTracing() → GlobalOpenTelemetry.get() → valid parent, asserting that 
Ozone creates its own child span (a no-op tracer would return the parent), and 
the enabled case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to