Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

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 1b47553 commit 798cba7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions baseplate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def new(cls) -> "TraceInfo":
with any upstream requests.
"""
trace_id = 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 Expand Up @@ -767,7 +768,8 @@ def make_child(
:param component_name: Name to identify local component
this span is recording in if it is a local span.
"""
span_id = random.getrandbits(64)
span_id = "{0:0{1}x}".format(random.getrandbits(64), 16)


context_copy = self.context.clone()
span: Span
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 798cba7

Please sign in to comment.