Skip to content

Commit

Permalink
remove convenience tracer methods from the OpenTelemetry class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwatson committed Oct 14, 2019
1 parent 5eb4656 commit b959240
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
24 changes: 7 additions & 17 deletions api/src/main/java/io/opentelemetry/OpenTelemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.opentelemetry.metrics.DefaultMeter;
import io.opentelemetry.metrics.Meter;
import io.opentelemetry.metrics.spi.MeterProvider;
import io.opentelemetry.trace.DefaultTracer;
import io.opentelemetry.trace.DefaultTracerFactory;
import io.opentelemetry.trace.DefaultTracerFactoryProvider;
import io.opentelemetry.trace.Tracer;
import io.opentelemetry.trace.TracerFactory;
Expand Down Expand Up @@ -51,25 +51,15 @@ public final class OpenTelemetry {
private final DistributedContextManager contextManager;

/**
* Returns a singleton {@link Tracer}.
* Returns a singleton {@link TracerFactory}.
*
* @return registered tracer or default via {@link DefaultTracer#getInstance()}.
* @throws IllegalStateException if a specified tracer (via system properties) could not be found.
* @since 0.1.0
*/
public static Tracer getTracer() {
return getTracer("defaultInstrumentationName", "defaultInstrumentationVersion");
}

/**
* Returns a named {@link Tracer} with the provided instrumentation name and version.
*
* @return registered tracer or default via {@link DefaultTracer#getInstance()}.
* @throws IllegalStateException if a specified tracer (via system properties) could not be found.
* @return registered TracerFactory of default via {@link DefaultTracerFactory#getInstance()}.
* @throws IllegalStateException if a specified TracerFactory (via system properties) could not be
* found.
* @since 0.1.0
*/
public static Tracer getTracer(String instrumentationName, String instrumentationVersion) {
return getInstance().tracerFactory.get(instrumentationName, instrumentationVersion);
public static TracerFactory getTracerFactory() {
return getInstance().tracerFactory;
}

/**
Expand Down
14 changes: 8 additions & 6 deletions api/src/test/java/io/opentelemetry/OpenTelemetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public void after() {

@Test
public void testDefault() {
assertThat(OpenTelemetry.getTracer()).isInstanceOf(DefaultTracer.getInstance().getClass());
assertThat(OpenTelemetry.getTracer()).isEqualTo(OpenTelemetry.getTracer());
assertThat(OpenTelemetry.getTracerFactory().get("testTracer"))
.isInstanceOf(DefaultTracer.getInstance().getClass());
assertThat(OpenTelemetry.getTracerFactory().get("testTracer"))
.isEqualTo(OpenTelemetry.getTracerFactory().get("testTracer"));
assertThat(OpenTelemetry.getMeter()).isInstanceOf(DefaultMeter.getInstance().getClass());
assertThat(OpenTelemetry.getMeter()).isEqualTo(OpenTelemetry.getMeter());
assertThat(OpenTelemetry.getDistributedContextManager())
Expand All @@ -95,8 +97,8 @@ public void testTracerLoadArbitrary() throws IOException {
TracerFactoryProvider.class, FirstTracerFactory.class, SecondTracerFactory.class);
try {
assertTrue(
(OpenTelemetry.getTracer() instanceof FirstTracerFactory)
|| (OpenTelemetry.getTracer() instanceof SecondTracerFactory));
(OpenTelemetry.getTracerFactory() instanceof FirstTracerFactory)
|| (OpenTelemetry.getTracerFactory() instanceof SecondTracerFactory));
} finally {
serviceFile.delete();
}
Expand All @@ -109,7 +111,7 @@ public void testTracerSystemProperty() throws IOException {
TracerFactoryProvider.class, FirstTracerFactory.class, SecondTracerFactory.class);
System.setProperty(TracerFactoryProvider.class.getName(), SecondTracerFactory.class.getName());
try {
assertThat(OpenTelemetry.getTracer()).isInstanceOf(SecondTracerFactory.class);
assertThat(OpenTelemetry.getTracerFactory()).isInstanceOf(SecondTracerFactory.class);
} finally {
serviceFile.delete();
}
Expand All @@ -119,7 +121,7 @@ public void testTracerSystemProperty() throws IOException {
public void testTracerNotFound() {
System.setProperty(TracerFactoryProvider.class.getName(), "io.does.not.exists");
thrown.expect(IllegalStateException.class);
OpenTelemetry.getTracer();
OpenTelemetry.getTracerFactory().get("testTracer");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ private TraceShim() {}
*/
public static io.opentracing.Tracer createTracerShim() {
return new TracerShim(
new TelemetryInfo(OpenTelemetry.getTracer(), OpenTelemetry.getDistributedContextManager()));
new TelemetryInfo(
OpenTelemetry.getTracerFactory().get("openTracingShim"),
OpenTelemetry.getDistributedContextManager()));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions sdk/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.sdk.distributedcontext.DistributedContextManagerSdk;
import io.opentelemetry.sdk.metrics.MeterSdk;
import io.opentelemetry.sdk.trace.TracerSdk;
import io.opentelemetry.sdk.trace.TracerSdkFactory;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand All @@ -34,13 +35,13 @@
@ThreadSafe
public final class OpenTelemetrySdk {
/**
* Returns a {@link TracerSdk}.
* Returns a {@link TracerSdkFactory}.
*
* @return tracer returned by {@link OpenTelemetry#getTracer()}.
* @return TracerFactory returned by {@link OpenTelemetry#getTracerFactory()}.
* @since 0.1.0
*/
public static TracerSdk getTracer() {
return (TracerSdk) OpenTelemetry.getTracer();
public static TracerSdkFactory getTracerFactory() {
return (TracerSdkFactory) OpenTelemetry.getTracerFactory();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class OpenTelemetrySdkTest {

@Test
public void testDefault() {
assertThat(OpenTelemetrySdk.getTracer()).isSameInstanceAs(OpenTelemetry.getTracer());
assertThat(OpenTelemetrySdk.getTracerFactory())
.isSameInstanceAs(OpenTelemetry.getTracerFactory());
assertThat(OpenTelemetrySdk.getDistributedContextManager())
.isSameInstanceAs(OpenTelemetry.getDistributedContextManager());
assertThat(OpenTelemetrySdk.getMeter()).isSameInstanceAs(OpenTelemetry.getMeter());
Expand Down

0 comments on commit b959240

Please sign in to comment.