From 86343c70b0406f2cd4f186968842e5de25e3eaf9 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Wed, 29 Nov 2023 19:12:02 +0200 Subject: [PATCH] fix: profiling: properly format trace context strings (#372) * fix: profiling: properly format trace context strings * chore: update changelog --- CHANGELOG.md | 2 ++ splunk_otel/profiling/__init__.py | 4 ++-- tests/unit/test_profiling.py | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac5ea1a9..1669119a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased - Upgraded Otel dependencies to 1.21.0 / 0.42b0 +- Fix trace and span id formatting for profiling + [#372](https://github.com/signalfx/splunk-otel-python/pull/372) ## 1.15.0 - 2023-11-15 diff --git a/splunk_otel/profiling/__init__.py b/splunk_otel/profiling/__init__.py index 27777260..0c75ccf8 100644 --- a/splunk_otel/profiling/__init__.py +++ b/splunk_otel/profiling/__init__.py @@ -226,12 +226,12 @@ def get_location(frame): trace_id_label = profile_pb2.Label() trace_id_label.key = trace_id_key - trace_id_label.str = str_table.index(f"{trace_id:#016x}") + trace_id_label.str = str_table.index(f"{trace_id:016x}") labels.append(trace_id_label) span_id_label = profile_pb2.Label() span_id_label.key = span_id_key - span_id_label.str = str_table.index(f"{span_id:#08x}") + span_id_label.str = str_table.index(f"{span_id:08x}") labels.append(span_id_label) sample = profile_pb2.Sample() diff --git a/tests/unit/test_profiling.py b/tests/unit/test_profiling.py index f6c69594..fbae60f8 100644 --- a/tests/unit/test_profiling.py +++ b/tests/unit/test_profiling.py @@ -164,10 +164,12 @@ def _assert_log_record(self, log_record): self.assertGreater(len(file_name), 0) if function_name == "do_work": - span_id = int(strings[find_label(sample, "span_id", strings).str], 16) - trace_id = int( - strings[find_label(sample, "trace_id", strings).str], 16 - ) + span_id_str = strings[find_label(sample, "span_id", strings).str] + trace_id_str = strings[find_label(sample, "trace_id", strings).str] + self.assertFalse(span_id_str.startswith("0x")) + self.assertFalse(trace_id_str.startswith("0x")) + span_id = int(span_id_str, 16) + trace_id = int(trace_id_str, 16) self.assertEqual(span_id, self.span_id) self.assertEqual(trace_id, self.trace_id) return True