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

Rename spi providers to match {$PACKAGE}Provider name #800

Merged
merged 1 commit into from
Jan 28, 2020
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about TracerProvider, since this provides tracers, not traces?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to use the name of the package with the idea that it provides the implementation of the whole package. Maybe we rename the whole package to traces (separate PR maybe)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about "tracing", then? And, yes, a follow-up PR would be fine.
So, we have the package io.opentelemetry.tracing... and TracingProvider. I like that much more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we happen to rename things, I'd be up for tracing rather than traces (even though we have metrics, as in a plural noun ;) )

That being said, having this as either TracerProvider or TraceProvider is fine IHMO.


/**
* 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