add support for OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME, OTEL_EXPORTER_OTLP_HEADERS and OTEL_EXPORTER_OTLP_PROTOCOL for spring boot starter#9950
Conversation
051663e to
01b786a
Compare
510f8c0 to
9c3e374
Compare
jeanbisutti
left a comment
There was a problem hiding this comment.
Could you please add a test for the new feature (I have not found it)?
|
|
||
| @Bean | ||
| @ConfigurationPropertiesBinding | ||
| public MapConverter mapConverter() { |
There was a problem hiding this comment.
Could this bean be moved to the OpenTelemetrySdkConfig class? I don't follow how it works. mapConverter bean does not seem to be injected into the OTel code and I don't see how Spring coud reuse this bean. Could you please add a comment?
There was a problem hiding this comment.
- yes, moved to
OpenTelemetrySdkConfig - the converter is used to parse headers, see https://github.com/zeitlinger/opentelemetry-java-instrumentation/blob/4bf15ad6529789eb848f609bf78ae2c96fc04103/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java#L103-L116
There was a problem hiding this comment.
I don't follow where the mapConverter bean is injected and used. Is the mapConverter bean really used (are the tests green without this bean)? The parsing is not done in the OtlpExporterUtil class?
There was a problem hiding this comment.
This test fails when the converter is removed:
This is the error message:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'otelOtlpSpanExporter' defined in io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration: Unsatisfied dependency expressed through method 'otelOtlpSpanExporter' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'otel.exporter.otlp-io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpExporterProperties': Could not bind properties to 'OtlpExporterProperties' : prefix=otel.exporter.otlp, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'otel.exporter.otlp.headers' to java.util.Map<java.lang.String, java.lang.String>
There was a problem hiding this comment.
I got it now.
Could you please update the code to:
- Move the
mapConverterbean to an autoconfiguration only related to OTLP (just realized that it's OTLP specific) - Only create the
mapConverterbean when OTLP is enabled - Perhaps add a comment to explain that the
mapConverterbean is necessary for theOtlpExporterPropertiescomponent?
Thank you!
There was a problem hiding this comment.
I added comments in the different places.
I tried to make the converter local, but that doesn't work:
for bean 'mapConverter' since there is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0;
There was a problem hiding this comment.
Could you please give the piece of code you have added and the stack trace?
There was a problem hiding this comment.
@jeanbisutti I've added support for OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME as well now.
And I've figured out a way to make the converter conditional:
@Bean
@ConfigurationPropertiesBinding
@ConditionalOnBean({OtelResourceAutoConfiguration.class, OtlpLoggerExporterAutoConfiguration.class,
OtlpSpanExporterAutoConfiguration.class, OtlpMetricExporterAutoConfiguration.class})
public MapConverter mapConverter() {
// needed for otlp exporter headers and OtelResourceProperties
return new MapConverter();
}There was a problem hiding this comment.
The mapConverter bean is still in the OpenTelemetryAutoConfiguration class whose responsibility is to instantiate an OpenTelemetry bean.
You could create the mapConverter bean with an OTLP-related autoconfiguration.
OtlpLoggerExporterAutoConfiguration, OtlpLoggerExporterAutoConfiguration, OtlpSpanExporterAutoConfiguration are examples of autoconfiguration.
The autoconfiguration classes have to be declared in the spring.factories (<Spring Boot 2.7) org.springframework.boot.autoconfigure.AutoConfiguration.imports (>=Spring Boot 2.7) files.
There was a problem hiding this comment.
it's also used to parse otel.resource.attributes - which can be seen in the javadoc of the class
| } | ||
|
|
||
| return builder.build(); | ||
| @ConditionalOnMissingBean({OtlpGrpcSpanExporter.class, OtlpHttpSpanExporter.class}) |
There was a problem hiding this comment.
What about if the user adds another type of span exporter (for logging by example)?
| } | ||
|
|
||
| return builder.build(); | ||
| @ConditionalOnMissingBean({OtlpGrpcMetricExporter.class, OtlpHttpMetricExporter.class}) |
There was a problem hiding this comment.
What about if the user adds another type of span exporter (for logging by example)?
There was a problem hiding this comment.
I've added a test to show that this still works: https://github.com/zeitlinger/opentelemetry-java-instrumentation/blob/4bf15ad6529789eb848f609bf78ae2c96fc04103/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java#L120-L128
can you help me decide which test style would fit here? |
|
You have two possibilities:
Personally, I'd prefer the first option in this case because the smoke tests could become difficult to read if we check to many features (only one Spring Boot app for the smoke tests). |
a279c92 to
4bf15ad
Compare
thanks for the help - and I agree. |
|
@jeanbisutti can you have another look? |
@zeitlinger Done |
done |
|
@jeanbisutti final review? |
|
@jeanbisutti all done 😄 |
| | Otlp Logs Exporter | otel.exporter.otlp.logs.enabled | `true` | OtlpGrpcLogRecordExporter | | ||
| | Jaeger Exporter | otel.exporter.jaeger.enabled | `true` | JaegerGrpcSpanExporter | | ||
| | Zipkin Exporter | otel.exporter.zipkin.enabled | `true` | ZipkinSpanExporter | | ||
| | Logging Exporter | otel.exporter.logging.enabled | `false` | LoggingSpanExporter | |
There was a problem hiding this comment.
Why the default value of the otel.exporter.logging.enabled property has been changed from true to false?
There was a problem hiding this comment.
it's not changed, the doc was wrong
There was a problem hiding this comment.
oh, right, we should change it for 2.0, similar to #10055
There was a problem hiding this comment.
this is the exporter for console logging, not otlp logging
| | spring-webflux | otel.instrumentation.spring-webflux.enabled | `true` | WebClient | | ||
| | @WithSpan | otel.instrumentation.annotations.enabled | `true` | WithSpan, Aspect | | ||
|
|
||
| `unknown_service:java` will be used as the service-name if no value has been specified to the |
There was a problem hiding this comment.
It would be great to keep this information to help users diagnose this issue
|
@jeanbisutti ready for approval 😄 |
@zeitlinger I have approved |
Fixes #8191
it's also possible to add the header in in application.yml as a yaml map.