use of io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider in project opentelemetry-java by open-telemetry.
the class ResourceConfiguration method configureResource.
static Resource configureResource(ConfigProperties config, ClassLoader serviceClassLoader, BiFunction<? super Resource, ConfigProperties, ? extends Resource> resourceCustomizer) {
Resource result = Resource.getDefault();
Set<String> enabledProviders = new HashSet<>(config.getList("otel.java.enabled.resource.providers"));
// TODO(anuraaga): We use a hyphen only once in this artifact, for
// otel.java.disabled.resource-providers. But fetching by the dot version is the simplest way
// to implement it for now.
Set<String> disabledProviders = new HashSet<>(config.getList("otel.java.disabled.resource.providers"));
for (ResourceProvider resourceProvider : ServiceLoader.load(ResourceProvider.class, serviceClassLoader)) {
if (!enabledProviders.isEmpty() && !enabledProviders.contains(resourceProvider.getClass().getName())) {
continue;
}
if (disabledProviders.contains(resourceProvider.getClass().getName())) {
continue;
}
result = result.merge(resourceProvider.createResource(config));
}
result = result.merge(createEnvironmentResource(config));
result = filterAttributes(result, config);
return resourceCustomizer.apply(result, config);
}
Aggregations