chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190802724
 
 

 ##########
 File path: 
common/scala/src/main/scala/whisk/common/tracing/OpenTracingProvider.scala
 ##########
 @@ -0,0 +1,198 @@
+/*
+ * 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 whisk.common.tracing
+
+import scala.collection.concurrent.TrieMap
+import scala.collection.mutable
+
+import brave.Tracing
+import brave.opentracing.BraveTracer
+import io.opentracing.{ActiveSpan, SpanContext}
+import io.opentracing.util.GlobalTracer
+import io.opentracing.propagation.{Format, TextMapExtractAdapter, 
TextMapInjectAdapter}
+import zipkin.reporter.Sender
+import zipkin.reporter.okhttp3.OkHttpSender
+import zipkin.reporter.AsyncReporter
+import zipkin.reporter.Reporter
+import pureconfig._
+import whisk.common.{LogMarkerToken, TransactionId}
+import whisk.core.ConfigKeys
+
+/**
+ * OpenTracing based implementation for tracing
+ */
+object OpenTracingProvider {
+
+  private val spanMap: mutable.Map[String, mutable.ListBuffer[ActiveSpan]] =
+    TrieMap[String, mutable.ListBuffer[ActiveSpan]]()
+  private val contextMap: mutable.Map[String, SpanContext] = TrieMap[String, 
SpanContext]()
+
+  var enabled = false;
+
+  def apply(serviceName: String): Unit = {
+    configureTracer(serviceName)
+  }
+
 
 Review comment:
   It would better to avoid a mutable enabled flag and rely on that in logic 
later. Instead have 2 variants - `NoopTracer` and `OpenTracer`. Something like 
below. With this whole tracing would be setup at time of first access to 
tracer. If enabled `OpenTracer` would get used otherwise a noop variant would 
be used
   
   ```scala
   object WhiskTracerProvider {
     val tracingConfig = loadConfigOrThrow[TracingConfig](ConfigKeys.tracing)
   
     val tracer = if (tracingConfig.enabled) new 
OpenTracer(createZipkinTracer(tracingConfig)) else NoopTracer
   }
   
   trait WhiskTracer {
     def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {}
     def finish(logMarker: LogMarkerToken, transactionId: TransactionId): Unit 
= {}
     def error(transactionId: TransactionId): Unit = {}
     def getTraceContext(transactionId: TransactionId): Option[Map[String, 
String]] = None
     def setTraceContext(transactionId: TransactionId, context: 
Option[Map[String, String]]): Unit = {}
   }
   
   private object NoopTracer extends WhiskTracer
   
   private class OpenTracer(tracer: Tracer) extends WhiskTracer {
   //Implement the methods here
   }

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to