Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class OtlpStdoutLogRecordExporterComponentProvider
implements ComponentProvider<LogRecordExporter> {
public final class OtlpStdoutLogRecordExporterComponentProvider implements ComponentProvider {

@Override
public Class<LogRecordExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class OtlpStdoutMetricExporterComponentProvider
implements ComponentProvider<MetricExporter> {
public final class OtlpStdoutMetricExporterComponentProvider implements ComponentProvider {

@Override
public Class<MetricExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class OtlpStdoutSpanExporterComponentProvider
implements ComponentProvider<SpanExporter> {
public final class OtlpStdoutSpanExporterComponentProvider implements ComponentProvider {

@Override
public Class<SpanExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ protected T exporterFromComponentProvider(DeclarativeConfigProperties properties
properties.getComponentLoader().load(ComponentProvider.class).spliterator(), false)
.filter(
p -> {
ComponentProvider<?> c = p;
return "otlp_file/development".equals(c.getName())
&& c.getType().equals(componentProviderType);
return "otlp_file/development".equals(p.getName())
&& p.getType().equals(componentProviderType);
})
.findFirst()
.orElseThrow(() -> new IllegalStateException("No provider found"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class ConsoleLogRecordExporterComponentProvider
implements ComponentProvider<LogRecordExporter> {
public final class ConsoleLogRecordExporterComponentProvider implements ComponentProvider {

@Override
public Class<LogRecordExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class ConsoleMetricExporterComponentProvider
implements ComponentProvider<MetricExporter> {
public final class ConsoleMetricExporterComponentProvider implements ComponentProvider {

@Override
public Class<MetricExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class ConsoleSpanExporterComponentProvider implements ComponentProvider<SpanExporter> {
public final class ConsoleSpanExporterComponentProvider implements ComponentProvider {

@Override
public Class<SpanExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpGrpcLogRecordExporterComponentProvider
implements ComponentProvider<LogRecordExporter> {
public class OtlpGrpcLogRecordExporterComponentProvider implements ComponentProvider {

@Override
public Class<LogRecordExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpGrpcMetricExporterComponentProvider implements ComponentProvider<MetricExporter> {
public class OtlpGrpcMetricExporterComponentProvider implements ComponentProvider {

@Override
public Class<MetricExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpGrpcSpanExporterComponentProvider implements ComponentProvider<SpanExporter> {
public class OtlpGrpcSpanExporterComponentProvider implements ComponentProvider {

@Override
public Class<SpanExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpHttpLogRecordExporterComponentProvider
implements ComponentProvider<LogRecordExporter> {
public class OtlpHttpLogRecordExporterComponentProvider implements ComponentProvider {

@Override
public Class<LogRecordExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpHttpMetricExporterComponentProvider implements ComponentProvider<MetricExporter> {
public class OtlpHttpMetricExporterComponentProvider implements ComponentProvider {

@Override
public Class<MetricExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpHttpSpanExporterComponentProvider implements ComponentProvider<SpanExporter> {
public class OtlpHttpSpanExporterComponentProvider implements ComponentProvider {

@Override
public Class<SpanExporter> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class PrometheusComponentProvider implements ComponentProvider<MetricReader> {
public class PrometheusComponentProvider implements ComponentProvider {

@Override
public Class<MetricReader> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class ZipkinSpanExporterComponentProvider implements ComponentProvider<SpanExporter> {
public class ZipkinSpanExporterComponentProvider implements ComponentProvider {
@Override
public Class<SpanExporter> getType() {
return SpanExporter.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class B3ComponentProvider implements ComponentProvider<TextMapPropagator> {
public final class B3ComponentProvider implements ComponentProvider {

@Override
public Class<TextMapPropagator> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class B3MultiComponentProvider implements ComponentProvider<TextMapPropagator> {
public final class B3MultiComponentProvider implements ComponentProvider {

@Override
public Class<TextMapPropagator> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class JaegerComponentProvider implements ComponentProvider<TextMapPropagator> {
public final class JaegerComponentProvider implements ComponentProvider {

@Override
public Class<TextMapPropagator> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class OtTraceComponentProvider implements ComponentProvider<TextMapPropagator> {
public final class OtTraceComponentProvider implements ComponentProvider {

@Override
public Class<TextMapPropagator> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*
* @param <T> the type of the SDK extension component. See {@link #getType()}. Supported values
* include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}, {@link
* SpanProcessor}, {@link LogRecordProcessor}, {@link TextMapPropagator}, {@link Sampler},
* {@link Resource}.
* <p>Supported component types include: {@link SpanExporter}, {@link MetricExporter}, {@link
* LogRecordExporter}, {@link SpanProcessor}, {@link LogRecordProcessor}, {@link TextMapPropagator},
* {@link Sampler}, {@link Resource}.
*/
public interface ComponentProvider<T> {
public interface ComponentProvider {

/**
* The type of SDK extension component. For example, if providing instances of a custom span
* exporter, the type would be {@link SpanExporter}.
*/
Class<T> getType();
Class<?> getType();

/**
* The name of the exporter, to be referenced in configuration files. For example, if providing
Expand All @@ -59,5 +58,5 @@ public interface ComponentProvider<T> {
*/
// TODO (jack-berg): consider dynamic configuration use case before stabilizing in case that
// affects any API decisions
T create(DeclarativeConfigProperties config);
Object create(DeclarativeConfigProperties config);
Copy link
Member

Choose a reason for hiding this comment

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

that feels very odd to me - like deliberately defeating the type checker

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.resources.Resource;

public class TestResourceDetector implements ComponentProvider<Resource>, AutoConfigureListener {
public class TestResourceDetector implements ComponentProvider, AutoConfigureListener {

@SuppressWarnings("NonFinalStaticField")
static boolean initialized = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -90,11 +89,8 @@ <T> T loadComponent(Class<T> type, String name, Object model) {

// TODO(jack-berg): cache loaded component providers
List<ComponentProvider> componentProviders = spiHelper.load(ComponentProvider.class);
List<ComponentProvider<?>> matchedProviders =
List<ComponentProvider> matchedProviders =
componentProviders.stream()
.map(
(Function<ComponentProvider, ComponentProvider<?>>)
componentProvider -> componentProvider)
.filter(
componentProvider ->
componentProvider.getType() == type && name.equals(componentProvider.getName()))
Expand All @@ -115,10 +111,22 @@ <T> T loadComponent(Class<T> type, String name, Object model) {
.collect(Collectors.joining(",", "[", "]")));
}
// Exactly one matching component provider
ComponentProvider<T> provider = (ComponentProvider<T>) matchedProviders.get(0);
ComponentProvider provider = matchedProviders.get(0);

try {
return provider.create(config);
Object component = provider.create(config);
if (component != null && !type.isInstance(component)) {
throw new DeclarativeConfigException(
"Error configuring "
+ type.getName()
+ " with name \""
+ name
+ "\". Component provider "
+ provider.getClass().getName()
+ " returned an unexpected component type: "
+ component.getClass().getName());
}
return (T) component;
} catch (Throwable throwable) {
throw new DeclarativeConfigException(
"Error configuring " + type.getName() + " with name \"" + name + "\"", throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Collections;
import java.util.UUID;

public class ServiceResourceDetector implements ComponentProvider<Resource> {
public class ServiceResourceDetector implements ComponentProvider {

private static final AttributeKey<String> SERVICE_NAME = AttributeKey.stringKey("service.name");
private static final AttributeKey<String> SERVICE_INSTANCE_ID =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.extension.incubator.fileconfig;

import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.common.ComponentLoader;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* A test utility that captures the configuration passed to component providers during loading. This
* allows tests to verify that component providers receive the expected configuration.
*/
class CapturingComponentLoader implements ComponentLoader {

private final ComponentLoader delegate;
private final Map<String, DeclarativeConfigProperties> capturedConfigs =
new ConcurrentHashMap<>();

CapturingComponentLoader() {
delegate = ComponentLoader.forClassLoader(getClass().getClassLoader());
}

DeclarativeConfigProperties getCapturedConfig(String name) {
return capturedConfigs.get(name);
}

@Override
public <T> Iterable<T> load(Class<T> spiClass) {
if (spiClass == ComponentProvider.class) {
return createWrappedComponentProviders();
}
return delegate.load(spiClass);
}

@SuppressWarnings("unchecked")
private <T> Iterable<T> createWrappedComponentProviders() {
List<T> wrappedProviders = new ArrayList<>();
for (ComponentProvider provider : delegate.load(ComponentProvider.class)) {
ComponentProvider wrapped = new CapturingComponentProvider(provider);
wrappedProviders.add((T) wrapped);
}
return wrappedProviders;
}

private class CapturingComponentProvider implements ComponentProvider {

private final ComponentProvider delegate;

CapturingComponentProvider(ComponentProvider delegate) {
this.delegate = delegate;
}

@Override
public Class<?> getType() {
return delegate.getType();
}

@Override
public String getName() {
return delegate.getName();
}

@Override
public Object create(DeclarativeConfigProperties config) {
capturedConfigs.put(getName(), config);
return delegate.create(config);
}
}
}
Loading
Loading