Micronaut: HTTP request/response logging with Logbook fails with NoSuchElementException: micronaut-http-response

102 views Asked by At

to implement HTTP request/response logging with my Micronaut-based application, I started from the solution described in Micronaut's documentation chapter "Configuring the Netty Server Pipeline", by simply copying Kotlin code provided there.

As the shown example bean depends on availability of a Logbook bean:

@Requires(beans = [Logbook::class])

I've added the following Factory:

@Factory
class LogbookFactory() {

  @Singleton
  fun logbook(): Logbook =
    Logbook.builder()
      .build()

}

Issuance of requests to my server yields logging of an

  • ERROR
  • from logger io.micronaut.http.netty.AbstractCompositeCustomizer,
  • stating "Failed to trigger customizer event",
  • and the following (shortened) stack trace:
java.util.NoSuchElementException: micronaut-http-response
  at io.netty.channel.DefaultChannelPipeline.getContextOrDie(DefaultChannelPipeline.java:1073)
  at io.netty.channel.DefaultChannelPipeline.addBefore(DefaultChannelPipeline.java:248)
  at io.netty.channel.DefaultChannelPipeline.addBefore(DefaultChannelPipeline.java:237)
  at [...].LogbookNettyServerCustomizer$Customizer.onStreamPipelineBuilt(LogbookNettyServerCustomizer.kt:32)
  at io.micronaut.http.netty.AbstractCompositeCustomizer.forEach(AbstractCompositeCustomizer.java:109)
  at io.micronaut.http.server.netty.CompositeNettyServerCustomizer.onStreamPipelineBuilt(CompositeNettyServerCustomizer.java:53)
  at io.micronaut.http.server.netty.HttpPipelineBuilder$ConnectionPipeline.configureForHttp1(HttpPipelineBuilder.java:386)
  [...]

Stack trace mentions line 32 in file LogbookNettyServerCustomizer.kt, which references the one marked with comment // (5) in previously mentioned example code from Micronaut's documentation:

        [...]

        override fun onStreamPipelineBuilt() {
            channel!!.pipeline().addBefore( // (5)   <=== Here is line 32 in my code
                ChannelPipelineCustomizer.HANDLER_MICRONAUT_HTTP_RESPONSE,
                "logbook",
                LogbookServerHandler(logbook)
            )
        }

        [...]

Any idea/hint what goes wrong here?

Micronaut's documentation chapter also contains warning/link towards an issue with Logbook ... does it play a role in the context I've described (though I personally can not see direct relation)?

Currently applied versions:

  • Micronaut 4.2.3
  • Logbook 3.7.2
  • Logback 1.4.13

Thanks

Christian

0

There are 0 answers