Skip to content

Commit

Permalink
Merge pull request #2476 from DataDog/ivoanjo/prof-6691-numeric-span-id
Browse files Browse the repository at this point in the history
[PROF-6691] Send span id in profiles as number and not string
  • Loading branch information
ivoanjo authored Dec 7, 2022
2 parents 7176d38 + 4480694 commit b9f1099
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ struct trace_identifiers {

bool valid;
ddog_CharSlice local_root_span_id;
ddog_CharSlice span_id;
uint64_t span_id;
char local_root_span_id_buffer[MAXIMUM_LENGTH_64_BIT_IDENTIFIER];
char span_id_buffer[MAXIMUM_LENGTH_64_BIT_IDENTIFIER];
VALUE trace_endpoint;
};

Expand Down Expand Up @@ -583,7 +582,7 @@ static void trigger_sample_for_thread(

if (trace_identifiers_result.valid) {
labels[label_pos++] = (ddog_Label) {.key = DDOG_CHARSLICE_C("local root span id"), .str = trace_identifiers_result.local_root_span_id};
labels[label_pos++] = (ddog_Label) {.key = DDOG_CHARSLICE_C("span id"), .str = trace_identifiers_result.span_id};
labels[label_pos++] = (ddog_Label) {.key = DDOG_CHARSLICE_C("span id"), .num = trace_identifiers_result.span_id};

if (trace_identifiers_result.trace_endpoint != Qnil) {
// The endpoint gets recorded in a different way because it is mutable in the tracer and can change during a
Expand Down Expand Up @@ -870,19 +869,13 @@ static void trace_identifiers_for(struct cpu_and_wall_time_collector_state *stat
if (numeric_local_root_span_id == Qnil || numeric_span_id == Qnil) return;

unsigned long long local_root_span_id = NUM2ULL(numeric_local_root_span_id);
unsigned long long span_id = NUM2ULL(numeric_span_id);

snprintf(trace_identifiers_result->local_root_span_id_buffer, MAXIMUM_LENGTH_64_BIT_IDENTIFIER, "%llu", local_root_span_id);
snprintf(trace_identifiers_result->span_id_buffer, MAXIMUM_LENGTH_64_BIT_IDENTIFIER, "%llu", span_id);

trace_identifiers_result->local_root_span_id = (ddog_CharSlice) {
.ptr = trace_identifiers_result->local_root_span_id_buffer,
.len = strlen(trace_identifiers_result->local_root_span_id_buffer)
};
trace_identifiers_result->span_id = (ddog_CharSlice) {
.ptr = trace_identifiers_result->span_id_buffer,
.len = strlen(trace_identifiers_result->span_id_buffer)
};
trace_identifiers_result->span_id = NUM2ULL(numeric_span_id);

trace_identifiers_result->valid = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def stats

expect(t1_sample.fetch(:labels)).to include(
:'local root span id' => @t1_local_root_span_id.to_s,
:'span id' => @t1_span_id.to_s,
:'span id' => @t1_span_id.to_i,
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/profiling/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def samples_from_pprof(pprof_data)
labels: sample.label.map do |it|
[
string_table[it.key].to_sym,
it.num == 0 ? string_table[it.str] : raise('Unexpected: label encoded as number instead of string'),
it.num == 0 ? string_table[it.str] : it.num,
]
end.to_h,
}
Expand Down

0 comments on commit b9f1099

Please sign in to comment.