Skip to content

Commit 24d1914

Browse files
committed
Add test for logdata warnings
1 parent 438bb7e commit 24d1914

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

opentelemetry-sdk/tests/logs/test_log_record.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
from opentelemetry.attributes import BoundedAttributes
2222
from opentelemetry.context import get_current
2323
from opentelemetry.sdk._logs import (
24+
LogData,
2425
LogDeprecatedInitWarning,
2526
LogDroppedAttributesWarning,
2627
LogLimits,
2728
LogRecord,
2829
)
2930
from opentelemetry.sdk.resources import Resource
31+
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
3032
from opentelemetry.trace.span import TraceFlags
3133

3234

@@ -222,7 +224,7 @@ def test_log_record_context_deprecated_init_warning(self):
222224
self.assertEqual(len(log_record_context_warning), 0)
223225

224226
def test_log_record_init_deprecated_warning(self):
225-
"""Test that LogRecord initialization emits a LogRecordInitDeprecatedWarning."""
227+
"""Test that LogRecord initialization emits a LogDeprecatedInitWarning."""
226228
with warnings.catch_warnings(record=True) as cw:
227229
warnings.simplefilter("always")
228230
LogRecord()
@@ -234,10 +236,10 @@ def test_log_record_init_deprecated_warning(self):
234236
self.assertGreater(
235237
len(log_record_init_warnings),
236238
0,
237-
"Expected at least one LogRecordInitDeprecatedWarning",
239+
"Expected at least one LogDeprecatedInitWarning",
238240
)
239241

240-
# Check the message content of the LogRecordInitDeprecatedWarning
242+
# Check the message content of the LogDeprecatedInitWarning
241243
warning_message = str(log_record_init_warnings[0].message)
242244
self.assertIn(
243245
"LogRecord will be removed in 1.39.0 and replaced by ReadWriteLogRecord and ReadableLogRecord",
@@ -277,3 +279,33 @@ def test_log_record_from_api_log_record(self):
277279
self.assertEqual(record.attributes, {"a": "b"})
278280
self.assertEqual(record.event_name, "an.event")
279281
self.assertEqual(record.resource, resource)
282+
283+
284+
class TestLogData(unittest.TestCase):
285+
def test_init_deprecated_warning(self):
286+
"""Test that LogData initialization emits a LogDeprecatedInitWarning."""
287+
log_record = LogRecord()
288+
289+
with warnings.catch_warnings(record=True) as cw:
290+
warnings.simplefilter("always")
291+
LogData(
292+
log_record=log_record,
293+
instrumentation_scope=InstrumentationScope("foo", "bar"),
294+
)
295+
296+
# Check that at least one LogDeprecatedInitWarning was emitted
297+
init_warnings = [
298+
w for w in cw if isinstance(w.message, LogDeprecatedInitWarning)
299+
]
300+
self.assertGreater(
301+
len(init_warnings),
302+
0,
303+
"Expected at least one LogDeprecatedInitWarning",
304+
)
305+
306+
# Check the message content of the LogDeprecatedInitWarning
307+
warning_message = str(init_warnings[0].message)
308+
self.assertIn(
309+
"LogData will be removed in 1.39.0 and replaced by ReadWriteLogRecord and ReadableLogRecord",
310+
warning_message,
311+
)

0 commit comments

Comments
 (0)