Skip to content

Commit

Permalink
Fix matching of decoded span ids from profiles
Browse files Browse the repository at this point in the history
Pprof decodes numeric labels as signed 64-bit values BUT as a slight
cheat both the profiler and the backend interpret them as unsigned
64-bit values so we can represent the full 64-bit values used for span
ids in traces.

But we were not accounting for this in our tests, so the decoded pprofs
we use for testing were not matching the expected values.

I've tweaked the pprof test reading code to account for this.
  • Loading branch information
ivoanjo committed Jun 17, 2024
1 parent a22a49c commit a99f0e5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions spec/datadog/profiling/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ def samples_from_pprof(pprof_data)
sample.location_id.map { |location_id| decode_frame_from_pprof(decoded_profile, location_id) },
pretty_sample_types.zip(sample.value).to_h,
sample.label.map do |it|
[
string_table[it.key].to_sym,
it.num == 0 ? string_table[it.str] : it.num,
]
key = string_table[it.key].to_sym
[key, (it.num == 0 ? string_table[it.str] : ProfileHelpers.maybe_fix_label_range(key, it.num))]
end.to_h,
).freeze
end
Expand Down Expand Up @@ -103,6 +101,16 @@ def build_stack_recorder(
timeline_enabled: timeline_enabled,
)
end

def self.maybe_fix_label_range(key, value)
if [:'local root span id', :'span id'].include?(key) && value < 0
# pprof labels are defined to be decoded as signed values BUT the backend explicitly interprets these as unsigned
# 64-bit numbers so we can still use them for these ids without having to fall back to strings
value + 2**64
else
value
end
end
end

RSpec.configure do |config|
Expand Down

0 comments on commit a99f0e5

Please sign in to comment.