Skip to content
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 shouldApply to ResourceProvider interface #4718

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,2 +1,4 @@
Comparing source compatibility of against
No changes.
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++! NEW METHOD: PUBLIC(+) boolean shouldApply(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties, io.opentelemetry.sdk.resources.Resource)
Expand Up @@ -14,4 +14,16 @@
public interface ResourceProvider extends Ordered {

Resource createResource(ConfigProperties config);

/**
* If an implementation needs to apply only under certain conditions related to the config or the
* existing state of the Resource being built, they can choose to override this default.
*
* @param config The auto configuration properties
* @param existing The current state of the Resource being created
* @return false to skip over this ResourceProvider, or true to use it
*/
default boolean shouldApply(ConfigProperties config, Resource existing) {
return true;
}
}
Expand Up @@ -46,7 +46,9 @@ static Resource configureResource(
if (disabledProviders.contains(resourceProvider.getClass().getName())) {
continue;
}
result = result.merge(resourceProvider.createResource(config));
if (resourceProvider.shouldApply(config, result)) {
result = result.merge(resourceProvider.createResource(config));
}
}

result = result.merge(createEnvironmentResource(config));
Expand Down