diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java index fb9b41457a..01ed1d9b2e 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java @@ -175,16 +175,13 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) if (msg instanceof LastHttpContent) { promise.addListener(future -> { - ChannelOperations channelOps = ChannelOperations.get(ctx.channel()); - if (channelOps instanceof HttpServerOperations) { - try { - recordWrite((HttpServerOperations) channelOps); - } - catch (RuntimeException e) { - // Allow request-response exchange to continue, unaffected by metrics problem - if (log.isWarnEnabled()) { - log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); - } + try { + recordWrite(ctx.channel()); + } + catch (RuntimeException e) { + // Allow request-response exchange to continue, unaffected by metrics problem + if (log.isWarnEnabled()) { + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } } @@ -299,7 +296,7 @@ protected void recordRead() { recorder().recordDataReceived(remoteSocketAddress, path, dataReceived); } - protected void recordWrite(HttpServerOperations ops) { + protected void recordWrite(Channel channel) { Duration dataSentTimeDuration = Duration.ofNanos(System.nanoTime() - dataSentTime); recorder().recordDataSentTime(path, method, status, dataSentTimeDuration); diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/ContextAwareHttpServerMetricsHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/ContextAwareHttpServerMetricsHandler.java index 1c259147cd..b4f3b9428f 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/ContextAwareHttpServerMetricsHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/ContextAwareHttpServerMetricsHandler.java @@ -15,6 +15,7 @@ */ package reactor.netty.http.server; +import io.netty.channel.Channel; import reactor.util.annotation.Nullable; import reactor.util.context.ContextView; @@ -72,7 +73,7 @@ protected void recordRead() { } @Override - protected void recordWrite(HttpServerOperations ops) { + protected void recordWrite(Channel channel) { Duration dataSentTimeDuration = Duration.ofNanos(System.nanoTime() - dataSentTime); recorder().recordDataSentTime(contextView, path, method, status, dataSentTimeDuration); diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/MicrometerHttpServerMetricsHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/MicrometerHttpServerMetricsHandler.java index ec393f15d6..fd84825936 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/MicrometerHttpServerMetricsHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/MicrometerHttpServerMetricsHandler.java @@ -19,6 +19,7 @@ import io.micrometer.core.instrument.Timer; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.RequestReplyReceiverContext; +import io.netty.channel.Channel; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import reactor.netty.observability.ReactorNettyHandlerContext; @@ -85,7 +86,7 @@ protected HttpServerMetricsRecorder recorder() { } @Override - protected void recordWrite(HttpServerOperations ops) { + protected void recordWrite(Channel channel) { Duration dataSentTimeDuration = Duration.ofNanos(System.nanoTime() - dataSentTime); recorder().recordDataSentTime(path, method, status, dataSentTimeDuration); @@ -100,7 +101,7 @@ protected void recordWrite(HttpServerOperations ops) { // Move the implementation from the recorder here responseTimeObservation.stop(); - setChannelContext(ops.channel(), parentContextView); + setChannelContext(channel, parentContextView); responseTimeHandlerContext = null; responseTimeObservation = null;