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] jeqo commented on a change in pull request #917: Refactors to reduce injector complexity and duplicate code
Date Mon, 03 Jun 2019 22:37:00 GMT
jeqo commented on a change in pull request #917: Refactors to reduce injector complexity and
duplicate code
URL: https://github.com/apache/incubator-zipkin-brave/pull/917#discussion_r290064917
 
 

 ##########
 File path: instrumentation/messaging/src/main/java/brave/messaging/ProcessorHandler.java
 ##########
 @@ -0,0 +1,71 @@
+/*
+ * 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 brave.messaging;
+
+import brave.Span;
+import brave.Tracer;
+import brave.internal.Nullable;
+
+/**
+ * @param <Chan> the type of the channel
+ * @param <Msg> the type of the message
+ * @param <C> the type that carriers the trace context, usually headers
+ */
+public final class ProcessorHandler<Chan, Msg, C> {
+  public static <Chan, Msg, C> ProcessorHandler<Chan, Msg, C> create(
+    MessagingTracing messagingTracing,
+    ConsumerHandler<Chan, Msg, C> consumerHandler
+  ) {
+    return new ProcessorHandler<>(messagingTracing, consumerHandler);
+  }
+
+  final Tracer tracer;
+  final ConsumerHandler<Chan, Msg, C> consumerHandler;
+  final MessagingAdapter<Chan, Msg, C> adapter;
+
+  ProcessorHandler(MessagingTracing messagingTracing,
+    ConsumerHandler<Chan, Msg, C> consumerHandler) {
+    this.tracer = messagingTracing.tracing.tracer();
+    this.consumerHandler = consumerHandler;
+    this.adapter = consumerHandler.adapter;
+  }
+
+  /**
+   * When {@code addConsumerSpan} is true, this creates 2 spans:
+   * <ol>
+   * <li>A duration 1 {@link Span.Kind#CONSUMER} span to represent receipt from the
+   * destination</li>
+   * <li>A child span with the duration of the delegated listener</li>
+   * </ol>
+   *
+   * <p>{@code addConsumerSpan} should only be set when the message consumer is not
traced.
+   */
+  // channel is nullable as JMS could have an exception getting it from the message
+  public Span startProcessor(@Nullable Chan channel, Msg message, boolean addConsumerSpan)
{
+    if (!addConsumerSpan) {
+      Span result = tracer.nextSpan().start();
 
 Review comment:
   Should we extract context from carrier before creating this span? If not, child span does
not have a parent unless we create one before calling `nextSpan`

----------------------------------------------------------------
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