Skip to content

Commit

Permalink
Improve time reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Sep 10, 2020
1 parent b803a84 commit 9c56859
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/ddtrace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def to_hash
}

if !@start_time.nil? && !@end_time.nil?
h[:start] = (@start_time.to_f * 1e9).to_i
h[:duration] = ((@end_time - @start_time) * 1e9).to_i
h[:start] = start_time_nano
h[:duration] = duration_nano
end

h
Expand All @@ -272,10 +272,10 @@ def to_msgpack(packer = nil)
packer.write_map_header(13) # Set header with how many elements in the map

packer.write('start')
packer.write((@start_time.to_f * 1e9).to_i)
packer.write(start_time_nano)

packer.write('duration')
packer.write(((@end_time - @start_time) * 1e9).to_i)
packer.write(duration_nano)
else
packer.write_map_header(11) # Set header with how many elements in the map
end
Expand Down Expand Up @@ -363,5 +363,17 @@ def now_allocations
GC.stat(:total_allocated_objects)
end
end

# Used for serialization
# @return [Integer] in nanoseconds since Epoch
def start_time_nano
@start_time.to_i * 1000000000 + @start_time.nsec
end

# Used for serialization
# @return [Integer] in nanoseconds since Epoch
def duration_nano
((@end_time - @start_time) * 1e9).to_i
end
end
end

0 comments on commit 9c56859

Please sign in to comment.