-
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
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
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 please add a test for the new feature (I have not found it)?
@@ -51,6 +53,12 @@ public class OpenTelemetryAutoConfiguration { | |||
|
|||
public OpenTelemetryAutoConfiguration() {} | |||
|
|||
@Bean | |||
@ConfigurationPropertiesBinding | |||
public MapConverter mapConverter() { |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it now.
Could you please update the code to:
- Move the
mapConverter
bean to an autoconfiguration only related to OTLP (just realized that it's OTLP specific) - Only create the
mapConverter
bean when OTLP is enabled - Perhaps add a comment to explain that the
mapConverter
bean is necessary for theOtlpExporterProperties
component?
Thank you!
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please give the piece of code you have added and the stack trace?
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's also used to parse otel.resource.attributes
- which can be seen in the javadoc of the class
.../java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/MapConverter.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
return builder.build(); | ||
@ConditionalOnMissingBean({OtlpGrpcSpanExporter.class, OtlpHttpSpanExporter.class}) |
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 about if the user adds another type of span exporter (for logging by example)?
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.
see below
} | ||
|
||
return builder.build(); | ||
@ConditionalOnMissingBean({OtlpGrpcMetricExporter.class, OtlpHttpMetricExporter.class}) |
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 about if the user adds another type of span exporter (for logging by example)?
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'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 |
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! can you add doc for this?
done |
@jeanbisutti final review? |
...a/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/internal/ExporterUtil.java
Outdated
Show resolved
Hide resolved
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not changed, the doc was wrong
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.
oh, right, we should change it for 2.0, similar to #10055
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.
this is the exporter for console logging, not otlp logging
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.
oh, right, thx!
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.
Thanks!
|
||
`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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to keep this information to help users diagnose this issue
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.
@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.