diff --git a/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c b/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c index 179391c950a..4d738df306d 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +++ b/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c @@ -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; }; @@ -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 @@ -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; diff --git a/spec/datadog/profiling/collectors/cpu_and_wall_time_spec.rb b/spec/datadog/profiling/collectors/cpu_and_wall_time_spec.rb index e3d56dd376a..6885ebe22ab 100644 --- a/spec/datadog/profiling/collectors/cpu_and_wall_time_spec.rb +++ b/spec/datadog/profiling/collectors/cpu_and_wall_time_spec.rb @@ -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 diff --git a/spec/datadog/profiling/spec_helper.rb b/spec/datadog/profiling/spec_helper.rb index 71dd0856111..8b24c5ad19e 100644 --- a/spec/datadog/profiling/spec_helper.rb +++ b/spec/datadog/profiling/spec_helper.rb @@ -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, }