-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ComponentLoader to support more auto configuration scenarios, e.g…
…. spring boot
- Loading branch information
1 parent
48d41d3
commit 703e039
Showing
29 changed files
with
270 additions
and
161 deletions.
There are no files selected for viewing
13 changes: 12 additions & 1 deletion
13
docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
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.ComponentLoader) | ||
+++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) | ||
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. | ||
+++ NEW SUPERCLASS: java.lang.Object | ||
+++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable<T> load(java.lang.Class<T>) | ||
GENERIC TEMPLATES: +++ T:java.lang.Object | ||
+++* NEW METHOD: PUBLIC(+) java.util.Map<java.lang.String,T> loadConfigurableProviders(java.lang.Class<T>) | ||
GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider | ||
+++* NEW METHOD: PUBLIC(+) java.util.List<T> loadOrdered(java.lang.Class<T>) | ||
GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...figure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure.spi; | ||
|
||
/** | ||
* A named configurable provider. | ||
* | ||
* <p>It can be used to generically determine if a provider should be replaced by another provider | ||
* with the same name. | ||
*/ | ||
public interface ConfigurableProvider { | ||
/** Returns the name of this provider. */ | ||
String getName(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...sions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; | ||
import io.opentelemetry.sdk.autoconfigure.spi.Ordered; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** A loader for components that are discovered via SPI. */ | ||
public interface ComponentLoader { | ||
<T> Iterable<T> load(Class<T> spiClass); | ||
|
||
default <T> Optional<T> loadOptional(Class<T> spiClass) { | ||
Iterable<T> iterable = load(spiClass); | ||
return StreamSupport.stream(iterable.spliterator(), false).findFirst(); | ||
} | ||
|
||
/** | ||
* 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()); | ||
} | ||
|
||
default <T extends ConfigurableProvider> Map<String, T> loadConfigurableProviders( | ||
Class<T> spiClass) { | ||
Map<String, T> components = new HashMap<>(); | ||
for (T component : load(spiClass)) { | ||
components.put(component.getName(), component); | ||
} | ||
return components; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.