[ 
https://issues.apache.org/jira/browse/HADOOP-15566?focusedWorklogId=745363&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-745363
 ]

ASF GitHub Bot logged work on HADOOP-15566:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Mar/22 18:45
            Start Date: 21/Mar/22 18:45
    Worklog Time Spent: 10m 
      Work Description: steveloughran commented on a change in pull request 
#3445:
URL: https://github.com/apache/hadoop/pull/3445#discussion_r831412903



##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/tracing/Span.java
##########
@@ -17,28 +17,54 @@
  */
 package org.apache.hadoop.tracing;
 
+import io.opentelemetry.context.Scope;
+
 import java.io.Closeable;
 
 public class Span implements Closeable {
-
+  private io.opentelemetry.api.trace.Span span = null;

Review comment:
       1. add some javadoc to line 24 to warn this wraps the opentelemetry span.
   2. skip the =null assignment, as it will save the jvm from some needless 
init. assuming a lot of spans get created, this may matter
   3. give the field a different name. like 'openspan'
   
   

##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/tracing/Span.java
##########
@@ -17,28 +17,54 @@
  */
 package org.apache.hadoop.tracing;
 
+import io.opentelemetry.context.Scope;
+
 import java.io.Closeable;
 
 public class Span implements Closeable {
-
+  private io.opentelemetry.api.trace.Span span = null;
   public Span() {
   }
 
+  public Span(io.opentelemetry.api.trace.Span span){
+    this.span = span;
+  }
+
   public Span addKVAnnotation(String key, String value) {
+    if(span != null){
+      span.setAttribute(key, value);
+    }
     return this;
   }
 
   public Span addTimelineAnnotation(String msg) {
+    if(span != null){
+      span.addEvent(msg);
+    }
     return this;
   }
 
   public SpanContext getContext() {
+    if(span != null){
+      return  new SpanContext(span.getSpanContext());
+    }
     return null;
   }
 
   public void finish() {
+    close();
   }
 
   public void close() {
+    if(span != null){
+      span.end();
+    }
+  }
+
+  public Scope makeCurrent() {

Review comment:
       nit: add javadocs

##########
File path: 
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/tracing/TestTracer.java
##########
@@ -0,0 +1,33 @@
+/**
+ * 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.tracing;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;

Review comment:
       * should extend AbstractHadoopTestBase or HadoopTestBase here.
   *  there is scope for a lot more tests

##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/tracing/Span.java
##########
@@ -17,28 +17,54 @@
  */
 package org.apache.hadoop.tracing;
 
+import io.opentelemetry.context.Scope;
+
 import java.io.Closeable;
 
 public class Span implements Closeable {
-
+  private io.opentelemetry.api.trace.Span span = null;
   public Span() {
   }
 
+  public Span(io.opentelemetry.api.trace.Span span){
+    this.span = span;
+  }
+
   public Span addKVAnnotation(String key, String value) {
+    if(span != null){
+      span.setAttribute(key, value);
+    }
     return this;
   }
 
   public Span addTimelineAnnotation(String msg) {
+    if(span != null){
+      span.addEvent(msg);
+    }
     return this;
   }
 
   public SpanContext getContext() {
+    if(span != null){
+      return  new SpanContext(span.getSpanContext());
+    }
     return null;
   }
 
   public void finish() {
+    close();
   }
 
   public void close() {
+    if(span != null){
+      span.end();

Review comment:
       would span need to be nullified here. or is it ok to invoke it after 
being ended?

##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/tracing/SpanContext.java
##########
@@ -18,15 +18,75 @@
 package org.apache.hadoop.tracing;
 
 import java.io.Closeable;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.TraceFlags;
+import io.opentelemetry.api.trace.TraceState;
+import io.opentelemetry.api.trace.TraceStateBuilder;
+import org.apache.hadoop.thirdparty.protobuf.ByteString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Wrapper class for SpanContext to avoid using OpenTracing/OpenTelemetry
  * SpanContext class directly for better separation.
  */
-public class SpanContext implements Closeable {
-  public SpanContext() {
+public class SpanContext implements Closeable  {
+  public static final Logger LOG = 
LoggerFactory.getLogger(SpanContext.class.getName());
+  private static final String TRACE_ID = "TRACE_ID";
+  private static final String SPAN_ID = "SPAN_ID";
+  private static final String TRACE_FLAGS = "TRACE_FLAGS";
+
+
+  private io.opentelemetry.api.trace.SpanContext spanContext = null;
+  public SpanContext(io.opentelemetry.api.trace.SpanContext spanContext) {
+    this.spanContext = spanContext;
   }
 
   public void close() {
+
+  }
+
+  public Map<String, String> getKVSpanContext(){
+    if(spanContext != null){
+      //TODO: may we should move this to Proto
+      Map<String, String> kvMap = new HashMap<>();
+      kvMap.put(TRACE_ID, spanContext.getTraceId());
+      kvMap.put(SPAN_ID, spanContext.getSpanId());
+      kvMap.put(TRACE_FLAGS, spanContext.getTraceFlags().asHex());
+      kvMap.putAll(spanContext.getTraceState().asMap());
+      return kvMap;
+    }
+    return null;
+  }
+
+  static SpanContext buildFromKVMap(Map<String, String> kvMap){
+    try{
+      String traceId = kvMap.get(TRACE_ID);
+      String spanId = kvMap.get(SPAN_ID);
+      String traceFlagsHex = kvMap.get(TRACE_FLAGS);
+      TraceFlags traceFlags = TraceFlags.fromHex(traceFlagsHex, 0);

Review comment:
        what if traceFlagsHex isn't found? exit fast

##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/tracing/SpanContext.java
##########
@@ -18,15 +18,75 @@
 package org.apache.hadoop.tracing;
 
 import java.io.Closeable;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.TraceFlags;
+import io.opentelemetry.api.trace.TraceState;
+import io.opentelemetry.api.trace.TraceStateBuilder;
+import org.apache.hadoop.thirdparty.protobuf.ByteString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Wrapper class for SpanContext to avoid using OpenTracing/OpenTelemetry
  * SpanContext class directly for better separation.
  */
-public class SpanContext implements Closeable {
-  public SpanContext() {
+public class SpanContext implements Closeable  {
+  public static final Logger LOG = 
LoggerFactory.getLogger(SpanContext.class.getName());
+  private static final String TRACE_ID = "TRACE_ID";
+  private static final String SPAN_ID = "SPAN_ID";
+  private static final String TRACE_FLAGS = "TRACE_FLAGS";
+
+
+  private io.opentelemetry.api.trace.SpanContext spanContext = null;

Review comment:
       again, give a different field name to avoid more confusion; skip the 
assignment to null

##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/tracing/TraceUtils.java
##########
@@ -20,28 +20,36 @@
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.thirdparty.protobuf.ByteString;
+import org.slf4j.Logger;

Review comment:
       nit: import rules/ordering




-- 
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: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 745363)
    Time Spent: 10h 10m  (was: 10h)

> Support OpenTelemetry
> ---------------------
>
>                 Key: HADOOP-15566
>                 URL: https://issues.apache.org/jira/browse/HADOOP-15566
>             Project: Hadoop Common
>          Issue Type: New Feature
>          Components: metrics, tracing
>    Affects Versions: 3.1.0
>            Reporter: Todd Lipcon
>            Assignee: Siyao Meng
>            Priority: Major
>              Labels: pull-request-available, security
>         Attachments: HADOOP-15566-WIP.1.patch, HADOOP-15566.000.WIP.patch, 
> OpenTelemetry Support Scope Doc v2.pdf, OpenTracing Support Scope Doc.pdf, 
> Screen Shot 2018-06-29 at 11.59.16 AM.png, ss-trace-s3a.png
>
>          Time Spent: 10h 10m
>  Remaining Estimate: 0h
>
> The HTrace incubator project has voted to retire itself and won't be making 
> further releases. The Hadoop project currently has various hooks with HTrace. 
> It seems in some cases (eg HDFS-13702) these hooks have had measurable 
> performance overhead. Given these two factors, I think we should consider 
> removing the HTrace integration. If there is someone willing to do the work, 
> replacing it with OpenTracing might be a better choice since there is an 
> active community.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to