-
Notifications
You must be signed in to change notification settings - Fork 870
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
Spring Boot Starter service-name is constant #5359
Spring Boot Starter service-name is constant #5359
Conversation
|
@mateuszrzeszutek could you provide some feedback, please? |
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.
thx @aschugunov! sorry for the delay in reviewing
public Supplier<Resource> otelOsResourceProvider() { | ||
return OsResource::get; | ||
} |
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.
what do you think of loading the resources via SPI? https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/resources/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider
or are there advantages to having them as separate named beans?
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.
To be honest, I dont deeply understand how SPI works.
Currently, trace does not contain any inforamtion about os, container and other resources.
Main idea is combine all resources via supplier resource beans and then inject complex resource into tracerProvider.
maybe it is possbile to do with SPI, I will try to research. Thanks.
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.
I tried to load resource objects via spring.factories and it seems spring does not load bean by interface or I did it in wrong manner.
If I understand correctly java loads objects via SPI when implementation is located in classpath, spring can customize context via spring.factories file. But this way does not work
io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider=\
io.opentelemetry.sdk.extension.resources.ContainerResourceProvider,\
io.opentelemetry.sdk.extension.resources.HostResourceProvider,\
io.opentelemetry.sdk.extension.resources.OsResourceProvider,\
io.opentelemetry.sdk.extension.resources.ProcessResourceProvider,\
io.opentelemetry.sdk.extension.resources.ProcessRuntimeResourceProvider
I added @ConditionalOnClass
over appropriate bean, maybe it will be more suitable
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.
How about registering the ResourceProvider
s as beans? That's the same interface that OTel SDK autoconfigure uses - but instead of using SPI/ServiceLoader
you'd just load all beans of that type.
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.
Could you explain a bit more, please?
Did you mean to create resourceProvider
beans in addition to resource
beans?
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.
So, instead of all the Supplier<Resource>
beans in this class, you could use ResourceProvider
instead:
@Bean
@ConditionalOnClass(OsResource.class)
public ResourceProvider osResourceProvider() {
return new OsResourceProvider();
}
@Bean
@ConditionalOnClass(ProcessResource.class)
public ResourceProvider processResourceProvider() {
return new ProcessResourceProvider();
}
// ...
Then, in the OpenTelemetryAutoConfiguration
class you'd change the otelResource
method so that it uses these beans:
@Bean
@ConditionalOnMissingBean
public Resource otelResource(
Environment env, ObjectProvider<List<ResourceProvider>> resourceProviders) {
String applicationName = env.getProperty("spring.application.name");
Resource resource = defaultResource(applicationName);
ConfigProperties config = SpringConfigProperties(env);
for (ResourceProvider provider : resourceProviders.getIfAvailable(Collections::emptyList)) {
resource = resource.merge(provider.createResource(config));
}
return resource;
}
ResourceProvider#createResource
requires a ConfigProperties
argument, but it would be quite simple to implement one that just simply delegates to Spring's Environment
class.
This way you could reuse the SDK ResourceProvider
interface in a way that's compatible with Spring beans -- instead of using SPI, the user of the instrumented application could just configure a ResourceProvider
bean in their app and it'd get picked up automatically by this lib.
WDYT about that?
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.
Yes it is a great idea to reuse existed interface for getting all available resources.
I see benefit of interface, it can be more clear for whole open telemetry project because interface provides consistent concept.
On the other hand, supplier follows the same idea - to provide resource. I mean there is no difference how spring will provide beans - via ResourceProvider
interface or via Supplier<Resource>
. Also interface enforce to use ConfigProperties
that is not used in any current resourceProviders implementations.
OtelResourceProperties
is such type of config. It is created by spring automatically.
If I understand correctly I should implement something like SpringResourceProvider and encapsulate there logic of determination of application name and attributes.
I will add these changes in second commit in this PR in a day or two. So you will be able to evaluate changes and choose more appropriate implementation.
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.
I will add these changes in second commit in this PR in a day or two. So you will be able to evaluate changes and choose more appropriate implementation.
👍 Thanks!
a5595cd
to
db474af
Compare
...io/opentelemetry/instrumentation/spring/autoconfigure/OtelResourceAutoConfigurationTest.java
Outdated
Show resolved
Hide resolved
db474af
to
a6868af
Compare
d7977d8
to
f0b71d1
Compare
@open-telemetry/java-instrumentation-approvers last chance to review! |
.../main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OtelResourceProperties.java
Outdated
Show resolved
Hide resolved
private static Resource defaultResource(String applicationName) { | ||
if (applicationName == null) { | ||
return Resource.getDefault(); | ||
} | ||
return Resource.getDefault() | ||
.merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName))); | ||
} |
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.
Nice 👍
...ava/io/opentelemetry/instrumentation/spring/autoconfigure/OtelResourceAutoConfiguration.java
Outdated
Show resolved
Hide resolved
public Supplier<Resource> otelOsResourceProvider() { | ||
return OsResource::get; | ||
} |
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.
How about registering the ResourceProvider
s as beans? That's the same interface that OTel SDK autoconfigure uses - but instead of using SPI/ServiceLoader
you'd just load all beans of that type.
Pattern-based resource configuration
f0b71d1
to
53678f2
Compare
d7c8011
to
393e0b9
Compare
Thanks @aschugunov ! |
* Spring Boot Starter service-name is constant Pattern-based resource configuration * Add ResourceProvider beans for spring with ConfigProperties
Pattern-based resource attributes configuration
fix 3480