-
Notifications
You must be signed in to change notification settings - Fork 848
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
Add a AutoConfiguredComponentWrapper SPI #3714
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
Comparing source compatibility of against | ||
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.spi.traces.SpanExporterWrapper (not serializable) | ||
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.spi.AutoConfiguredComponentWrapper (not serializable) | ||
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. | ||
+++ NEW SUPERCLASS: java.lang.Object | ||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.trace.export.SpanExporter wrap(io.opentelemetry.sdk.trace.export.SpanExporter, io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.Resource wrap(io.opentelemetry.sdk.resources.Resource, io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.samplers.Sampler wrap(io.opentelemetry.sdk.trace.samplers.Sampler, io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.SpanExporter wrap(io.opentelemetry.sdk.trace.export.SpanExporter, io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.context.propagation.TextMapPropagator wrap(io.opentelemetry.context.propagation.TextMapPropagator, io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure.spi; | ||
|
||
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
|
||
/** | ||
* A service provider interface (SPI) for wrapping autoconfigured components. For any component | ||
* automatically created by autoconfiguration, for example a span exporter, implementations of this | ||
* interface will be invoked to replace it, resulting in the final used component. | ||
*/ | ||
public interface AutoConfiguredComponentWrapper { | ||
|
||
/** Wraps a {@link Resource}. */ | ||
default Resource wrap(Resource resource, ConfigProperties config) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder if the names of these methods should be something more generic than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the more I think about it, the more I like "AutoConfiguredComponentCustomizer" as the SPI name. |
||
return resource; | ||
} | ||
|
||
/** Wraps a {@link Sampler}. */ | ||
default Sampler wrap(Sampler sampler, ConfigProperties config) { | ||
return sampler; | ||
} | ||
|
||
/** | ||
* Wraps a {@link SpanExporter}. It is common to use in conjunction with {@link | ||
* io.opentelemetry.sdk.trace.data.DelegatingSpanData} to adjust the exported data. | ||
*/ | ||
default SpanExporter wrap(SpanExporter exporter, ConfigProperties config) { | ||
return exporter; | ||
} | ||
|
||
/** Wraps a {@link TextMapPropagator}. */ | ||
default TextMapPropagator wrap(TextMapPropagator propagator, ConfigProperties config) { | ||
return propagator; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure.spi.internal; | ||
|
||
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfiguredComponentWrapper; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* Wraps components with SPI implementations. | ||
* | ||
* <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 ComponentWrapping { | ||
|
||
private static final List<AutoConfiguredComponentWrapper> wrappers; | ||
|
||
static { | ||
List<AutoConfiguredComponentWrapper> loaded = new ArrayList<>(); | ||
ServiceLoader.load(AutoConfiguredComponentWrapper.class).forEach(loaded::add); | ||
wrappers = Collections.unmodifiableList(loaded); | ||
} | ||
|
||
/** Wraps a {@link Resource}. */ | ||
public static Resource wrap(Resource resource, ConfigProperties config) { | ||
for (AutoConfiguredComponentWrapper wrapper : wrappers) { | ||
resource = wrapper.wrap(resource, config); | ||
} | ||
return resource; | ||
} | ||
|
||
/** Wraps a {@link Sampler}. */ | ||
public static Sampler wrap(Sampler sampler, ConfigProperties config) { | ||
for (AutoConfiguredComponentWrapper wrapper : wrappers) { | ||
sampler = wrapper.wrap(sampler, config); | ||
} | ||
return sampler; | ||
} | ||
|
||
/** | ||
* Wraps a {@link SpanExporter}. It is common to use in conjunction with {@link | ||
* io.opentelemetry.sdk.trace.data.DelegatingSpanData} to adjust the exported data. | ||
*/ | ||
public static SpanExporter wrap(SpanExporter exporter, ConfigProperties config) { | ||
for (AutoConfiguredComponentWrapper wrapper : wrappers) { | ||
exporter = wrapper.wrap(exporter, config); | ||
} | ||
return exporter; | ||
} | ||
|
||
/** Wraps a {@link TextMapPropagator}. */ | ||
public static TextMapPropagator wrap(TextMapPropagator propagator, ConfigProperties config) { | ||
for (AutoConfiguredComponentWrapper wrapper : wrappers) { | ||
propagator = wrapper.wrap(propagator, config); | ||
} | ||
return propagator; | ||
} | ||
|
||
private ComponentWrapping() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** Internal utilities for autoconfiguration. */ | ||
@ParametersAreNonnullByDefault | ||
package io.opentelemetry.sdk.autoconfigure.spi.internal; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.opentelemetry.sdk.autoconfigure.TestComponentWrapper |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have defined this and used in place of my previous proposed SpanExporterWrapper. Let me know if this looks OK and I'll slot it in the rest of the places