question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trace context is not propagated to Netty access logs

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
qavidcommented, Jun 2, 2021

@violetagg many thanks. Trace context is now printed in access log with reactor-netty-http-brave 1.0.8-SNAPSHOT.

1reaction
qavidcommented, May 25, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found