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] adriancole commented on a change in pull request #917: Refactors to reduce injector complexity and duplicate code
Date Tue, 04 Jun 2019 01:26:06 GMT
adriancole 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_r290096602
 
 

 ##########
 File path: instrumentation/messaging/src/main/java/brave/messaging/ConsumerHandler.java
 ##########
 @@ -0,0 +1,143 @@
+/*
+ * 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.Tracing;
+import brave.internal.Nullable;
+import brave.propagation.TraceContext;
+import brave.propagation.TraceContextOrSamplingFlags;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @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 ConsumerHandler<Chan, Msg, C> {
+
+  public static <Chan, Msg, C> ConsumerHandler<Chan, Msg, C> create(
+    MessagingTracing messagingTracing,
+    MessagingAdapter<Chan, Msg, C> adapter,
+    TraceContext.Extractor<C> extractor,
+    TraceContext.Injector<C> injector
+  ) {
+    return new ConsumerHandler<>(messagingTracing, adapter, extractor, injector);
+  }
+
+  final Tracing tracing;
+  final TraceContext.Extractor<C> extractor;
+  final TraceContext.Injector<C> injector;
+  final MessagingParser parser;
+  final MessagingAdapter<Chan, Msg, C> adapter;
+
+  ConsumerHandler(MessagingTracing messagingTracing,
+    MessagingAdapter<Chan, Msg, C> adapter,
+    TraceContext.Extractor<C> extractor,
+    TraceContext.Injector<C> injector
+  ) {
+    this.tracing = messagingTracing.tracing;
+    this.extractor = extractor;
+    this.injector = injector;
+    this.parser = messagingTracing.parser;
+    this.adapter = adapter;
+  }
+
+  public void handleReceive(Chan channel, Msg message) {
+    if (message == null || tracing.isNoop()) return;
+    C carrier = adapter.carrier(message);
+    TraceContextOrSamplingFlags extracted = extractor.extract(carrier);
+    handleReceive(channel, message, carrier, adapter.brokerName(channel), extracted, false);
+  }
+
+  /** Returns a started processor span if {@code createProcessor} is true */
+  @Nullable Span handleReceive(Chan channel, Msg message, C carrier, String remoteServiceName,
+    TraceContextOrSamplingFlags extracted, boolean createProcessor) {
+    Span span = tracing.tracer().nextSpan(extracted);
+    // Creating the processor while the consumer is not finished ensures clocks are the same.
This
+    // allows the processor to start later, but not be subject to clock drift relative to
the parent.
+    Span processorSpan = createProcessor ? tracing.tracer().newChild(span.context()) : null;
+    if (!span.isNoop()) {
+      span.kind(Span.Kind.CONSUMER);
+      parser.start("receive", adapter, channel, message, span.context(), span.customizer());
 
 Review comment:
   I started with this, but stopped because type complexity and using an enum hints at a closed
amount of operations.. we could use this for other operations .. not sure yet really that's
why at least temporarily open (ex http.method is open)

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