Trace context is not propagated to Netty access logs
See original GitHub issueDescribe the bug When Reactor Netty access log is enabled and reactor signals are published on different scheduler, then there is no trace info in access logs. If same scheduler is used, trace context is propagated and correctly printed in access log.
Trace context should also be propagated to access log so we can correlate application logs with access logs.
Spring Cloud version: 2020.0.2 Spring Sleuth version: 3.0.2
Sample Use Spring Initializer with Spring Reactive Web and Sleuth (in my case with Kotlin). Add controller:
@RestController
class Controller {
private val logger = LoggerFactory.getLogger(javaClass)
@GetMapping("test1")
fun test1() = Mono.just("response")
.doOnNext {
logger.info("Test1")
}
@GetMapping("test2")
fun test2() = Mono.just("response")
.doOnNext {
logger.info("Test2 - before publishOn")
}
.publishOn(Schedulers.boundedElastic())
.doOnNext {
logger.info("Test2 - after publishOn")
}
}
Start application with -Dreactor.netty.http.server.accessLogEnabled=true GET http://localhost:8080/test1 correctly prints spanId & traceId
2021-05-25 09:45:53.357 INFO [,dc579da470f010ee,dc579da470f010ee] 31692 --- [ctor-http-nio-4] com.example.demo.Controller : Test1
2021-05-25 09:45:53.357 INFO [,dc579da470f010ee,dc579da470f010ee] 31692 --- [ctor-http-nio-4] reactor.netty.http.server.AccessLog : 127.0.0.1:52134 - - [25/May/2021:09:45:53 +0200] "GET /test1 HTTP/1.1" 200 8 0 ms
GET http://localhost:8080/test2 spanId & traceId is missing in access log
2021-05-25 09:45:55.990 INFO [,172cd6fa0e60cb81,172cd6fa0e60cb81] 31692 --- [ctor-http-nio-5] com.example.demo.Controller : Test2 - before publishOn
2021-05-25 09:45:55.990 INFO [,172cd6fa0e60cb81,172cd6fa0e60cb81] 31692 --- [oundedElastic-2] com.example.demo.Controller : Test2 - after publishOn
2021-05-25 09:45:55.990 INFO [,,] 31692 --- [ctor-http-nio-5] reactor.netty.http.server.AccessLog : 127.0.0.1:52135 - - [25/May/2021:09:45:55 +0200] "GET /test2 HTTP/1.1" 200 8 0 ms
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Logback MDC on Netty or any other non-blocking IO server
I'm not terribly familiar with using netty directly, but I do know that it is possible to use logback MDC with asynchronous code....
Read more >Spring Cloud Sleuth
The span context is the state that must get propagated to any child spans across process boundaries. Part of the Span Context is...
Read more >Reactor 3 Reference Guide
The Schedulers class has static methods that give access to the following execution contexts: No execution context ( Schedulers.immediate() ): at processing ...
Read more >Exceptions in Netty - Baeldung
However, we can actually propagate the exception on to another channel handler in the pipeline. Instead of logging the error message and calling ......
Read more >Using OpenTelemetry - Quarkus
6, You can also only put the trace info into the access log. ... opentelemetry, rest-client, resteasy, smallrye-context-propagation, vertx] 10:49:03 INFO ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@violetagg many thanks. Trace context is now printed in access log with reactor-netty-http-brave 1.0.8-SNAPSHOT.
@marcingrzejszczak I have created PR to sleuth-issues repo: https://github.com/spring-cloud-samples/sleuth-issues/pull/67