Skip to content

Commit

Permalink
Convert unsigned IDs to signed IDs for Thrift
Browse files Browse the repository at this point in the history
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 (jaegertracing/jaeger#1951 (comment)), but we get to use type specifiers to make it clearer (:tada: Erlang!) instead of bit shifts and masking that Python needs to do.
  • Loading branch information
KronicDeth committed Oct 21, 2020
1 parent 242e027 commit 22db061
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/oc_reporter_jaeger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand All @@ -77,17 +77,25 @@ send_jaeger_span(Span, Agent, Process) ->
make_spans(Span) ->

TraceId = Span#span.trace_id,
<<High:64, Low:64>> = <<TraceId:128/integer>>,
%% 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
<<SignedTraceIdHigh:64/signed-integer, SignedTraceIdLow:64/signed-integer>> = <<TraceId:128/unsigned-integer>>,

%% Likewise, the span IDs, `parentSpanId` and `spanId` are signed 64, not unsigned 64
SpanId = Span#span.span_id,
<<SignedSpanId:64/signed-integer>> = <<SpanId:64/unsigned-integer>>,

ParentSpanId = case Span#span.parent_span_id of
undefined -> 0;
PSI -> PSI
end,
<<SignedParentSpanId:64/signed-integer>> = <<ParentSpanId:64/unsigned-integer>>,

[#'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,
Expand Down

0 comments on commit 22db061

Please sign in to comment.