Skip to content

Commit

Permalink
Merge branch 'main' into rm-assertequal-instrinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi authored Nov 26, 2024
2 parents 53fefaa + 1ee2774 commit 8612c21
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4270](https://github.com/open-telemetry/opentelemetry-python/pull/4270))
- api: fix logging of duplicate EventLogger setup warning
([#4299](https://github.com/open-telemetry/opentelemetry-python/pull/4299))
- sdk: fix setting of process owner in ProcessResourceDetector
([#4311](https://github.com/open-telemetry/opentelemetry-python/pull/4311))
- sdk: fix serialization of logs severity_number field to int
([#4324](https://github.com/open-telemetry/opentelemetry-python/pull/4324))
- Remove `TestBase.assertEqualSpanInstrumentationInfo` method, use `assertEqualSpanInstrumentationScope` instead
([#4310](https://github.com/open-telemetry/opentelemetry-python/pull/4310))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def to_json(self, indent=4) -> str:
return json.dumps(
{
"body": self.body,
"severity_number": repr(self.severity_number),
"severity_number": self.severity_number.value
if self.severity_number is not None
else None,
"severity_text": self.severity_text,
"attributes": (
dict(self.attributes) if bool(self.attributes) else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
try:
import psutil as psutil_module

pustil = psutil_module
psutil = psutil_module
except ImportError:
pass

Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ importlib-metadata==6.11.0
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
psutil==5.9.6; sys_platform != 'win32'
py-cpuinfo==9.0.0
pytest==7.4.4
tomli==2.0.1
Expand Down
17 changes: 15 additions & 2 deletions opentelemetry-sdk/tests/logs/test_log_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest
import warnings

from opentelemetry._logs.severity import SeverityNumber
from opentelemetry.attributes import BoundedAttributes
from opentelemetry.sdk._logs import (
LogDroppedAttributesWarning,
Expand All @@ -30,7 +31,7 @@ def test_log_record_to_json(self):
expected = json.dumps(
{
"body": "a log line",
"severity_number": "None",
"severity_number": None,
"severity_text": None,
"attributes": None,
"dropped_attributes": 0,
Expand All @@ -56,9 +57,21 @@ def test_log_record_to_json(self):
self.assertEqual(expected, actual.to_json(indent=4))
self.assertEqual(
actual.to_json(indent=None),
'{"body": "a log line", "severity_number": "None", "severity_text": null, "attributes": null, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}',
'{"body": "a log line", "severity_number": null, "severity_text": null, "attributes": null, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}',
)

def test_log_record_to_json_serializes_severity_number_as_int(self):
actual = LogRecord(
timestamp=0,
severity_number=SeverityNumber.WARN,
observed_timestamp=0,
body="a log line",
resource=Resource({"service.name": "foo"}),
)

decoded = json.loads(actual.to_json())
self.assertEqual(SeverityNumber.WARN.value, decoded["severity_number"])

def test_log_record_bounded_attributes(self):
attr = {"key": "value"}

Expand Down

0 comments on commit 8612c21

Please sign in to comment.