diff --git a/opencensus-shim/build.gradle.kts b/opencensus-shim/build.gradle.kts index 7d3b7e908ce..73873c453f6 100644 --- a/opencensus-shim/build.gradle.kts +++ b/opencensus-shim/build.gradle.kts @@ -1,7 +1,10 @@ +import io.opentelemetry.gradle.OtelVersionClassPlugin + plugins { id("otel.java-conventions") id("otel.publish-conventions") } +apply() description = "OpenTelemetry OpenCensus Shim" otelJava.moduleName.set("io.opentelemetry.opencensusshim") diff --git a/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/OpenTelemetrySpanBuilderImpl.java b/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/OpenTelemetrySpanBuilderImpl.java index 1bef8c686f1..bd09e9b66f1 100644 --- a/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/OpenTelemetrySpanBuilderImpl.java +++ b/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/OpenTelemetrySpanBuilderImpl.java @@ -41,18 +41,17 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.common.internal.OtelVersion; 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", OPENCENSUSSHIM_VERSION); + GlobalOpenTelemetry.getTracer("io.opentelemetry.opencensusshim", OtelVersion.VERSION); private static final Tracestate OC_TRACESTATE_DEFAULT = Tracestate.builder().build(); private static final TraceOptions OC_SAMPLED_TRACE_OPTIONS = TraceOptions.builder().setIsSampled(true).build(); @@ -212,20 +211,6 @@ private static boolean isAnyParentLinkSampled(List parentLinks) { 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; diff --git a/opentracing-shim/build.gradle.kts b/opentracing-shim/build.gradle.kts index 56dac7d0ce8..1f2363ac6f5 100644 --- a/opentracing-shim/build.gradle.kts +++ b/opentracing-shim/build.gradle.kts @@ -1,7 +1,10 @@ +import io.opentelemetry.gradle.OtelVersionClassPlugin + plugins { id("otel.java-conventions") id("otel.publish-conventions") } +apply() description = "OpenTelemetry OpenTracing Bridge" otelJava.moduleName.set("io.opentelemetry.opentracingshim") diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java index 4f83561bdfd..caec9b7c949 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.opentracing.shim.internal.OtelVersion; import io.opentracing.Scope; import io.opentracing.ScopeManager; import io.opentracing.Span; @@ -18,7 +19,6 @@ 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; @@ -27,8 +27,6 @@ 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; @@ -40,7 +38,7 @@ final class TracerShim implements Tracer { TextMapPropagator textMapPropagator, TextMapPropagator httpPropagator) { this.provider = provider; - this.tracer = provider.get("opentracing-shim", OPENTRACINGSHIM_VERSION); + this.tracer = provider.get("opentracing-shim", OtelVersion.VERSION); this.propagation = new Propagation(textMapPropagator, httpPropagator); this.scopeManagerShim = new ScopeManagerShim(); } @@ -150,18 +148,4 @@ private static TracerProvider maybeUnobfuscate(TracerProvider tracerProvider) { } 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; - } } diff --git a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java index 7a97055d80f..cfe4a066bbd 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.common.internal.OtelVersion; import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentracing.propagation.Format; import org.junit.jupiter.api.AfterEach; @@ -41,8 +42,7 @@ void createTracerShim_fromOpenTelemetryInstance() { .isSameAs(textMapPropagator); assertThat(tracerShim.propagation().getPropagator(Format.Builtin.HTTP_HEADERS)) .isSameAs(textMapPropagator); - assertThat(tracerShim.tracer()) - .isEqualTo(sdk.get("opentracing-shim", TracerShim.OPENTRACINGSHIM_VERSION)); + assertThat(tracerShim.tracer()).isEqualTo(sdk.get("opentracing-shim", OtelVersion.VERSION)); } @Test @@ -76,7 +76,6 @@ void createTracerShim_withTraceProviderAndPropagator() { .isSameAs(textMapPropagator); assertThat(tracerShim.propagation().getPropagator(Format.Builtin.HTTP_HEADERS)) .isSameAs(httpHeadersPropagator); - assertThat(tracerShim.tracer()) - .isSameAs(sdk.get("opentracing-shim", TracerShim.OPENTRACINGSHIM_VERSION)); + assertThat(tracerShim.tracer()).isSameAs(sdk.get("opentracing-shim", OtelVersion.VERSION)); } }