-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Span and Trace Id are not being exported in Spring Batch (Spring Boot 3.4.1). #5758
Comments
I suspect you're ending up with double instrumentation that may be causing issues. I don't know if the instrumentation in the third-party |
We need both libraries because Micrometer only exports traces and metrics. However, OpenTelemetry handles the export of logs. OpenTelemetry does not generate the same set of metrics as Micrometer by default. Additionally, the micrometer-tracing-bridge dependency is necessary because the correlationId is only added to the logs when it is included in the project. We observed while debugging the application that the logs are sent immediately when calling any of the logger methods if the application is web-based. However, when the application is standalone, as in the mentioned case, the logs are sent only at the end of everything, at which point Context.getCurrent() returns null. Lastly, this same configuration works correctly when the application is web-based, just by adding the spring-boot-starter-web dependency and creating a RestController that executes the same batch. |
I would say Spring Boot sets up exporting traces and metrics by default. Micrometer can emit all kinds of outputs through its Observation API (see Another way of emitting this kind of information to logs is adding In both cases, you should be able to remove the starter.
This is because OTel has its own set of naming conventions. Micrometer has support to change the naming convention through the
I'm not sure I understand this completely but could you please check if registering an
Same as the previous one. |
Hi @jonatan-ivanov, thanks for the attention. As you pointed out, we are referencing micrometer-tracing-bridge-otel. This is because Micrometer provides more metrics than the OpenTelemetry (OTel) library. It is not only the naming convention that differs; Micrometer has a broad set of metrics (Tomcat, JVM, filesystem, etc.). So, in order to export the same set of metrics, we need to activate otel.instrumentation.micrometer.enabled, which requires this library. As you can see in the provided pom.xml, we are already using io.opentelemetry:opentelemetry-exporter-logging to help debug this situation. What we have observed is that the traceId is being generated correctly for the batch logs, but when I log something inside a step, for example, the traceId shows only on the console. However, when the actual logs are sent to the collector (in this case, the logs are sent to system out via otel.logs.exporter=console), we only see the traceId on internal logs of the batching system, like when it updates the database tables. My log messages show no traceId. Another difference is that when we start the batch from a RestController, we see that the logs are exported immediately after the actual log message. The same occurs with the spans, but in the standalone scenario, the spans are immediate, but the logs are exported only at the end. |
I'm not sure what's the connection, the tracing bridge is for tracing data not for metrics.
You don't need to, Micrometer produces those metrics on its own, you can configure its OTLP registry if you want to use the OpenTelemetry Protocol.
I see it in your POM but please read the rest of the paragraph, have you tried removing |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
We are implementing an internal library to collect logs and traces from Spring Batch applications and standalone applications in general.
When running a test application, the TraceId and SpanId are propagated within the application and appear in the logs. However, they are not exported. Exemples:
Logs(logback) have span information:
Logs(SystemOutLogRecordExporter) when exported loose span information:
Environment
To Reproduce
The test application we use is a simple Hello World for Spring Batch. In the properties, we set OpenTelemetry to export the traceId and spanId to the console.
The code and properties used:
Java code:
application.yml:
pom.xml
Expected behavior
We expected the traceId and spanId to be in the exported logs, as you can see in the previous log in the bug explanation
Additional context
We tested the same job on a route in a Spring web application, and everything worked as expected.
The text was updated successfully, but these errors were encountered: