-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Optimize OpenTelemetry Metric and Tracing autoconfiguration #34023
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
Comments
Thanks for the suggestion, @FranPregernik. Unfortunately, I'm struggling to follow exactly what you mean. For example, you seem to be proposing a change to I think it may be easier if we take a step back and focus on what you'd like to be able to do rather than describing code changes that you believe will make it possible. Alternatively, seeing Java code (rather than Kotlin) complete with imports may help us to better understand your goals. |
If I've understood @FranPregernik correctly and from an examination of the code:
|
@wilkinsona I am sorry, I should have checked the libraries of the classes I mentioned. My bad. @jimbogithub Thank you for stepping in. That is it exactly. However, one small sidenote on the last point, I have a PR open-telemetry/opentelemetry-java-instrumentation#7697 that allows JDBC instrumentation to accept an external OpenTelemetry instance. |
Also interested in #2 in particular. Currently there is no way to identify a traced application's Ideally you can provide a configuration property like metrics, but for now the whole SdkTracerProvider needs to be replaced. |
I think this could work:
We would just need to pass all spring properties with |
We are using this strategy so we can support all otel configuration flags - and provide an additional means of configuration - via spring boot properties. I was going to propose this for Spring, but one drawback I see for now is that otel-sdk-autoconfigure version has -alpha suffix: see their releases https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-sdk-extension-autoconfigure. Not sure when they'll promote it to stable. ps: instead of using system properties you can provide a properties supplier and provide a map that was generated from spring boot properties. E.g: Map<String, String> otelProperties = readPropertiesStartingWith("otel", env);
final AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
sdkBuilder.addPropertiesSupplier(() -> otelProperties); |
I've created a draft PR now:
|
@wilkinsona Something that might actually be helpful as a tweak for those of us trying to do "alpha" things like logs and metrics right now would be to create something like this in the OpenTelemetryAutoConfiguration class: @Bean
@ConditionalOnMissingBean
public Resource resource(Environment environment) {
String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
return Resource.getDefault()
.merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName)));
} And then use that bean in the SdkTracerProvider bean that IS being autoconfigured. This way, the resource is easily available/reusable by those of us who wish to create something like this ourselves: @Bean
public SdkLoggerProvider sdkLoggerProvider(Resource resource) {
SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder().setResource(resource)
.addLogRecordProcessor(
SimpleLogRecordProcessor.create(
OtlpGrpcLogRecordExporter.builder()
.setEndpoint(otelCollectorEndpoint)
.build()))
.build();
GlobalLoggerProvider.set(sdkLoggerProvider);
return sdkLoggerProvider;
} Otherwise we might need to override other classes like SdkTracerProvider that I'd rather let spring autoconfigure. |
Seeing this has been labeled as |
Possibly relevant for this issue, OpenTelemetry Java has just released |
There's a lot going on in this issue and I think this should be split into multiple issues. So let's dissect this a bit more:
What would be another option to send metrics to OpenTelemetry? If I understand it correctly, we have OTLP support for spans via OTel's What you all want is a support for OTLP metrics directly via OTel, so that all the other abstractions (Resource, |
This could be solved by creating a
That means moving the configuration properties from |
Yes, |
And another remark from @vpavic about the number of beans contributed by the OpenTelemetry auto-configuration, which has been marked as a duplicate of this: #36248 (comment) |
I've splitted this issue into multiple smaller ones and I'm going to close this issue. Please subscribe to the issues which you're interested in: |
Hi!
I would like to propose an improvement in the way the OpenTelemetry metrics and tracing are auto-configured.
This is related to the issue: #30156 and my comment at the end.
As a starting point, the tracing
OpenTelemetryAutoConfiguration
sets up an instance of the OpenTelemetry and fetches a list of tracing providers. It is a great way to specify a non-supported exporter (e.g.OtlpGrpcSpanExporter
instead of brave/zipkin/wavefront).But the
OtlpMetricsExportAutoConfiguration
does not use the OpenTelemetry instance at all and registers theOtlpMeterRegistry
based on a configuration. Currently I have no way of specifying aOtlpGrpcMetricExporter
that it want to use.My proposition is to have separate basic OpenTelemetry auto-configuration, a OpenTelemetry tracing auto-configuration and finally a OpenTelemetry metrics auto-configuration.
The main OpenTeleletry autoconfiguration would have the following:
The
otelResource
is a consistent way to specify the service name and other parameters for both metrics and tracing. The OpenTelemetry accepts the additionalsdkMeterProvider
and allows a setup of a customMetricExporter
.The
OtlpMetricsExportAutoConfiguration
would create theSdkMeterProvider
, Exporter and Registry:So now both tracing and metrics use the same OpenTelemetry instance that is set up with a single OpenTelemetry Resource instance. The default metric exporter is the
OtlpHttpMetricExporter
and can be overridden with the GRPC version.The text was updated successfully, but these errors were encountered: