diff --git a/baseplate/__init__.py b/baseplate/__init__.py index 4fe8ccbac..1230fb160 100644 --- a/baseplate/__init__.py +++ b/baseplate/__init__.py @@ -124,8 +124,9 @@ def new(cls) -> "TraceInfo": with any upstream requests. """ - trace_id = str(random.getrandbits(64)) - return cls(trace_id=trace_id, parent_id=None, span_id=trace_id, sampled=None, flags=None) + trace_id = "{0:0{1}x}".format(random.getrandbits(128), 32) + span_id = "{0:0{1}x}".format(random.getrandbits(64), 16) + return cls(trace_id=trace_id, parent_id=None, span_id=span_id, sampled=None, flags=None) @classmethod def from_upstream( diff --git a/baseplate/observers/tracing.py b/baseplate/observers/tracing.py index 7a3021270..594c18530 100644 --- a/baseplate/observers/tracing.py +++ b/baseplate/observers/tracing.py @@ -279,7 +279,9 @@ def _to_span_obj( "binaryAnnotations": binary_annotations, } - span["parentId"] = self.span.parent_id or 0 + if self.span.parent_id: + span["parentId"] = self.span.parent_id + return span def _serialize(self) -> Dict[str, Any]: