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


##########
solr/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/CustomTestOtelTracerConfigurator.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.opentelemetry;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
+import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
+import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
+import org.apache.solr.common.util.NamedList;
+
+public class CustomTestOtelTracerConfigurator extends OtelTracerConfigurator {
+
+  static {
+    if (System.getProperty("host") == null) {
+      System.setProperty("host", "localhost");
+    }
+  }
+
+  private static final InMemorySpanExporter exporter = 
InMemorySpanExporter.create();

Review Comment:
   yes the error is strange. I don't think the exported is the cause but I 
added shutdown to it, it was a good suggestion (I think this gets closed via 
the otel sdk clode method).
   the issue seems to be some component calls GlobalOpenTelemetry.get() before 
the actual init happens (as an aside this is a very strange design decision on 
otel side: calling GlobalOpenTelemetry.get() will actually _set_ it to noop and 
will not allow anyone else to set it again hence the failure in the logs). I am 
also considering the test itself as a culprit (it does a call to .get() to 
verify otel is active). still massaging the test code to make it into a test 
failure instead of a crash-like situation.
   
   ```
   Caused by: java.lang.IllegalStateException: GlobalOpenTelemetry.set has 
already been called. GlobalOpenTelemetry.set must be called only once before 
any calls to GlobalOpenTelemetry.get. If you are using the OpenTelemetrySdk, 
use OpenTelemetrySdkBuilder.buildAndRegisterGlobal instead. Previous invocation 
set to cause of this exception.
     2>    at 
io.opentelemetry.api.GlobalOpenTelemetry.set(GlobalOpenTelemetry.java:104) 
~[opentelemetry-api-1.28.0.jar:1.28.0]
     2>    at 
io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:401)
 ~[opentelemetry-sdk-extension-autoconfigure-1.28.0.jar:1.28.0]
     2>    ... 21 more
   ```
   
   



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