[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-06-12 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r194667851
 
 

 ##
 File path: 
common/scala/src/main/scala/whisk/common/tracing/TracingCacheProvider.scala
 ##
 @@ -0,0 +1,108 @@
+/*
+ * 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 java.util.concurrent.TimeUnit
+
+import com.github.benmanes.caffeine.cache.{Cache, Caffeine}
+import io.opentracing.{Span, SpanContext}
+import pureconfig.loadConfigOrThrow
+import whisk.core.ConfigKeys
+
+import scala.collection.mutable
+import scala.ref.WeakReference
+
+class WhiskTracingSpanCacheImpl(val cache: Cache[String, 
mutable.ListBuffer[WeakReference[Span]]])
+extends WhiskTracingSpanCache {
+
+  override def put(key: String, value: 
mutable.ListBuffer[WeakReference[Span]]): Unit = {
 
 Review comment:
   Would be better to avoid using a mutable `ListBuffer` here. See [this 
previous comment][1] for a possible approach.
   
   [1]: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190802179


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


[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-06-12 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r194665739
 
 

 ##
 File path: 
common/scala/src/main/scala/whisk/common/tracing/TracingCacheProvider.scala
 ##
 @@ -0,0 +1,108 @@
+/*
+ * 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 java.util.concurrent.TimeUnit
+
+import com.github.benmanes.caffeine.cache.{Cache, Caffeine}
+import io.opentracing.{Span, SpanContext}
+import pureconfig.loadConfigOrThrow
+import whisk.core.ConfigKeys
+
+import scala.collection.mutable
+import scala.ref.WeakReference
+
+class WhiskTracingSpanCacheImpl(val cache: Cache[String, 
mutable.ListBuffer[WeakReference[Span]]])
 
 Review comment:
   Instead of having these wrapper classes can we directly construct the cache 
in `OpenTracer` like
   
   ```
   Caffeine
 .newBuilder()
 .asInstanceOf[Caffeine[String, 
mutable.ListBuffer[WeakReference[Span]]]
 .expireAfterAccess(duration, TimeUnit.MINUTES)
 .softValues()
 .build()
 .asMap()
   ```
   
   This returns a `Map` instance which can then be used similar to what the 
logic was prior to switch to cache


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


[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-06-12 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r194664618
 
 

 ##
 File path: 
common/scala/src/main/scala/whisk/common/tracing/OpenTracingProvider.scala
 ##
 @@ -0,0 +1,220 @@
+/*
+ * 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.mutable
+import scala.collection.JavaConverters._
+import brave.Tracing
+import brave.opentracing.BraveTracer
+import brave.sampler.Sampler
+import io.opentracing.{Span, SpanContext, Tracer}
+import io.opentracing.util.GlobalTracer
+import io.opentracing.propagation.{Format, TextMapExtractAdapter, 
TextMapInjectAdapter}
+import zipkin2.reporter.{AsyncReporter, Sender}
+import zipkin2.reporter.okhttp3.OkHttpSender
+import pureconfig._
+import whisk.common.{LogMarkerToken, TransactionId}
+import whisk.core.ConfigKeys
+
+import scala.ref.WeakReference
+
+/**
+ * OpenTracing based implementation for tracing
+ */
+class OpenTracer(val tracer: Tracer) extends WhiskTracer {
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  override def startSpan(logMarker: LogMarkerToken, transactionId: 
TransactionId): Unit = {
+
+val activeSpan: Option[Span] =
+  TracingCacheProvider.spanCache.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child span
+  val spanBuilder = tracer
+.buildSpan(logMarker.action)
+.withTag("transactionId", transactionId.meta.id)
+
+  Some(
+spanList.last.get
+  .map(spanBuilder.asChildOf(_).startActive(true).span())
+  .getOrElse(spanBuilder.startActive(true).span()))
+
+}
+case None => {
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[WeakReference[Span]] = 
mutable.ListBuffer()
+  TracingCacheProvider.spanCache.put(transactionId.meta.id, list)
+
+  TracingCacheProvider.contextCache.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child span if we have a tracing context
+  Some(
+tracer
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(context)
+  .startActive(true)
+  .span())
+}
+case None => {
+  Some(
+tracer
+  .buildSpan(logMarker.action)
+  .ignoreActiveSpan()
+  .withTag("transactionId", transactionId.meta.id)
+  .startActive(true)
+  .span())
+}
+  }
+}
+  }
+
+//add active span to list
+if (activeSpan.isDefined)
+  TracingCacheProvider.spanCache.get(transactionId.meta.id).map(_.+=:(new 
WeakReference(activeSpan.get)))
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  override def finishSpan(transactionId: TransactionId): Unit = {
+clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  override def error(transactionId: TransactionId): Unit = {
+clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  override def getTraceContext(transactionId: TransactionId): 
Option[Map[String, String]] = {
+var contextMap: Option[Map[String, String]] = None
+TracingCacheProvider.spanCache.get(transactionId.meta.id) match {
+  case Some(spanList) => {
+var map: java.util.Map[String, String] = new java.util.HashMap()
+//inject latest span context in map
+spanList.last.get match {
+  case Some(span) => {
+tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new 
TextMapInjectAdapter(map))
+contextMap = 

[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-06-12 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r194662887
 
 

 ##
 File path: 
common/scala/src/main/scala/whisk/common/tracing/OpenTracingProvider.scala
 ##
 @@ -0,0 +1,220 @@
+/*
+ * 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.mutable
+import scala.collection.JavaConverters._
+import brave.Tracing
+import brave.opentracing.BraveTracer
+import brave.sampler.Sampler
+import io.opentracing.{Span, SpanContext, Tracer}
+import io.opentracing.util.GlobalTracer
+import io.opentracing.propagation.{Format, TextMapExtractAdapter, 
TextMapInjectAdapter}
+import zipkin2.reporter.{AsyncReporter, Sender}
+import zipkin2.reporter.okhttp3.OkHttpSender
+import pureconfig._
+import whisk.common.{LogMarkerToken, TransactionId}
+import whisk.core.ConfigKeys
+
+import scala.ref.WeakReference
+
+/**
+ * OpenTracing based implementation for tracing
+ */
+class OpenTracer(val tracer: Tracer) extends WhiskTracer {
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  override def startSpan(logMarker: LogMarkerToken, transactionId: 
TransactionId): Unit = {
+
+val activeSpan: Option[Span] =
+  TracingCacheProvider.spanCache.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child span
+  val spanBuilder = tracer
+.buildSpan(logMarker.action)
+.withTag("transactionId", transactionId.meta.id)
+
+  Some(
+spanList.last.get
+  .map(spanBuilder.asChildOf(_).startActive(true).span())
+  .getOrElse(spanBuilder.startActive(true).span()))
+
+}
+case None => {
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[WeakReference[Span]] = 
mutable.ListBuffer()
+  TracingCacheProvider.spanCache.put(transactionId.meta.id, list)
+
+  TracingCacheProvider.contextCache.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child span if we have a tracing context
+  Some(
+tracer
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(context)
+  .startActive(true)
+  .span())
+}
+case None => {
+  Some(
+tracer
+  .buildSpan(logMarker.action)
+  .ignoreActiveSpan()
+  .withTag("transactionId", transactionId.meta.id)
+  .startActive(true)
+  .span())
+}
+  }
+}
+  }
+
+//add active span to list
+if (activeSpan.isDefined)
+  TracingCacheProvider.spanCache.get(transactionId.meta.id).map(_.+=:(new 
WeakReference(activeSpan.get)))
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  override def finishSpan(transactionId: TransactionId): Unit = {
+clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  override def error(transactionId: TransactionId): Unit = {
+clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  override def getTraceContext(transactionId: TransactionId): 
Option[Map[String, String]] = {
+var contextMap: Option[Map[String, String]] = None
+TracingCacheProvider.spanCache.get(transactionId.meta.id) match {
+  case Some(spanList) => {
+var map: java.util.Map[String, String] = new java.util.HashMap()
+//inject latest span context in map
+spanList.last.get match {
+  case Some(span) => {
+tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new 
TextMapInjectAdapter(map))
+contextMap = 

[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-06-12 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r194661744
 
 

 ##
 File path: common/scala/src/main/resources/application.conf
 ##
 @@ -186,4 +186,14 @@ whisk {
 constraint-delimiter = " "//used to parse constraint strings
 teardown-on-exit = true //set to true to disable the mesos framework 
on system exit; set for false for HA deployments
 }
+
+# tracing configuration
+tracing {
+cache-expiry = 30 #cache expiry in seconds. Set to appropriate value 
to trace long running requests
+#zipnkin configuration. Uncomment following to enable zipkin based 
tracing
+#zipkin {
+#url = "http://localhost:9411; //url to connecto to zipkin server
+#sample-rate = "0.01"
 
 Review comment:
   Can we link to some document which explains the `sample-rate` for reference. 


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


[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190802858
 
 

 ##
 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)
+  }
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {
+if (enabled) {
+  var activeSpan: Option[ActiveSpan] = None
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child trace
+  activeSpan = Some(
+GlobalTracer
+  .get()
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(spanList.last)
+  .startActive())
+}
+case None => {
+  contextMap.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child trace if we have a tracing context
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).asChildOf(context).startActive())
+}
+case None => {
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).ignoreActiveSpan().startActive())
+}
+  }
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[ActiveSpan] = mutable.ListBuffer()
+  spanMap.put(transactionId.meta.id, list)
+}
+  }
+
+  //add active span to list
+  if (activeSpan.isDefined)
+spanMap.get(transactionId.meta.id).map(_.+=:(activeSpan.get))
+}
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  def finish(logMarker: LogMarkerToken, transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  def error(transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  def getTraceContext(transactionId: TransactionId): Option[Map[String, 
String]] = {
+var contextMap: Option[Map[String, String]] = None
+if (enabled) {
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  var map: java.util.Map[String, String] = new java.util.HashMap()
+  //inject latest span context in map
+  GlobalTracer.get().inject(spanList.last.context(), 
Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(map))
+  contextMap = 
Some(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap)
+}
+case None => None
+  }
+}
+contextMap
+  }
+
+  /**
+   * Get 

[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190803840
 
 

 ##
 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)
+  }
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {
+if (enabled) {
+  var activeSpan: Option[ActiveSpan] = None
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child trace
+  activeSpan = Some(
+GlobalTracer
+  .get()
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(spanList.last)
+  .startActive())
+}
+case None => {
+  contextMap.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child trace if we have a tracing context
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).asChildOf(context).startActive())
+}
+case None => {
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).ignoreActiveSpan().startActive())
+}
+  }
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[ActiveSpan] = mutable.ListBuffer()
+  spanMap.put(transactionId.meta.id, list)
+}
+  }
+
+  //add active span to list
+  if (activeSpan.isDefined)
+spanMap.get(transactionId.meta.id).map(_.+=:(activeSpan.get))
+}
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  def finish(logMarker: LogMarkerToken, transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  def error(transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  def getTraceContext(transactionId: TransactionId): Option[Map[String, 
String]] = {
+var contextMap: Option[Map[String, String]] = None
+if (enabled) {
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  var map: java.util.Map[String, String] = new java.util.HashMap()
+  //inject latest span context in map
+  GlobalTracer.get().inject(spanList.last.context(), 
Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(map))
+  contextMap = 
Some(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap)
+}
+case None => None
+  }
+}
+contextMap
+  }
+
+  /**
+   * Get 

[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190799562
 
 

 ##
 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)
+  }
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {
+if (enabled) {
+  var activeSpan: Option[ActiveSpan] = None
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child trace
+  activeSpan = Some(
+GlobalTracer
+  .get()
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(spanList.last)
+  .startActive())
+}
+case None => {
+  contextMap.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child trace if we have a tracing context
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).asChildOf(context).startActive())
+}
+case None => {
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).ignoreActiveSpan().startActive())
+}
+  }
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[ActiveSpan] = mutable.ListBuffer()
+  spanMap.put(transactionId.meta.id, list)
+}
+  }
+
+  //add active span to list
+  if (activeSpan.isDefined)
+spanMap.get(transactionId.meta.id).map(_.+=:(activeSpan.get))
+}
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  def finish(logMarker: LogMarkerToken, transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  def error(transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  def getTraceContext(transactionId: TransactionId): Option[Map[String, 
String]] = {
+var contextMap: Option[Map[String, String]] = None
+if (enabled) {
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  var map: java.util.Map[String, String] = new java.util.HashMap()
+  //inject latest span context in map
+  GlobalTracer.get().inject(spanList.last.context(), 
Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(map))
+  contextMap = 
Some(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap)
+}
+case None => None
+  }
+}
+contextMap
+  }
+
+  /**
+   * Get 

[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190804603
 
 

 ##
 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)
+  }
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {
+if (enabled) {
+  var activeSpan: Option[ActiveSpan] = None
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child trace
+  activeSpan = Some(
+GlobalTracer
+  .get()
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(spanList.last)
+  .startActive())
+}
+case None => {
+  contextMap.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child trace if we have a tracing context
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).asChildOf(context).startActive())
+}
+case None => {
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).ignoreActiveSpan().startActive())
+}
+  }
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[ActiveSpan] = mutable.ListBuffer()
+  spanMap.put(transactionId.meta.id, list)
+}
+  }
+
+  //add active span to list
+  if (activeSpan.isDefined)
+spanMap.get(transactionId.meta.id).map(_.+=:(activeSpan.get))
+}
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  def finish(logMarker: LogMarkerToken, transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  def error(transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  def getTraceContext(transactionId: TransactionId): Option[Map[String, 
String]] = {
+var contextMap: Option[Map[String, String]] = None
+if (enabled) {
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  var map: java.util.Map[String, String] = new java.util.HashMap()
+  //inject latest span context in map
+  GlobalTracer.get().inject(spanList.last.context(), 
Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(map))
+  contextMap = 
Some(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap)
+}
+case None => None
+  }
+}
+contextMap
+  }
+
+  /**
+   * Get 

[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
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


[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190799810
 
 

 ##
 File path: 
core/controller/src/main/scala/whisk/core/controller/Controller.scala
 ##
 @@ -203,6 +204,7 @@ object Controller {
 // if deploying multiple instances (scale out), must pass the instance 
number as the
 require(args.length >= 1, "controller instance required")
 val instance = args(0).toInt
+OpenTracingProvider.apply("Controller")
 
 Review comment:
   Instead of having controller and invoker initialize the tracer it would be 
better to capture the name as part of config itself. Then you can specify the 
name in reference.conf of invoker and controller and no need for any explicit 
initialization call


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


[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190802179
 
 

 ##
 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)
+  }
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {
+if (enabled) {
+  var activeSpan: Option[ActiveSpan] = None
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child trace
+  activeSpan = Some(
+GlobalTracer
+  .get()
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(spanList.last)
+  .startActive())
+}
+case None => {
+  contextMap.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child trace if we have a tracing context
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).asChildOf(context).startActive())
+}
+case None => {
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).ignoreActiveSpan().startActive())
+}
+  }
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[ActiveSpan] = mutable.ListBuffer()
+  spanMap.put(transactionId.meta.id, list)
+}
+  }
+
+  //add active span to list
+  if (activeSpan.isDefined)
+spanMap.get(transactionId.meta.id).map(_.+=:(activeSpan.get))
+}
 
 Review comment:
   Avoid using `var` as much as possible. For example here it would be better 
to have `spanMap` use immutable list as values instead of buffer. And then 
above logic can be rewritten as below. Note here we add to head of list. So 
later in clear we need to remove from head
   
   ```scala
 override def startTrace(logMarker: LogMarkerToken, transactionId: 
TransactionId): Unit = {
   val spanList = spanMap.getOrElse(transactionId.meta.id, Nil)
   val activeSpan = spanList match {
 case Nil => getContextSpan(logMarker, transactionId)
 case _ =>
   tracer
 .buildSpan(logMarker.action)
 .withTag("transactionId", transactionId.meta.id)
 .asChildOf(spanList.last)
 .startActive()
   }
   
   spanMap.put(transactionId.meta.id, activeSpan :: spanList)
 }
   
 private def getContextSpan(logMarker: LogMarkerToken, transactionId: 
TransactionId) = {
   val baseSpan = tracer.buildSpan(logMarker.action)
   contextMap
 .get(transactionId.meta.id)
 .map(baseSpan.asChildOf(_).startActive())
 .getOrElse(baseSpan.ignoreActiveSpan().startActive())
 }
   ```


[GitHub] chetanmeh commented on a change in pull request #2282: Distributed tracing support #2192

2018-05-25 Thread GitBox
chetanmeh commented on a change in pull request #2282: Distributed tracing 
support #2192
URL: 
https://github.com/apache/incubator-openwhisk/pull/2282#discussion_r190800720
 
 

 ##
 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)
+  }
+
+  /**
+   * Start a Trace for given service.
+   *
+   * @param transactionId transactionId to which this Trace belongs.
+   * @return TracedRequest which provides details about current service being 
traced.
+   */
+  def startTrace(logMarker: LogMarkerToken, transactionId: TransactionId): 
Unit = {
+if (enabled) {
+  var activeSpan: Option[ActiveSpan] = None
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  //create a child trace
+  activeSpan = Some(
+GlobalTracer
+  .get()
+  .buildSpan(logMarker.action)
+  .withTag("transactionId", transactionId.meta.id)
+  .asChildOf(spanList.last)
+  .startActive())
+}
+case None => {
+  contextMap.get(transactionId.meta.id) match {
+case Some(context) => {
+  //create child trace if we have a tracing context
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).asChildOf(context).startActive())
+}
+case None => {
+  activeSpan = 
Some(GlobalTracer.get().buildSpan(logMarker.action).ignoreActiveSpan().startActive())
+}
+  }
+  //initialize list for this transactionId
+  val list: mutable.ListBuffer[ActiveSpan] = mutable.ListBuffer()
+  spanMap.put(transactionId.meta.id, list)
+}
+  }
+
+  //add active span to list
+  if (activeSpan.isDefined)
+spanMap.get(transactionId.meta.id).map(_.+=:(activeSpan.get))
+}
+  }
+
+  /**
+   * Finish a Trace associated with given transactionId.
+   *
+   * @param transactionId
+   */
+  def finish(logMarker: LogMarkerToken, transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Register error
+   *
+   * @param transactionId
+   */
+  def error(transactionId: TransactionId): Unit = {
+if (enabled)
+  clear(transactionId)
+  }
+
+  /**
+   * Get the current TraceContext which can be used for downstream services
+   *
+   * @param transactionId
+   * @return
+   */
+  def getTraceContext(transactionId: TransactionId): Option[Map[String, 
String]] = {
+var contextMap: Option[Map[String, String]] = None
+if (enabled) {
+  spanMap.get(transactionId.meta.id) match {
+case Some(spanList) => {
+  var map: java.util.Map[String, String] = new java.util.HashMap()
+  //inject latest span context in map
+  GlobalTracer.get().inject(spanList.last.context(), 
Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(map))
+  contextMap = 
Some(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap)
 
 Review comment:
   Instead of this you can use [JavaConverters implicits][1]