Adds version to otel tracer instrumentation scope (#5336)
* Adds version to otel tracer instrumentation scope * spotless * while I'm here * fix tests * spotless * use version properties
This commit is contained in:
parent
8e3c29538f
commit
9bd1a5198c
|
|
@ -44,12 +44,15 @@ import io.opentelemetry.context.Context;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
class OpenTelemetrySpanBuilderImpl extends SpanBuilder {
|
||||
|
||||
private static final String OPENCENSUSSHIM_VERSION = readVersion();
|
||||
private static final Tracer OTEL_TRACER =
|
||||
GlobalOpenTelemetry.getTracer("io.opentelemetry.opencensusshim");
|
||||
GlobalOpenTelemetry.getTracer("io.opentelemetry.opencensusshim", OPENCENSUSSHIM_VERSION);
|
||||
private static final Tracestate OC_TRACESTATE_DEFAULT = Tracestate.builder().build();
|
||||
private static final TraceOptions OC_SAMPLED_TRACE_OPTIONS =
|
||||
TraceOptions.builder().setIsSampled(true).build();
|
||||
|
|
@ -209,6 +212,20 @@ class OpenTelemetrySpanBuilderImpl extends SpanBuilder {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static String readVersion() {
|
||||
Properties properties = new Properties();
|
||||
String version;
|
||||
try {
|
||||
properties.load(
|
||||
OpenTelemetrySpanBuilderImpl.class.getResourceAsStream(
|
||||
"/io/opentelemetry/opencensusshim/version.properties"));
|
||||
version = properties.getProperty("sdk.version", "unknown");
|
||||
} catch (Exception e) {
|
||||
version = "unknown";
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
static final class Options {
|
||||
private final RandomHandler randomHandler;
|
||||
private final TraceConfig traceConfig;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import io.opentracing.propagation.TextMapInject;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -26,6 +27,8 @@ import javax.annotation.Nullable;
|
|||
final class TracerShim implements Tracer {
|
||||
private static final Logger logger = Logger.getLogger(TracerShim.class.getName());
|
||||
|
||||
static final String OPENTRACINGSHIM_VERSION = readVersion();
|
||||
|
||||
private final io.opentelemetry.api.trace.TracerProvider provider;
|
||||
private final io.opentelemetry.api.trace.Tracer tracer;
|
||||
private final ScopeManager scopeManagerShim;
|
||||
|
|
@ -37,7 +40,7 @@ final class TracerShim implements Tracer {
|
|||
TextMapPropagator textMapPropagator,
|
||||
TextMapPropagator httpPropagator) {
|
||||
this.provider = provider;
|
||||
this.tracer = provider.get("opentracing-shim");
|
||||
this.tracer = provider.get("opentracing-shim", OPENTRACINGSHIM_VERSION);
|
||||
this.propagation = new Propagation(textMapPropagator, httpPropagator);
|
||||
this.scopeManagerShim = new ScopeManagerShim();
|
||||
}
|
||||
|
|
@ -147,4 +150,18 @@ final class TracerShim implements Tracer {
|
|||
}
|
||||
return tracerProvider;
|
||||
}
|
||||
|
||||
private static String readVersion() {
|
||||
Properties properties = new Properties();
|
||||
String version;
|
||||
try {
|
||||
properties.load(
|
||||
TracerShim.class.getResourceAsStream(
|
||||
"/io/opentelemetry/opentracingshim/version.properties"));
|
||||
version = properties.getProperty("sdk.version", "unknown");
|
||||
} catch (Exception e) {
|
||||
version = "unknown";
|
||||
}
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class OpenTracingShimTest {
|
|||
.isSameAs(textMapPropagator);
|
||||
assertThat(tracerShim.propagation().getPropagator(Format.Builtin.HTTP_HEADERS))
|
||||
.isSameAs(textMapPropagator);
|
||||
assertThat(tracerShim.tracer()).isEqualTo(sdk.get("opentracing-shim"));
|
||||
assertThat(tracerShim.tracer())
|
||||
.isEqualTo(sdk.get("opentracing-shim", TracerShim.OPENTRACINGSHIM_VERSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -75,6 +76,7 @@ class OpenTracingShimTest {
|
|||
.isSameAs(textMapPropagator);
|
||||
assertThat(tracerShim.propagation().getPropagator(Format.Builtin.HTTP_HEADERS))
|
||||
.isSameAs(httpHeadersPropagator);
|
||||
assertThat(tracerShim.tracer()).isSameAs(sdk.get("opentracing-shim"));
|
||||
assertThat(tracerShim.tracer())
|
||||
.isSameAs(sdk.get("opentracing-shim", TracerShim.OPENTRACINGSHIM_VERSION));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue