ctubbsii commented on a change in pull request #2259: URL: https://github.com/apache/accumulo/pull/2259#discussion_r718712370
########## 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: From what I can tell, the authors of OpenTelemetry don't really understand user configuration/bootstrapping very well, as they've not provided an easy mechanism to configure a specific implementation. They seem to have half of what is needed, but they didn't go far enough. I think that response about it being brittle is not correct. Yes, you can't force users to set it, but the whole point is that they *can* set it if they want to. This is where OpenTelemetry could have done a better job with configuration, so that they provide a mechanism to set it automatically outside of code. What is most important for our purposes is that the GlobalOpenTelemetry works out of the box as either a NOOP or an AutoConfiguration implementation, depending on the classpath, and that it is *possible* for an end user to do something to change it. We only need possible. That's not brittle... that's flexible... which is what we want for end users. -- 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]
