janhoy commented on code in PR #1841:
URL: https://github.com/apache/solr/pull/1841#discussion_r1294442984


##########
solr/modules/opentelemetry/src/java/org/apache/solr/opentelemetry/OtelTracerConfigurator.java:
##########
@@ -16,38 +16,56 @@
  */
 package org.apache.solr.opentelemetry;
 
-import io.opentelemetry.opentracingshim.OpenTracingShim;
-import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.trace.Tracer;
 import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
-import io.opentracing.Tracer;
 import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
+import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.TracerConfigurator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * OpenTracing TracerConfigurator implementation which exports spans to 
OpenTelemetry in OTLP
- * format. This impl re-uses the existing OpenTracing instrumentation through 
a shim, and takes care
- * of properly closing the backing Tracer when Solr shuts down.
+ * Tracing TracerConfigurator implementation which exports spans to 
OpenTelemetry in OTLP format.
  */
 public class OtelTracerConfigurator extends TracerConfigurator {
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-  // Copy of environment. Can be overridden by tests
-  Map<String, String> currentEnv = System.getenv();
+
+  private final Map<String, String> currentEnv;
+
+  public OtelTracerConfigurator() {
+    this(System.getenv());
+  }
+
+  OtelTracerConfigurator(Map<String, String> currentEnv) {
+    this.currentEnv = currentEnv;
+  }
 
   @Override
   public Tracer getTracer() {
+    // TODO remove reliance on global
+    return GlobalOpenTelemetry.getTracer("solr");
+  }
+
+  @Override
+  public void init(NamedList<?> args) {
+    prepareConfiguration();
+    AutoConfiguredOpenTelemetrySdk.initialize();
+  }
+
+  void prepareConfiguration() {
     setDefaultIfNotConfigured("OTEL_SERVICE_NAME", "solr");
     setDefaultIfNotConfigured("OTEL_TRACES_EXPORTER", "otlp");
     setDefaultIfNotConfigured("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc");
     setDefaultIfNotConfigured("OTEL_TRACES_SAMPLER", "parentbased_always_on");
-    addOtelResourceAttributes(Map.of("host.name", System.getProperty("host")));
+    setDefaultIfNotConfigured("OTEL_PROPAGATORS", "tracecontext,baggage");
+    addOtelResourceAttributes(Map.of("host.name", System.getProperty("host", 
"localhost")));

Review Comment:
   Why localhost here? All validly started Solr instances will have the `host` 
sysprop set?



##########
solr/core/src/java/org/apache/solr/api/AnnotatedApi.java:
##########
@@ -215,7 +214,6 @@ public void call(SolrQueryRequest req, SolrQueryResponse 
rsp) {
     }
 
     for (CommandOperation cmd : cmds) {
-      TraceUtils.ifNotNoop(req.getSpan(), (span) -> span.log("Command: " + 
cmd.name));

Review Comment:
   Why is this removed?



##########
solr/modules/opentelemetry/src/java/org/apache/solr/opentelemetry/OtelTracerConfigurator.java:
##########
@@ -16,38 +16,56 @@
  */
 package org.apache.solr.opentelemetry;
 
-import io.opentelemetry.opentracingshim.OpenTracingShim;
-import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.trace.Tracer;
 import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
-import io.opentracing.Tracer;
 import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
+import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.TracerConfigurator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * OpenTracing TracerConfigurator implementation which exports spans to 
OpenTelemetry in OTLP
- * format. This impl re-uses the existing OpenTracing instrumentation through 
a shim, and takes care
- * of properly closing the backing Tracer when Solr shuts down.
+ * Tracing TracerConfigurator implementation which exports spans to 
OpenTelemetry in OTLP format.
  */
 public class OtelTracerConfigurator extends TracerConfigurator {
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-  // Copy of environment. Can be overridden by tests
-  Map<String, String> currentEnv = System.getenv();
+
+  private final Map<String, String> currentEnv;
+
+  public OtelTracerConfigurator() {
+    this(System.getenv());
+  }
+
+  OtelTracerConfigurator(Map<String, String> currentEnv) {
+    this.currentEnv = currentEnv;
+  }
 
   @Override
   public Tracer getTracer() {
+    // TODO remove reliance on global
+    return GlobalOpenTelemetry.getTracer("solr");
+  }
+
+  @Override
+  public void init(NamedList<?> args) {

Review Comment:
   This is only called if there is a `<tracerConfig` tag in solrconfig.xml, 
right?
   In 
https://issues.apache.org/jira/browse/SOLR-16536?focusedCommentId=17655736&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17655736
 I coin the idea of getting rid of TracerConfigurator altogether, and instead 
initialize the tracer in static context here in the `opentelemetry` module. 
WDYT?



##########
solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java:
##########
@@ -977,15 +979,32 @@ protected void writeResponse(
       }
 
       if (Method.HEAD != reqMethod) {
-        OutputStream out = response.getOutputStream();
-        QueryResponseWriterUtil.writeQueryResponse(out, responseWriter, 
solrReq, solrRsp, ct);
+        writeQueryResponseWithTracing(responseWriter, solrRsp, ct);

Review Comment:
   Is this `writeQueryResponse` a new span that we did not record before?



##########
solr/core/src/java/org/apache/solr/api/V2HttpCall.java:
##########
@@ -510,18 +507,21 @@ protected void populateTracingSpan(Span span) {
     // if this api has commands ...
     final Map<String, JsonSchemaValidator> validators = getValidators(); // 
should be cached
     if (validators != null && validators.isEmpty() == false && solrReq != 
null) {
-      boolean validateInput = true; // because getCommands caches it; and we 
want it validated later
+      //      boolean validateInput = true; // because getCommands caches it; 
and we want it
+      // validated later
       // does this request have one command?
-      List<CommandOperation> cmds = solrReq.getCommands(validateInput);
-      if (cmds.size() == 1) {
-        verb = cmds.get(0).name;
-      }
+      // this can clash with other calls to read commands via 
CommandOperation.readCommands
+      // see 
"org.apache.solr.security.jwt.JWTAuthPluginIntegrationTest.testMetrics"
+      //   List<CommandOperation> cmds = solrReq.getCommands(validateInput);
+      //      if (cmds.size() == 1) {
+      //        verb = cmds.get(0).name;
+      //      }

Review Comment:
   Can you explain the clash?



##########
solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java:
##########
@@ -241,6 +243,18 @@ public void handleRequest(SolrQueryRequest req, 
SolrQueryResponse rsp) {
     }
   }
 
+  private void handleRequestBodyWithTracing(SolrQueryRequest req, 
SolrQueryResponse rsp)

Review Comment:
   Why is this handled differently form opentracing? How was the span started 
earlier?



##########
solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java:
##########
@@ -255,15 +247,12 @@ private void dispatch(
       Action result = call.call();
       switch (result) {
         case PASSTHROUGH:
-          getSpan(request).log("SolrDispatchFilter PASSTHROUGH");

Review Comment:
   Not sure what this log call did, are we removing something from the trace 
here that we had before?



##########
solr/core/src/java/org/apache/solr/core/TracerConfigurator.java:
##########
@@ -17,83 +17,88 @@
 
 package org.apache.solr.core;
 
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.Tracer;
-import io.opentracing.util.GlobalTracer;
-import java.lang.invoke.MethodHandles;
-import java.util.concurrent.atomic.AtomicReference;
-import org.apache.solr.common.util.ExecutorUtil;
+import io.opentelemetry.api.trace.Tracer;
 import org.apache.solr.util.plugin.NamedListInitializedPlugin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.solr.util.tracing.TraceUtils;
 
-/** Produces an OpenTracing {@link Tracer} from configuration. */
+/** Produces a {@link Tracer} from configuration. */
 public abstract class TracerConfigurator implements NamedListInitializedPlugin 
{

Review Comment:
   See comment elsewhere - can we get away with this entire plugin class, and 
remove the need for `<tracerConfig` in solr.xml to configure tracing? Since 
this will be a Solr 10 PR this breaking change is ok.



##########
solr/core/src/java/org/apache/solr/util/tracing/HttpServletRequestGetter.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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 io.opentelemetry.context.propagation.TextMapGetter;
+import java.util.Iterator;
+import javax.servlet.http.HttpServletRequest;
+
+public class HttpServletRequestGetter implements 
TextMapGetter<HttpServletRequest> {

Review Comment:
   JavaDoc on class



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

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to