From 8a99feec6792a3fd6ab2e2db16875740f26012ff Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 2 Feb 2024 11:29:51 +0800 Subject: [PATCH] fix #1101 memory leaks in RSocketRequesterTracingObservationHandler Signed-off-by: kevin --- ...ketRequesterTracingObservationHandler.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/rsocket-micrometer/src/main/java/io/rsocket/micrometer/observation/RSocketRequesterTracingObservationHandler.java b/rsocket-micrometer/src/main/java/io/rsocket/micrometer/observation/RSocketRequesterTracingObservationHandler.java index 996267d4a..c4051f7af 100644 --- a/rsocket-micrometer/src/main/java/io/rsocket/micrometer/observation/RSocketRequesterTracingObservationHandler.java +++ b/rsocket-micrometer/src/main/java/io/rsocket/micrometer/observation/RSocketRequesterTracingObservationHandler.java @@ -23,13 +23,17 @@ import io.micrometer.tracing.handler.TracingObservationHandler; import io.micrometer.tracing.internal.EncodingUtils; import io.micrometer.tracing.propagation.Propagator; +import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.CompositeByteBuf; import io.rsocket.Payload; +import io.rsocket.metadata.CompositeMetadataCodec; import io.rsocket.metadata.TracingMetadataCodec; -import java.util.HashSet; +import io.rsocket.metadata.WellKnownMimeType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashSet; + public class RSocketRequesterTracingObservationHandler implements TracingObservationHandler { private static final Logger log = @@ -115,17 +119,22 @@ private void injectDefaultZipkinRSocketHeaders( long[] spanId = EncodingUtils.fromString(traceContext.spanId()); long[] parentSpanId = EncodingUtils.fromString(traceContext.parentId()); boolean isTraceId128Bit = traceIds.length == 2; + final ByteBufAllocator allocator = newMetadata.alloc(); if (isTraceId128Bit) { - TracingMetadataCodec.encode128( - newMetadata.alloc(), + CompositeMetadataCodec.encodeAndAddMetadata(newMetadata, + allocator, WellKnownMimeType.MESSAGE_RSOCKET_TRACING_ZIPKIN, + TracingMetadataCodec.encode128( + allocator, traceIds[0], traceIds[1], spanId[0], EncodingUtils.fromString(traceContext.parentId())[0], - flags); + flags)); } else { - TracingMetadataCodec.encode64( - newMetadata.alloc(), traceIds[0], spanId[0], parentSpanId[0], flags); + CompositeMetadataCodec.encodeAndAddMetadata(newMetadata, + allocator, WellKnownMimeType.MESSAGE_RSOCKET_TRACING_ZIPKIN, + TracingMetadataCodec.encode64( + allocator, traceIds[0], spanId[0], parentSpanId[0], flags)); } } }