diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 22cf273c6d7..0e85b464c33 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -440,7 +440,7 @@ def _get_attributes(self, record: logging.LogRecord) -> Attributes: attributes = { k: v for k, v in vars(record).items() - if k not in _EXCLUDED_ATTRIBUTES + if k not in _EXCLUDED_ATTRIBUTES and v is not None } # Add standard code attributes for logs. diff --git a/opentelemetry-sdk/tests/logs/test_handler.py b/opentelemetry-sdk/tests/logs/test_handler.py index 079aae2b466..2bd82efd464 100644 --- a/opentelemetry-sdk/tests/logs/test_handler.py +++ b/opentelemetry-sdk/tests/logs/test_handler.py @@ -114,7 +114,6 @@ def test_log_record_user_attributes(self): log_record = args[0] self.assertIsNotNone(log_record) - self.assertEqual(len(log_record.attributes), 4) self.assertEqual( log_record.attributes, {**log_record.attributes, **{"http.status_code": 200}},