diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cbeab987c9..6106b889b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Logs: ObservedTimestamp field is missing in console exporter output + ([#3564](https://github.com/open-telemetry/opentelemetry-python/pull/3564)) - Fix explicit bucket histogram aggregation ([#3429](https://github.com/open-telemetry/opentelemetry-python/pull/3429)) - Add `code.lineno`, `code.function` and `code.filepath` to all logs diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 50d918ea8c3..046025754b3 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -206,6 +206,7 @@ def to_json(self, indent=4) -> str: else None, "dropped_attributes": self.dropped_attributes, "timestamp": ns_to_iso_str(self.timestamp), + "observed_timestamp": ns_to_iso_str(self.observed_timestamp), "trace_id": f"0x{format_trace_id(self.trace_id)}" if self.trace_id is not None else "", diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index 1f0bd785a85..6a33db101c8 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -29,6 +29,7 @@ def test_log_record_to_json(self): "attributes": None, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", + "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": None, @@ -38,6 +39,7 @@ def test_log_record_to_json(self): ) actual = LogRecord( timestamp=0, + observed_timestamp=0, body="a log line", ).to_json() self.assertEqual(expected, actual)