Skip to content

Commit

Permalink
Conform zipkin traceId, spanId, parentId specs
Browse files Browse the repository at this point in the history
Using v1 API defined in https://github.com/openzipkin/zipkin-api/blob/7692ca7be4dc3be9225db550d60c4d30e6e9ec59/zipkin-api.yaml

traceId to 32 character lowercase hex string
spanId to 16 character lowercase hex string
parentId to be absent for root span
  • Loading branch information
praxist committed Jul 22, 2021
1 parent 15b60b7 commit fc66d51
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions baseplate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion baseplate/observers/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit fc66d51

Please sign in to comment.