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 a63486a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased
- Use BoundedAttributes instead of raw dict to extract attributes from LogRecord and Support dropped_attributes_count in LogRecord ([#3310](https://github.com/open-telemetry/opentelemetry-python/pull/3310))
- LogRecord now JSON serializes resource objects to match ReadableSpan and MetricsData equivalents ([#3345](https://github.com/open-telemetry/opentelemetry-python/issues/3345))

## Version 1.18.0/0.39b0 (2023-05-04)

- Select histogram aggregation with an environment variable
Expand Down
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 a63486a

Please sign in to comment.