From 82c343ee4a470991140b89a05436fdeb96360c36 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 24 Jan 2023 16:23:31 +0100 Subject: [PATCH] Fix serializable trace legacy JSON format --- lib/ddtrace/transport/serializable_trace.rb | 8 ++++++-- spec/ddtrace/transport/serializable_trace_spec.rb | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ddtrace/transport/serializable_trace.rb b/lib/ddtrace/transport/serializable_trace.rb index 4272603df01..cd94cc69afd 100644 --- a/lib/ddtrace/transport/serializable_trace.rb +++ b/lib/ddtrace/transport/serializable_trace.rb @@ -31,7 +31,7 @@ def to_msgpack(packer = nil) # JSON serializer interface. # Used by older version of the transport. def to_json(*args) - trace.spans.map(&:to_hash).to_json(*args) + trace.spans.map { |s| SerializableSpan.new(s).to_hash }.to_json(*args) end end @@ -102,7 +102,7 @@ def to_msgpack(packer = nil) # JSON serializer interface. # Used by older version of the transport. def to_json(*args) - span.to_hash.to_json(*args) + to_hash.to_json(*args) end # Used for serialization @@ -111,6 +111,10 @@ def time_nano(time) time.to_i * 1000000000 + time.nsec end + def to_hash + span.to_hash + end + # Used for serialization # @return [Integer] in nanoseconds since Epoch def duration_nano(duration) diff --git a/spec/ddtrace/transport/serializable_trace_spec.rb b/spec/ddtrace/transport/serializable_trace_spec.rb index 0cecaf71653..c6ec72aff54 100644 --- a/spec/ddtrace/transport/serializable_trace_spec.rb +++ b/spec/ddtrace/transport/serializable_trace_spec.rb @@ -111,12 +111,11 @@ end end - # DEV: confirm? context 'when given 128 bits trace id' do let(:trace_id) { 0xaaaaaaaaaaaaaaaaffffffffffffffff } - it 'serializes 128 bits trace id entirely' do - expect(unpacked_trace.map { |s| s['trace_id'] }).to all(eq(0xaaaaaaaaaaaaaaaaffffffffffffffff)) + it 'serializes the low order 64 bits trace id' do + expect(unpacked_trace.map { |s| s['trace_id'] }).to all(eq(0xffffffffffffffff)) end end end