ctubbsii commented on a change in pull request #2259:
URL: https://github.com/apache/accumulo/pull/2259#discussion_r717152559



##########
File path: 
server/tracer/src/main/java/org/apache/accumulo/tracer/DefaultTracerProvider.java
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.accumulo.tracer;
+
+import org.apache.accumulo.core.trace.TracerProvider;
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.auto.service.AutoService;
+
+import io.opentelemetry.api.OpenTelemetry;
+import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.sdk.autoconfigure.OpenTelemetrySdkAutoConfiguration;
+
+@AutoService(TracerProvider.class)
+public class DefaultTracerProvider implements TracerProvider {
+
+  @Override
+  public Tracer getTracer() {
+    // Set the service name if not set
+    String svcNameEnvVar = System.getenv("OTEL_SERVICE_NAME");
+    String svcNameProp = System.getenv("otel.service.name");
+    String appName = System.getProperty("accumulo.application"); // set in 
accumulo-env.sh
+    if (StringUtils.isEmpty(svcNameEnvVar) && StringUtils.isEmpty(svcNameProp)
+        && !StringUtils.isEmpty(appName)) {
+      System.setProperty("otel.service.name", appName);
+    }
+    // Configures a global OpenTelemetry object that can be configured using
+    // the instructions at
+    // 
https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure
+    OpenTelemetry otel = OpenTelemetrySdkAutoConfiguration.initialize();
+    return otel.getTracer(INSTRUMENTATION_NAME);

Review comment:
       Calling `GlobalOpenTelemetry.get()` gets us either the 
`OpenTelemetrySdkAutoConfiguration` implementation or the NOOP implementation. 
Even without providing some other mechanism to specify a different 
implementation, I think a user could still use a Java Agent to register a 
global implementation with `GlobalOpenTelemetry.set()`. If I'm right, we 
wouldn't even need to provide any configuration options to specify the 
implementation. But, loading a factory that is configured explicitly by us or 
discovered by the service loader is probably more convenient for most users. On 
the other hand, few will want to diverge from the autoconfigure implementation, 
and those that do may find writing a Java Agent to set the global 
implementation a small inconvenience.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to