Skip to content

Commit

Permalink
fix: profiling: properly format trace context strings (#372)
Browse files Browse the repository at this point in the history
* fix: profiling: properly format trace context strings

* chore: update changelog
  • Loading branch information
seemk authored Nov 29, 2023
1 parent 4f94ee6 commit 86343c7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions splunk_otel/profiling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/test_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86343c7

Please sign in to comment.