Skip to content

Commit 3a8d19e

Browse files
authored
Fix JSON serialization
Parent span ID also needs the special hex serialization
1 parent d4c3c39 commit 3a8d19e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/partial_span_processor/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ def get_log_data(self, span: Span, attributes: dict[str, str]) -> LogData:
121121
instrumentation_scope = span.instrumentation_scope if hasattr(span,
122122
"instrumentation_scope") else None
123123
span_context = span.get_span_context()
124+
parent = span.parent
124125

125126
enc_spans = encode_spans([span]).resource_spans
126127
traces_data = trace_pb2.TracesData()
127128
traces_data.resource_spans.extend(enc_spans)
128129
serialized_traces_data = json_format.MessageToJson(traces_data)
129130

130-
# FIXME/HACK replace serialized traceId and spanId values as string comparison
131+
# FIXME/HACK replace serialized traceId, spanId, and parentSpanId (if present) values as string comparison
131132
# possible issue is when there are multiple spans in the same trace.
132133
# currently that should not be the case.
133134
# trace_id and span_id are stored as int.
@@ -139,7 +140,10 @@ def get_log_data(self, span: Span, attributes: dict[str, str]) -> LogData:
139140
for span in scope_span.get("spans", []):
140141
span["traceId"] = hex(span_context.trace_id)[2:]
141142
span["spanId"] = hex(span_context.span_id)[2:]
142-
serialized_traces_data = json.dumps(traces_dict, separators=(',', ':'))
143+
if parent:
144+
span["parentSpanId"] = hex(parent.span_id)[2:]
145+
146+
serialized_traces_data = json.dumps(traces_dict, separators=(",", ":"))
143147

144148
log_record = LogRecord(
145149
timestamp=time.time_ns(),

0 commit comments

Comments
 (0)