Skip to content

Commit

Permalink
Rename spi providers to match {}Provider name (#800)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Cristian Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jan 28, 2020
1 parent 48af226 commit d4cf312
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 66 deletions.
26 changes: 13 additions & 13 deletions api/src/main/java/io/opentelemetry/OpenTelemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager;
import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerProvider;
import io.opentelemetry.metrics.DefaultMeterRegistry;
import io.opentelemetry.metrics.DefaultMeterRegistryProvider;
import io.opentelemetry.metrics.DefaultMetricsProvider;
import io.opentelemetry.metrics.Meter;
import io.opentelemetry.metrics.MeterRegistry;
import io.opentelemetry.metrics.spi.MeterRegistryProvider;
import io.opentelemetry.metrics.spi.MetricsProvider;
import io.opentelemetry.trace.DefaultTraceProvider;
import io.opentelemetry.trace.DefaultTracerRegistry;
import io.opentelemetry.trace.DefaultTracerRegistryProvider;
import io.opentelemetry.trace.Tracer;
import io.opentelemetry.trace.TracerRegistry;
import io.opentelemetry.trace.spi.TracerRegistryProvider;
import io.opentelemetry.trace.spi.TraceProvider;
import java.util.ServiceLoader;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
Expand All @@ -40,7 +40,7 @@
* <p>The telemetry objects are lazy-loaded singletons resolved via {@link ServiceLoader} mechanism.
*
* @see TracerRegistry
* @see MeterRegistryProvider
* @see MetricsProvider
* @see CorrelationContextManagerProvider
*/
@ThreadSafe
Expand Down Expand Up @@ -102,17 +102,17 @@ private static OpenTelemetry getInstance() {
}

private OpenTelemetry() {
TracerRegistryProvider tracerRegistryProvider = loadSpi(TracerRegistryProvider.class);
TraceProvider traceProvider = loadSpi(TraceProvider.class);
this.tracerRegistry =
tracerRegistryProvider != null
? tracerRegistryProvider.create()
: DefaultTracerRegistryProvider.getInstance().create();
traceProvider != null
? traceProvider.create()
: DefaultTraceProvider.getInstance().create();

MeterRegistryProvider meterRegistryProvider = loadSpi(MeterRegistryProvider.class);
MetricsProvider metricsProvider = loadSpi(MetricsProvider.class);
meterRegistry =
meterRegistryProvider != null
? meterRegistryProvider.create()
: DefaultMeterRegistryProvider.getInstance().create();
metricsProvider != null
? metricsProvider.create()
: DefaultMetricsProvider.getInstance().create();
CorrelationContextManagerProvider contextManagerProvider =
loadSpi(CorrelationContextManagerProvider.class);
contextManager =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package io.opentelemetry.metrics;

import io.opentelemetry.metrics.spi.MeterRegistryProvider;
import io.opentelemetry.metrics.spi.MetricsProvider;

public class DefaultMeterRegistryProvider implements MeterRegistryProvider {
private static final MeterRegistryProvider instance = new DefaultMeterRegistryProvider();
public class DefaultMetricsProvider implements MetricsProvider {
private static final MetricsProvider instance = new DefaultMetricsProvider();

public static MeterRegistryProvider getInstance() {
public static MetricsProvider getInstance() {
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @see io.opentelemetry.OpenTelemetry
*/
@ThreadSafe
public interface MeterRegistryProvider {
public interface MetricsProvider {

/**
* Creates a new meter registry instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package io.opentelemetry.trace;

import io.opentelemetry.trace.spi.TracerRegistryProvider;
import io.opentelemetry.trace.spi.TraceProvider;

public class DefaultTracerRegistryProvider implements TracerRegistryProvider {
private static final TracerRegistryProvider instance = new DefaultTracerRegistryProvider();
public class DefaultTraceProvider implements TraceProvider {
private static final TraceProvider instance = new DefaultTraceProvider();

public static TracerRegistryProvider getInstance() {
public static TraceProvider getInstance() {
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @see io.opentelemetry.OpenTelemetry
*/
@ThreadSafe
public interface TracerRegistryProvider {
public interface TraceProvider {

/**
* Creates a new TracerRegistry.
Expand Down
64 changes: 30 additions & 34 deletions api/src/test/java/io/opentelemetry/OpenTelemetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
import io.opentelemetry.metrics.LongObserver;
import io.opentelemetry.metrics.Meter;
import io.opentelemetry.metrics.MeterRegistry;
import io.opentelemetry.metrics.spi.MeterRegistryProvider;
import io.opentelemetry.metrics.spi.MetricsProvider;
import io.opentelemetry.trace.DefaultTracer;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.SpanContext;
import io.opentelemetry.trace.Tracer;
import io.opentelemetry.trace.TracerRegistry;
import io.opentelemetry.trace.spi.TracerRegistryProvider;
import io.opentelemetry.trace.spi.TraceProvider;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
Expand Down Expand Up @@ -75,8 +75,8 @@ public static void beforeClass() {
@After
public void after() {
OpenTelemetry.reset();
System.clearProperty(TracerRegistryProvider.class.getName());
System.clearProperty(MeterRegistryProvider.class.getName());
System.clearProperty(TraceProvider.class.getName());
System.clearProperty(MetricsProvider.class.getName());
System.clearProperty(CorrelationContextManagerProvider.class.getName());
}

Expand All @@ -98,12 +98,11 @@ public void testDefault() {
@Test
public void testTracerLoadArbitrary() throws IOException {
File serviceFile =
createService(
TracerRegistryProvider.class, FirstTracerRegistry.class, SecondTracerRegistry.class);
createService(TraceProvider.class, FirstTraceProvider.class, SecondTraceProvider.class);
try {
assertTrue(
(OpenTelemetry.getTracerRegistry() instanceof FirstTracerRegistry)
|| (OpenTelemetry.getTracerRegistry() instanceof SecondTracerRegistry));
(OpenTelemetry.getTracerRegistry() instanceof FirstTraceProvider)
|| (OpenTelemetry.getTracerRegistry() instanceof SecondTraceProvider));
} finally {
serviceFile.delete();
}
Expand All @@ -112,20 +111,18 @@ public void testTracerLoadArbitrary() throws IOException {
@Test
public void testTracerSystemProperty() throws IOException {
File serviceFile =
createService(
TracerRegistryProvider.class, FirstTracerRegistry.class, SecondTracerRegistry.class);
System.setProperty(
TracerRegistryProvider.class.getName(), SecondTracerRegistry.class.getName());
createService(TraceProvider.class, FirstTraceProvider.class, SecondTraceProvider.class);
System.setProperty(TraceProvider.class.getName(), SecondTraceProvider.class.getName());
try {
assertThat(OpenTelemetry.getTracerRegistry()).isInstanceOf(SecondTracerRegistry.class);
assertThat(OpenTelemetry.getTracerRegistry()).isInstanceOf(SecondTraceProvider.class);
} finally {
serviceFile.delete();
}
}

@Test
public void testTracerNotFound() {
System.setProperty(TracerRegistryProvider.class.getName(), "io.does.not.exists");
System.setProperty(TraceProvider.class.getName(), "io.does.not.exists");
thrown.expect(IllegalStateException.class);
OpenTelemetry.getTracerRegistry().get("testTracer");
}
Expand All @@ -134,11 +131,11 @@ public void testTracerNotFound() {
public void testMeterLoadArbitrary() throws IOException {
File serviceFile =
createService(
MeterRegistryProvider.class, FirstMeterRegistry.class, SecondMeterRegistry.class);
MetricsProvider.class, FirstMetricsProvider.class, SecondMetricsProvider.class);
try {
assertTrue(
(OpenTelemetry.getMeterRegistry() instanceof FirstMeterRegistry)
|| (OpenTelemetry.getMeterRegistry() instanceof SecondMeterRegistry));
(OpenTelemetry.getMeterRegistry() instanceof FirstMetricsProvider)
|| (OpenTelemetry.getMeterRegistry() instanceof SecondMetricsProvider));
assertThat(OpenTelemetry.getMeterRegistry()).isEqualTo(OpenTelemetry.getMeterRegistry());
} finally {
serviceFile.delete();
Expand All @@ -149,10 +146,10 @@ public void testMeterLoadArbitrary() throws IOException {
public void testMeterSystemProperty() throws IOException {
File serviceFile =
createService(
MeterRegistryProvider.class, FirstMeterRegistry.class, SecondMeterRegistry.class);
System.setProperty(MeterRegistryProvider.class.getName(), SecondMeterRegistry.class.getName());
MetricsProvider.class, FirstMetricsProvider.class, SecondMetricsProvider.class);
System.setProperty(MetricsProvider.class.getName(), SecondMetricsProvider.class.getName());
try {
assertThat(OpenTelemetry.getMeterRegistry()).isInstanceOf(SecondMeterRegistry.class);
assertThat(OpenTelemetry.getMeterRegistry()).isInstanceOf(SecondMetricsProvider.class);
assertThat(OpenTelemetry.getMeterRegistry()).isEqualTo(OpenTelemetry.getMeterRegistry());
} finally {
serviceFile.delete();
Expand All @@ -161,7 +158,7 @@ public void testMeterSystemProperty() throws IOException {

@Test
public void testMeterNotFound() {
System.setProperty(MeterRegistryProvider.class.getName(), "io.does.not.exists");
System.setProperty(MetricsProvider.class.getName(), "io.does.not.exists");
thrown.expect(IllegalStateException.class);
OpenTelemetry.getMeterRegistry();
}
Expand Down Expand Up @@ -227,10 +224,10 @@ private static File createService(Class<?> service, Class<?>... impls) throws IO
return file;
}

public static class SecondTracerRegistry extends FirstTracerRegistry {
public static class SecondTraceProvider extends FirstTraceProvider {
@Override
public Tracer get(String instrumentationName) {
return new SecondTracerRegistry();
return new SecondTraceProvider();
}

@Override
Expand All @@ -240,15 +237,14 @@ public Tracer get(String instrumentationName, String instrumentationVersion) {

@Override
public TracerRegistry create() {
return new SecondTracerRegistry();
return new SecondTraceProvider();
}
}

public static class FirstTracerRegistry
implements Tracer, TracerRegistry, TracerRegistryProvider {
public static class FirstTraceProvider implements Tracer, TracerRegistry, TraceProvider {
@Override
public Tracer get(String instrumentationName) {
return new FirstTracerRegistry();
return new FirstTraceProvider();
}

@Override
Expand Down Expand Up @@ -288,14 +284,14 @@ public HttpTextFormat<SpanContext> getHttpTextFormat() {

@Override
public TracerRegistry create() {
return new FirstTracerRegistry();
return new FirstTraceProvider();
}
}

public static class SecondMeterRegistry extends FirstMeterRegistry {
public static class SecondMetricsProvider extends FirstMetricsProvider {
@Override
public Meter get(String instrumentationName) {
return new SecondMeterRegistry();
return new SecondMetricsProvider();
}

@Override
Expand All @@ -305,14 +301,14 @@ public Meter get(String instrumentationName, String instrumentationVersion) {

@Override
public MeterRegistry create() {
return new SecondMeterRegistry();
return new SecondMetricsProvider();
}
}

public static class FirstMeterRegistry implements Meter, MeterRegistryProvider, MeterRegistry {
public static class FirstMetricsProvider implements Meter, MetricsProvider, MeterRegistry {
@Override
public MeterRegistry create() {
return new FirstMeterRegistry();
return new FirstMetricsProvider();
}

@Nullable
Expand Down Expand Up @@ -383,7 +379,7 @@ public LabelSet createLabelSet(@Nonnull Map<String, String> labels) {

@Override
public Meter get(String instrumentationName) {
return new FirstMeterRegistry();
return new FirstMetricsProvider();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.MeterRegistry;
import io.opentelemetry.metrics.spi.MeterRegistryProvider;
import io.opentelemetry.metrics.spi.MetricsProvider;

/**
* {@code MeterRegistry} provider implementation for {@link MeterRegistryProvider}.
* {@code MeterRegistry} provider implementation for {@link MetricsProvider}.
*
* <p>This class is not intended to be used in application code and it is used only by {@link
* io.opentelemetry.OpenTelemetry}.
*/
public class MeterSdkRegistryProvider implements MeterRegistryProvider {
public class SdkMetricsProvider implements MetricsProvider {

@Override
public MeterRegistry create() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package io.opentelemetry.sdk.trace;

import io.opentelemetry.trace.TracerRegistry;
import io.opentelemetry.trace.spi.TracerRegistryProvider;
import io.opentelemetry.trace.spi.TraceProvider;

/** SDK implementation of the TracerProviderFactory for SPI. */
public class TracerSdkRegistryProvider implements TracerRegistryProvider {
public class SdkTraceProvider implements TraceProvider {
@Override
public TracerRegistry create() {
return TracerSdkRegistry.builder().build();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.opentelemetry.sdk.metrics.SdkMetricsProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.opentelemetry.sdk.trace.SdkTraceProvider

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class MeterSdkProviderTest {

@Test
public void testDefault() {
assertThat(new MeterSdkRegistryProvider().create()).isInstanceOf(MeterSdkRegistry.class);
assertThat(new SdkMetricsProvider().create()).isInstanceOf(MeterSdkRegistry.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@RunWith(JUnit4.class)
public class TracerSdkProviderTest {
private final TracerSdkRegistryProvider tracerFactoryProvider = new TracerSdkRegistryProvider();
private final SdkTraceProvider tracerFactoryProvider = new SdkTraceProvider();

@Test
public void testDefault() {
Expand Down

0 comments on commit d4cf312

Please sign in to comment.