rajeshkumarchandolu commented on code in PR #11607:
URL: https://github.com/apache/ozone/pull/11607#discussion_r4369831912


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/OzoneContextStorageProvider.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.tracing;
+
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.SpanContext;
+import io.opentelemetry.context.Context;
+import io.opentelemetry.context.ContextStorage;
+import io.opentelemetry.context.ContextStorageProvider;
+import io.opentelemetry.context.Scope;
+import org.slf4j.MDC;
+
+/**
+ * Registered through {@code META-INF/services} so OpenTelemetry uses {@link 
OzoneContextStorage},
+ * which wraps the default thread-local storage.
+ */
+public final class OzoneContextStorageProvider implements 
ContextStorageProvider {
+  public static final String MDC_TRACE_ID = "trace_id";
+  public static final String MDC_SPAN_ID = "span_id";
+
+  @Override
+  public ContextStorage get() {
+    return new OzoneContextStorage(ContextStorage.defaultStorage());
+  }
+
+  /**
+   * {@link ContextStorage} that keeps the logging MDC in sync with the 
current span.
+   * Every {@code makeCurrent()} / {@code Context.wrap(...)} goes through 
{@link #attach(Context)},
+   * so trace and span IDs are available to log patterns without changes at 
the call sites.
+   * The MDC is always derived from the current context (never saved and 
restored),
+   * so values inherited by child threads through the MDC are overwritten on 
the next attach or close.

Review Comment:
   Thanks, yes, I'm aware of this. Threads created inside a span, such as the 
SCM EventQueue executors, inherit the IDs through the reload4j MDC and keep 
them until they attach a context themselves. This PR only covers the 
synchronous paths: log lines that run inside the spans already shown in Jaeger 
for each command (RPC handlers, CLIs, S3G, datanode write and read paths) get 
the matching trace and span IDs. Asynchronous tasks like EventQueue aren't 
traced yet. I'm handling them in the follow-up that enables tracing across all 
the services, where the trace context will be propagated into those tasks.



-- 
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