quarkus: traceId, spanId not set in logs when using quartz and opentelemetry
Describe the bug
I use quarkus-quartz and quarkus-opentelemetry
Have definded a custom log format like in https://quarkus.io/guides/opentelemetry#create-the-configuration
quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n
Expected behavior
Expected that traceId etc. are filled, (this only works for rest resource), see:
00:16:43 INFO traceId=7d79594584b49a7db88f47c75a0cd185, parentId=, spanId=cb9d17786f3ed0c0, sampled=true [or.ac.qu.TaskResource] (executor-thread-0) log test
Actual behavior
But for log output in quartz scheduled method everything is empty
00:16:45 INFO traceId=, parentId=, spanId=, sampled= [or.ac.qu.TaskBean] (QuarkusQuartzScheduler_Worker-3) log test
How to Reproduce?
https://github.com/syr/quartz-otel-logs is based on latest quartz-quickstart code.
Only needs to be started, scheduler runs every 10 seconds printing log lines without traceId etc.
Calling http://localhost:8080/tasks shows that it works generally, but only for rest resources
Output of uname -a or ver
No response
Output of java -version
java -version openjdk version “17.0.2” 2022-01-18 OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8) OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.13.2.Final
Build tool (ie. output of mvnw --version or gradlew --version)
Maven 3.8.1
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 45 (24 by maintainers)
Commits related to this issue
- trying to reproduce https://github.com/quarkusio/quarkus/issues/28552 — committed to syr/quarkus-resteasy-postgres by cstsys a year ago
- trying to reproduce https://github.com/quarkusio/quarkus/issues/28552 — committed to syr/quarkus-resteasy-postgres by syr a year ago
- reproduced https://github.com/quarkusio/quarkus/issues/28552 — committed to syr/quarkus-resteasy-postgres by syr a year ago
- reproduced https://github.com/quarkusio/quarkus/issues/28552 — committed to syr/quarkus-resteasy-postgres by syr a year ago
quarkus-opentelemetryGonna have a look at this
It would require adding proper OTel integration in a
JobListener. This can be used as a basis: https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/quartz-2.0/library/src/main/java/io/opentelemetry/instrumentation/quartz/v2_0Would you like to try submitting a PR with the proper support? 😃
If everything works with
@WithSpan, which we treat as an interceptor binding, enabling tracing by default for scheduled methods would amount to a simple annotation transformation I’d say.@syr I’m not using the otel agent explicitly, only quarkus-opentelemetry + quarkus-scheduler dependencies and additionally
io.opentelemetry.instrumentation:opentelemetry-jdbc.@WithSpanjust works, I see JDBC sub-spans for my job executions.I created a separate enhancement issue: #29647
Wow this sounds really promissing and gives a very specific picture. Thanks for sharing @brunobat
I would wrap it up here now and close the ticket as we have a perspective for 2023.
For everyone looking for a workaround/fix to get traceId, spanId set in logs when using libs which are not instrumented by quarkus-opentelemetry atm (e.g. quartz, aws sdk) I woud advice to use otel agent, which requires:
quarkus.opentelemetry.enabled=falseto get the otel interface for example to create custom spans (e.g. @WithSpan)OK sounds good. I was referring to the status shown at code.quarkus.io. Is there a rough roadmap weeks/months/2023 when to expect these extended otel support beeing released? This info would be very helpful to decide how much effort we put in workarounds using otel agent.
Yes I noticed quite some issues (mainly three points in https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7120#issuecomment-1316697698), however it was the only way I see to get quartz and aws sdk auto-instrumented atm.
We have quite few reactive code in the project, I would rather consider to change it back to impierative because there are also issues when Mutiny is combined with @Transactional for example…likely mixing imperative and reactive is not a good idea. But that’s another topic…
Tracing does make sense on Quartz Jobs. This is not just for HTTP. It will be great to understand the outcome of each job. This requires 2 changes, though. One thing is to instrument jobs, another one is curating the MDC context with the right data.
Technically, a scheduled method can call other external services etc., and so tracing may make sense. As you mention, a scheduled method is an entrypoint, so it deserves a fresh new trace/span, I’d say.