Skip to content

Commit

Permalink
LogRecord Resource Serialization
Browse files Browse the repository at this point in the history
Currently, the `LogRecord.to_json`
method serializes the resource object
using `repr` of its attributes. This
differs from how the serialization
process is handled in `ReadableSpan.to_json`
and `MetricsData.to_json`, which utilize the
`Resource.to_json` functionality directly.
Using `repr` does not produce a json-parseable
output and doesn't follow the same depth of
serialization as the other two signal types.
Therefore, this change carries over the
serialization process from the spans and
metrics signal types to the logs type.

Fixes open-telemetry#3345
  • Loading branch information
sernst committed Jun 13, 2023
1 parent 92bfd08 commit b5e76c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def to_json(self, indent=4) -> str:
if self.span_id is not None
else "",
"trace_flags": self.trace_flags,
"resource": repr(self.resource.attributes)
"resource": json.loads(self.resource.to_json())
if self.resource
else "",
else None,
},
indent=indent,
)
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/logs/test_log_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_log_record_to_json(self):
"trace_id": "",
"span_id": "",
"trace_flags": None,
"resource": "",
"resource": None,
},
indent=4,
)
Expand Down

0 comments on commit b5e76c0

Please sign in to comment.