Skip to content

Commit

Permalink
fix parent_id formatting inconsistency (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored May 10, 2021
1 parent 684f57d commit 6f30160
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1811](https://github.com/open-telemetry/opentelemetry-python/pull/1811))
- Improve warning when failing to decode byte attribute
([#1810](https://github.com/open-telemetry/opentelemetry-python/pull/1810))
- Fixed inconsistency in parent_id formatting from the ConsoleSpanExporter
([#1833](https://github.com/open-telemetry/opentelemetry-python/pull/1833))

### Removed
- Moved `opentelemetry-instrumentation` to contrib repository.
Expand Down
8 changes: 6 additions & 2 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,13 @@ def to_json(self, indent=4):
if self.parent is not None:
if isinstance(self.parent, Span):
ctx = self.parent.context
parent_id = trace_api.format_span_id(ctx.span_id)
parent_id = "0x{}".format(
trace_api.format_span_id(ctx.span_id)
)
elif isinstance(self.parent, SpanContext):
parent_id = trace_api.format_span_id(self.parent.span_id)
parent_id = "0x{}".format(
trace_api.format_span_id(self.parent.span_id)
)

start_time = None
if self._start_time:
Expand Down
9 changes: 6 additions & 3 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,10 @@ def test_to_json(self):
is_remote=False,
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
)
span = trace._Span("span-name", context, resource=Resource({}))
parent = trace._Span("parent-name", context, resource=Resource({}))
span = trace._Span(
"span-name", context, resource=Resource({}), parent=parent
)

self.assertEqual(
span.to_json(),
Expand All @@ -1233,7 +1236,7 @@ def test_to_json(self):
"trace_state": "[]"
},
"kind": "SpanKind.INTERNAL",
"parent_id": null,
"parent_id": "0x00000000deadbef0",
"start_time": null,
"end_time": null,
"status": {
Expand All @@ -1247,7 +1250,7 @@ def test_to_json(self):
)
self.assertEqual(
span.to_json(indent=None),
'{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "[]"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "status": {"status_code": "UNSET"}, "attributes": {}, "events": [], "links": [], "resource": {}}',
'{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "[]"}, "kind": "SpanKind.INTERNAL", "parent_id": "0x00000000deadbef0", "start_time": null, "end_time": null, "status": {"status_code": "UNSET"}, "attributes": {}, "events": [], "links": [], "resource": {}}',
)

def test_attributes_to_json(self):
Expand Down

0 comments on commit 6f30160

Please sign in to comment.