Skip to content

Commit cc18b73

Browse files
authored
Include parent span in Jaeger gRPC export (#1809)
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.
1 parent f7358e9 commit cc18b73

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.1.0...HEAD)
88

9+
### Changed
10+
- Include span parent in Jaeger gRPC export as `CHILD_OF` reference
11+
([#1809])(https://github.com/open-telemetry/opentelemetry-python/pull/1809)
12+
913
### Added
1014
- Added example for running Django with auto instrumentation.
1115
([#1803](https://github.com/open-telemetry/opentelemetry-python/pull/1803))

Diff for: exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,18 @@ def _extract_tags(
318318
def _extract_refs(
319319
self, span: ReadableSpan
320320
) -> Optional[Sequence[model_pb2.SpanRef]]:
321-
if not span.links:
322-
return None
323321

324322
refs = []
323+
if span.parent:
324+
ctx = span.get_span_context()
325+
parent_id = span.parent.span_id
326+
parent_ref = model_pb2.SpanRef(
327+
ref_type=model_pb2.SpanRefType.CHILD_OF,
328+
trace_id=_trace_id_to_bytes(ctx.trace_id),
329+
span_id=_span_id_to_bytes(parent_id),
330+
)
331+
refs.append(parent_ref)
332+
325333
for link in span.links:
326334
trace_id = link.context.trace_id
327335
span_id = link.context.span_id

Diff for: exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,16 @@ def test_translate_to_jaeger(self):
287287
),
288288
],
289289
references=[
290+
model_pb2.SpanRef(
291+
ref_type=model_pb2.SpanRefType.CHILD_OF,
292+
trace_id=pb_translator._trace_id_to_bytes(trace_id),
293+
span_id=pb_translator._span_id_to_bytes(parent_id),
294+
),
290295
model_pb2.SpanRef(
291296
ref_type=model_pb2.SpanRefType.FOLLOWS_FROM,
292297
trace_id=pb_translator._trace_id_to_bytes(trace_id),
293298
span_id=pb_translator._span_id_to_bytes(other_id),
294-
)
299+
),
295300
],
296301
logs=[
297302
model_pb2.Log(

0 commit comments

Comments
 (0)