From 22db0619a65f4d45c80f6e741ee76971ce366335 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Tue, 20 Oct 2020 22:26:15 -0500 Subject: [PATCH] Convert unsigned IDs to signed IDs for Thrift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes jaegertracing/jaeger#1951 Thrift IDs are i64, which is a _signed_ 64-bit integer, but the Jaeger protocol says IDs are unsigned, so in our records we store them unsigned.  When sending the IDs through Thrift, we need to convert the bits directly from unsigned to signed.  This matches the behavior in the Python client (https://github.com/jaegertracing/jaeger-client-python/blob/51d9027c3e0b87f6721dd14e7bc2b3303ce682c2/jaeger_client/thrift.py#L32-L47) as pointed out here (https://github.com/jaegertracing/jaeger/issues/1951#issuecomment-563865989), but we get to use type specifiers to make it clearer (:tada: Erlang!) instead of bit shifts and masking that Python needs to do. --- src/oc_reporter_jaeger.erl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/oc_reporter_jaeger.erl b/src/oc_reporter_jaeger.erl index 3c6bba3..645d0cc 100644 --- a/src/oc_reporter_jaeger.erl +++ b/src/oc_reporter_jaeger.erl @@ -50,7 +50,7 @@ init(Opts) -> Port = jaeger_port(Opts), ProtocolModule = jaeger_protocol(Opts), TransportModule = ?DEFAULT_TRANSPORT, - + ServiceName = jaeger_service_name(Opts), ServiceTags = jaeger_service_tags(Opts), @@ -77,17 +77,25 @@ send_jaeger_span(Span, Agent, Process) -> make_spans(Span) -> TraceId = Span#span.trace_id, - <> = <>, + %% traceIdLow and traceIdHigh are _signed_ 64-bit integers while `High` and `Low` are unsigned, so they need to + %% converted to signed to not be truncated in the thrift protocol + %% See https://github.com/jaegertracing/jaeger/issues/1951 + <> = <>, + + %% Likewise, the span IDs, `parentSpanId` and `spanId` are signed 64, not unsigned 64 + SpanId = Span#span.span_id, + <> = <>, ParentSpanId = case Span#span.parent_span_id of undefined -> 0; PSI -> PSI end, + <> = <>, - [#'Jaeger.Thrift.Span'{'traceIdLow' = Low, - 'traceIdHigh' = High, - 'spanId' = Span#span.span_id, - 'parentSpanId' = ParentSpanId, + [#'Jaeger.Thrift.Span'{'traceIdLow' = SignedTraceIdLow, + 'traceIdHigh' = SignedTraceIdHigh, + 'spanId' = SignedSpanId, + 'parentSpanId' = SignedParentSpanId, 'operationName' = Span#span.name, 'references' = to_references(Span#span.links), 'flags' = Span#span.trace_options,