Skip to content

Commit

Permalink
Fix serializable trace legacy JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Jan 24, 2023
1 parent 26d5ca3 commit 82c343e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/ddtrace/transport/serializable_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions spec/ddtrace/transport/serializable_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82c343e

Please sign in to comment.