sumitagrawl commented on code in PR #10020:
URL: https://github.com/apache/ozone/pull/10020#discussion_r3151787416
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java:
##########
@@ -46,34 +49,57 @@ public class TracingFilter implements
ContainerRequestFilter,
public void filter(ContainerRequestContext requestContext) {
finishAndCloseActiveSpan();
- TracingUtil.TraceCloseable activatedSpan =
-
TracingUtil.createActivatedSpan(resourceInfo.getResourceClass().getSimpleName()
+ "." +
- resourceInfo.getResourceMethod().getName());
- requestContext.setProperty(TRACING_SPAN_CLOSABLE, activatedSpan);
+ String traceparent = requestContext.getHeaderString("traceparent");
+ String tracestate = requestContext.getHeaderString("tracestate");
+ String encodedParent = TracingUtil.buildTraceContextCarrier(traceparent,
tracestate);
+
+ String spanName = resourceInfo.getResourceClass().getSimpleName() + "." +
+ resourceInfo.getResourceMethod().getName();
+
+ TracingUtil.TraceCloseable traceCloseable =
Review Comment:
check if trace header is not present, it should not start tracing if trace
is not enabled.
##########
hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/FreonS3TraceContextRequestHandler.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.ozone.freon;
+
+import com.amazonaws.Request;
+import com.amazonaws.handlers.RequestHandler2;
+import org.apache.hadoop.hdds.tracing.TracingUtil;
+
+/**
+ * Adds W3C trace context headers to each outgoing S3 request so the S3 Gateway
+ * can attach its spans to the Freon task span.
+ * BeforeRequest extracts current span info and converts it into a string
traceContext.
+ * This context is used to add headers to provide context to S3Gateway.
+ */
+public final class FreonS3TraceContextRequestHandler extends RequestHandler2 {
+
+ @Override
+ public void beforeRequest(Request<?> request) {
+ String traceContext = TracingUtil.exportCurrentSpan();
Review Comment:
We can export as W3Header export and import directly,
```
// Injecting context into an outbound request
W3CTraceContextPropagator.getInstance().inject(
Context.current(),
requestHeaders,
(carrier, key, value) -> carrier.put(key, value)
);
// Extracting context from an inbound request
Context extractedContext = W3CTraceContextPropagator.getInstance().extract(
Context.current(),
incomingHeaders,
(carrier, key) -> carrier.get(key)
);
```
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java:
##########
@@ -46,34 +49,57 @@ public class TracingFilter implements
ContainerRequestFilter,
public void filter(ContainerRequestContext requestContext) {
finishAndCloseActiveSpan();
- TracingUtil.TraceCloseable activatedSpan =
-
TracingUtil.createActivatedSpan(resourceInfo.getResourceClass().getSimpleName()
+ "." +
- resourceInfo.getResourceMethod().getName());
- requestContext.setProperty(TRACING_SPAN_CLOSABLE, activatedSpan);
+ String traceparent = requestContext.getHeaderString("traceparent");
Review Comment:
we can use same header exporter to get trace, may be this specific
understanding is not required.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java:
##########
@@ -46,34 +49,57 @@ public class TracingFilter implements
ContainerRequestFilter,
public void filter(ContainerRequestContext requestContext) {
finishAndCloseActiveSpan();
- TracingUtil.TraceCloseable activatedSpan =
-
TracingUtil.createActivatedSpan(resourceInfo.getResourceClass().getSimpleName()
+ "." +
- resourceInfo.getResourceMethod().getName());
- requestContext.setProperty(TRACING_SPAN_CLOSABLE, activatedSpan);
+ String traceparent = requestContext.getHeaderString("traceparent");
+ String tracestate = requestContext.getHeaderString("tracestate");
+ String encodedParent = TracingUtil.buildTraceContextCarrier(traceparent,
tracestate);
+
+ String spanName = resourceInfo.getResourceClass().getSimpleName() + "." +
+ resourceInfo.getResourceMethod().getName();
+
+ TracingUtil.TraceCloseable traceCloseable =
+ TracingUtil.createActivatedSpanWithParent(spanName, encodedParent);
+
+ requestContext.setProperty(TRACING_SPAN_CLOSABLE, traceCloseable);
}
@Override
public void filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext) {
final TracingUtil.TraceCloseable spanClosable
= (TracingUtil.TraceCloseable)
requestContext.getProperty(TRACING_SPAN_CLOSABLE);
+ if (spanClosable == null) {
+ return;
+ }
// HDDS-7064: Operation performed while writing StreamingOutput response
// should only be closed once the StreamingOutput callback has completely
// written the data to the destination
- OutputStream out = responseContext.getEntityStream();
- if (out != null) {
- responseContext.setEntityStream(new WrappedOutputStream(out) {
- @Override
- public void close() throws IOException {
- super.close();
- finishAndClose(spanClosable);
- }
- });
+ if (isStreamingGetObject(requestContext)) {
+ OutputStream out = responseContext.getEntityStream();
+ if (out != null) {
+ responseContext.setEntityStream(new WrappedOutputStream(out) {
+ @Override
+ public void close() throws IOException {
+ super.close();
+ finishAndClose(spanClosable);
+ }
+ });
+ } else {
+ finishAndClose(spanClosable);
+ }
} else {
finishAndClose(spanClosable);
}
}
+ private boolean isStreamingGetObject(ContainerRequestContext req) {
+ if (!HTTP_GET_METHOD.equalsIgnoreCase(req.getMethod())) {
Review Comment:
unable to understand this case why not traced
--
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]