-
Notifications
You must be signed in to change notification settings - Fork 923
add ComponentLoader to support more auto configuration scenarios #6217
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
Changes from 18 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 |
|---|---|---|
|
|
@@ -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
Member
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.
Outdated
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 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.