Skip to content

Commit 5769784

Browse files
authored
Fix JSON serialization when a parent span exists (#28)
* Fix JSON serialization Parent span ID also needs the special hex serialization * Bump version to 0.0.8
1 parent d4c3c39 commit 5769784

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "partial_span_processor"
7-
version = "0.0.7"
7+
version = "0.0.8"
88
authors = [
99
{ name = "Mladjan Gadzic", email = "[email protected]" }
1010
]

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)