Skip to content

Commit

Permalink
Include parent span in Jaeger gRPC export
Browse files Browse the repository at this point in the history
This extracts the parent span and adds it as a CHILD_OF reference in the
gRPC export, so that we get the expected hierarchy of spans.

Test case is updated to cover this case.
  • Loading branch information
plajjan committed May 3, 2021
1 parent 300ce1b commit 407d055
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,18 @@ def _extract_tags(
def _extract_refs(
self, span: ReadableSpan
) -> Optional[Sequence[model_pb2.SpanRef]]:
if not span.links:
return None

refs = []
if span.parent:
ctx = span.get_span_context()
parent_id = span.parent.span_id
parent_ref = model_pb2.SpanRef(
ref_type=model_pb2.SpanRefType.CHILD_OF,
trace_id=_trace_id_to_bytes(ctx.trace_id),
span_id=_span_id_to_bytes(parent_id),
)
refs.append(parent_ref)

for link in span.links:
trace_id = link.context.trace_id
span_id = link.context.span_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ def test_translate_to_jaeger(self):
),
],
references=[
model_pb2.SpanRef(
ref_type=model_pb2.SpanRefType.CHILD_OF,
trace_id=pb_translator._trace_id_to_bytes(trace_id),
span_id=pb_translator._span_id_to_bytes(parent_id),
),
model_pb2.SpanRef(
ref_type=model_pb2.SpanRefType.FOLLOWS_FROM,
trace_id=pb_translator._trace_id_to_bytes(trace_id),
Expand Down

0 comments on commit 407d055

Please sign in to comment.