Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OtelVersionClassPlugin instead of reading version from resource #5622

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions opencensus-shim/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import io.opentelemetry.gradle.OtelVersionClassPlugin

plugins {
id("otel.java-conventions")
id("otel.publish-conventions")
}
apply<OtelVersionClassPlugin>()

description = "OpenTelemetry OpenCensus Shim"
otelJava.moduleName.set("io.opentelemetry.opencensusshim")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -212,20 +211,6 @@ private static boolean isAnyParentLinkSampled(List<Span> 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;
Expand Down
3 changes: 3 additions & 0 deletions opentracing-shim/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import io.opentelemetry.gradle.OtelVersionClassPlugin

plugins {
id("otel.java-conventions")
id("otel.publish-conventions")
}
apply<OtelVersionClassPlugin>()

description = "OpenTelemetry OpenTracing Bridge"
otelJava.moduleName.set("io.opentelemetry.opentracingshim")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}