zipkin-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-zipkin-brave] devinsba commented on a change in pull request #904: Messaging adapter
Date Thu, 09 May 2019 17:09:38 GMT
devinsba commented on a change in pull request #904: Messaging adapter
URL: https://github.com/apache/incubator-zipkin-brave/pull/904#discussion_r282579930
 
 

 ##########
 File path: instrumentation/messaging/src/main/java/brave/messaging/MessagingProducerHandler.java
 ##########
 @@ -0,0 +1,56 @@
+package brave.messaging;
+
+import brave.Span;
+import brave.Tracer;
+import brave.propagation.TraceContext;
+
+public class MessagingProducerHandler<Msg> extends MessagingHandler<Msg, MessagingAdapter<Msg>>
{
+
+  public static <Msg> MessagingProducerHandler<Msg> create(MessagingTracing tracing,
+      MessagingAdapter<Msg> adapter,
+      TraceContext.Extractor<Msg> extractor,
+      TraceContext.Injector<Msg> injector) {
+    return new MessagingProducerHandler<>(tracing, adapter, extractor, injector);
+  }
+
+  final Tracer tracer;
+
+  MessagingProducerHandler(MessagingTracing messagingTracing,
+      MessagingAdapter<Msg> adapter,
+      TraceContext.Extractor<Msg> extractor,
+      TraceContext.Injector<Msg> injector) {
+    super(messagingTracing.tracing.currentTraceContext(), adapter, messagingTracing.parser,
+        extractor, injector);
+    this.tracer = messagingTracing.tracing.tracer();
+  }
+
+  public Span handleProduce(Msg message) {
+    TraceContext maybeParent = currentTraceContext.get();
+    // Unlike message consumers, we try current span before trying extraction. This is the
proper
+    // order because the span in scope should take precedence over a potentially stale header
entry.
+    //
+    // NOTE: Brave instrumentation used properly does not result in stale header entries,
as we
+    // always clear message headers after reading.
+    Span span;
+    if (maybeParent == null) {
+      span = tracer.nextSpan(parser.extractContextAndClearMessage(adapter, extractor, message));
+    } else {
+      // As JMS is sensitive about write access to headers, we  defensively clear even if
it seems
+      // upstream would have cleared (because there is a span in scope!).
+      span = tracer.newChild(maybeParent);
+      adapter.clearPropagation(message);
+    }
+
+    if (!span.isNoop()) {
+      span.kind(Span.Kind.PRODUCER).name("send");
+      parser.message(adapter, message, span);
+      String remoteServiceName = adapter.remoteServiceName(message);
+      if (remoteServiceName != null) span.remoteServiceName(remoteServiceName);
+      span.start();
 
 Review comment:
   Elsewhere we've done: `span.start().finish();` though I'm not sure I like that pattern
a ton, since this will end up flushed anyway, maybe we should flush explictly

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@zipkin.apache.org
For additional commands, e-mail: dev-help@zipkin.apache.org


Mime
View raw message