-
Notifications
You must be signed in to change notification settings - Fork 774
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 ComponentLoader to support more auto configuration scenarios #6217
Changes from 17 commits
0531869
6d51896
2b9fb28
e1352d6
091b19b
eac57ca
ae2c633
2bec27f
ad4047f
5336d59
44df716
74322cd
5799589
3f574fb
6d06755
42d6e17
d03a67f
517d773
e97c4f9
4519a7e
22996e0
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,2 +1,5 @@ | ||
Comparing source compatibility of against | ||
No changes. | ||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader) | ||
*** MODIFIED METHOD: PUBLIC (<- PACKAGE_PROTECTED) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setConfig(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import io.opentelemetry.sdk.OpenTelemetrySdkBuilder; | ||
import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; | ||
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||
|
@@ -115,7 +116,7 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur | |
* {@link #addPropertiesSupplier(Supplier)} and {@link #addPropertiesCustomizer(Function)} will | ||
* have no effect if this method is used. | ||
*/ | ||
AutoConfiguredOpenTelemetrySdkBuilder setConfig(ConfigProperties config) { | ||
public AutoConfiguredOpenTelemetrySdkBuilder setConfig(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. Can you explain the reasoning for this? Its pretty drastic to want to call this and negate calls to Its currently only being used in tests, and even those usages aren't necessary. I honestly think we ought to delete it altogether rather than promote it to the public API. 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. Spring needs a different implementation of The alternative would be to stringify maps and lists - and then let them be parsed using 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. My suggestion: Make this method experimental like 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.
What would be the path to stabilizing? I think we should stabilize 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. What about an experimental method to customize ConfigProperties? Something like:
The idea is that it follows a similar pattern to the customization methods in 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. That idea is quite elegant. I don't think a spring user would expect that capability, because spring can already do that: https://stackoverflow.com/questions/29072628/how-can-i-override-spring-boot-application-properties-programmatically 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 think your proposal could be good for distros of the spring starter, so I'll implement it. |
||
requireNonNull(config, "config"); | ||
this.config = config; | ||
return this; | ||
|
@@ -368,6 +369,13 @@ public AutoConfiguredOpenTelemetrySdkBuilder setServiceClassLoader( | |
return this; | ||
} | ||
|
||
/** Sets the {@link ComponentLoader} to be used to load SPI implementations. */ | ||
public AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(ComponentLoader componentLoader) { | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
jack-berg marked this conversation as resolved.
Show resolved
Hide resolved
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. Actually this is problematic. Can't have a public API reference an internal class, since this would break when we move ComponentLoader to a public package. The way we've implemented this stuff in the past is:
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. ah, that's why we have those reflective methods 😄 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. Its strange but it works 😅 |
||
requireNonNull(componentLoader, "componentLoader"); | ||
this.spiHelper = SpiHelper.create(componentLoader); | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a new {@link AutoConfiguredOpenTelemetrySdk} holding components auto-configured using | ||
* the settings of this {@link AutoConfiguredOpenTelemetrySdkBuilder}. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,21 +173,13 @@ static Sampler configureSampler(String sampler, ConfigProperties config, SpiHelp | |
case "always_off": | ||
return Sampler.alwaysOff(); | ||
case "traceidratio": | ||
{ | ||
double ratio = | ||
config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO); | ||
return Sampler.traceIdRatioBased(ratio); | ||
} | ||
return ratioSampler(config); | ||
case PARENTBASED_ALWAYS_ON: | ||
return Sampler.parentBased(Sampler.alwaysOn()); | ||
case "parentbased_always_off": | ||
return Sampler.parentBased(Sampler.alwaysOff()); | ||
case "parentbased_traceidratio": | ||
{ | ||
double ratio = | ||
config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO); | ||
return Sampler.parentBased(Sampler.traceIdRatioBased(ratio)); | ||
} | ||
return Sampler.parentBased(ratioSampler(config)); | ||
Comment on lines
-186
to
+182
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. this is a nice change, but seems unrelated to this PR? in the future splitting out unrelated changes can make life easier for reviewers |
||
case "parentbased_jaeger_remote": | ||
Sampler jaegerRemote = spiSamplersManager.getByName("jaeger_remote"); | ||
if (jaegerRemote == null) { | ||
|
@@ -205,5 +197,10 @@ static Sampler configureSampler(String sampler, ConfigProperties config, SpiHelp | |
} | ||
} | ||
|
||
private static Sampler ratioSampler(ConfigProperties config) { | ||
double ratio = config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO); | ||
return Sampler.traceIdRatioBased(ratio); | ||
} | ||
|
||
private TracerProviderConfiguration() {} | ||
} |
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.internal; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.spi.Ordered; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
* A loader for components that are discovered via SPI. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
public interface ComponentLoader { | ||
/** | ||
* Load implementations of an SPI. | ||
* | ||
* @param spiClass the SPI class | ||
* @param <T> the SPI type | ||
* @return iterable of SPI implementations | ||
*/ | ||
<T> Iterable<T> load(Class<T> spiClass); | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Load implementations of an ordered SPI (i.e. implements {@link Ordered}). | ||
* | ||
* @param spiClass the SPI class | ||
* @param <T> the SPI type | ||
* @return list of SPI implementations, in order | ||
*/ | ||
default <T extends Ordered> List<T> loadOrdered(Class<T> spiClass) { | ||
return StreamSupport.stream(load(spiClass).spliterator(), false) | ||
.sorted(Comparator.comparing(Ordered::order)) | ||
.collect(Collectors.toList()); | ||
} | ||
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. do we need this method? (can inline as private method in 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. the method is meant for overriding. I'm still unsure if that's what users actually expect though. It affects
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. can't find a really compelling reason - I'll remove it. |
||
} |
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.
Shouldn't need this anymore.
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.
not for this PR - but it's still true that jApiCmp will trip over generics - I'm fine to take it out, of course.