lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucene-solr] zsgyulavari commented on a change in pull request #685: SOLR-13434: OpenTracing support for Solr
Date Wed, 29 May 2019 09:33:01 GMT
zsgyulavari commented on a change in pull request #685: SOLR-13434: OpenTracing support for
Solr
URL: https://github.com/apache/lucene-solr/pull/685#discussion_r288477013
 
 

 ##########
 File path: solr/core/src/java/org/apache/solr/util/tracing/GlobalTracer.java
 ##########
 @@ -0,0 +1,82 @@
+/*
+ * 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 org.apache.solr.util.tracing;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Random;
+
+import io.opentracing.SpanContext;
+import io.opentracing.Tracer;
+import io.opentracing.noop.NoopTracerFactory;
+import io.opentracing.propagation.Format;
+
+public class GlobalTracer {
+  private static final Random RANDOM;
+  static {
+    // We try to make things reproducible in the context of our tests by initializing the
random instance
+    // based on the current seed
+    String seed = System.getProperty("tests.seed");
+    if (seed == null) {
+      RANDOM = new Random();
+    } else {
+      RANDOM = new Random(seed.hashCode());
+    }
+  }
+
+  private static final Tracer NOOP_TRACER = NoopTracerFactory.create();
+  private static volatile Tracer TRACER = NOOP_TRACER;
+  private static volatile int rate;
+  private final static ThreadLocal<Tracer> threadLocal = new ThreadLocal<>();
+
+  public static void setup(Tracer tracer, double rate) {
+    GlobalTracer.rate = (int) (rate * 10);
+    GlobalTracer.TRACER = tracer;
+  }
+
+  public static boolean tracing() {
+    return threadLocal.get() != null
+        && threadLocal.get() != NOOP_TRACER
+        && threadLocal.get().activeSpan() != null;
+  }
+
+  public static SpanContext extract(HttpServletRequest request) {
+    SpanContext spanContext = TRACER.extract(Format.Builtin.HTTP_HEADERS, new HttpServletCarrier(request));
+    if (spanContext != null) {
+      threadLocal.set(TRACER);
+    }
+    return spanContext;
+  }
+
+  public static Tracer get() {
+    Tracer tracer = threadLocal.get();
+    if (tracer != null)
+      return tracer;
+
+    if (traced()) {
 
 Review comment:
   When we're getting a request that is already sampled by the calling process we should continue
sampling it regardless of the sampling rate set here (failing to do so would result in incomplete
reports). I think that a sampling rate on its own is only half of the solution.
   
   If we hit a node and it distributes the tracing context but other nodes ignore it 99% of
the time we'd get only incomplete tracing data. That's why I would leave it to the implementor.
Dealing with the thread locals could also be spared.

----------------------------------------------------------------
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@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message