Skip to content

Commit

Permalink
fix rsocket#1101 memory leaks in RSocketRequesterTracingObservationHa…
Browse files Browse the repository at this point in the history
…ndler

Signed-off-by: kevin <[email protected]>
  • Loading branch information
kevinat authored Feb 2, 2024
1 parent 6d07389 commit 8a99fee
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RSocketContext> {
private static final Logger log =
Expand Down Expand Up @@ -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));
}
}
}

0 comments on commit 8a99fee

Please sign in to comment.