Skip to content

Commit fbce7a5

Browse files
committed
Keep using one warning
1 parent 0095883 commit fbce7a5

File tree

7 files changed

+59
-138
lines changed

7 files changed

+59
-138
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515

1616
from opentelemetry.sdk._logs._internal import (
1717
LogData,
18-
LogLimitsInitDeprecatedWarning,
19-
LogRecordInitDeprecatedWarning,
20-
LogDataInitDeprecatedWarning,
21-
LogRecordContextDeprecatedWarning,
22-
InMemoryLogExporterDeprecatedWarning,
23-
ConsoleLogExporterDeprecatedWarning,
18+
LogDeprecatedInitWarning,
2419
LogDroppedAttributesWarning,
2520
Logger,
2621
LoggerProvider,
@@ -38,11 +33,6 @@
3833
"LogLimits",
3934
"LogRecord",
4035
"LogRecordProcessor",
41-
"LogLimitsInitDeprecatedWarning",
42-
"LogRecordInitDeprecatedWarning",
36+
"LogDeprecatedInitWarning",
4337
"LogDroppedAttributesWarning",
44-
"LogDataInitDeprecatedWarning",
45-
"LogRecordContextDeprecatedWarning",
46-
"InMemoryLogExporterDeprecatedWarning",
47-
"ConsoleLogExporterDeprecatedWarning",
4838
]

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -84,76 +84,16 @@ class LogDroppedAttributesWarning(UserWarning):
8484
warnings.simplefilter("once", LogDroppedAttributesWarning)
8585

8686

87-
class LogLimitsInitDeprecatedWarning(UserWarning):
88-
"""Custom warning to indicate deprecated LogLimits init was used.
87+
class LogDeprecatedInitWarning(UserWarning):
88+
"""Custom warning to indicate that deprecated and soon to be deprecated Log classes was used.
8989
9090
This class is used to filter and handle these specific warnings separately
9191
from other warnings, ensuring that they are only shown once without
9292
interfering with default user warnings.
9393
"""
9494

9595

96-
warnings.simplefilter("once", LogLimitsInitDeprecatedWarning)
97-
98-
99-
class LogRecordInitDeprecatedWarning(UserWarning):
100-
"""Custom warning to indicate deprecated LogRecord init was used.
101-
102-
This class is used to filter and handle these specific warnings separately
103-
from other warnings, ensuring that they are only shown once without
104-
interfering with default user warnings.
105-
"""
106-
107-
108-
warnings.simplefilter("once", LogRecordInitDeprecatedWarning)
109-
110-
111-
class LogDataInitDeprecatedWarning(UserWarning):
112-
"""Custom warning to indicate deprecated LogData init was used.
113-
114-
This class is used to filter and handle these specific warnings separately
115-
from other warnings, ensuring that they are only shown once without
116-
interfering with default user warnings.
117-
"""
118-
119-
120-
warnings.simplefilter("once", LogDataInitDeprecatedWarning)
121-
122-
123-
class LogRecordContextDeprecatedWarning(UserWarning):
124-
"""Custom warning to indicate LogRecord was initialized without using context.
125-
126-
This class is used to filter and handle these specific warnings separately
127-
from other warnings, ensuring that they are only shown once without
128-
interfering with default user warnings.
129-
"""
130-
131-
132-
warnings.simplefilter("once", LogRecordContextDeprecatedWarning)
133-
134-
135-
class InMemoryLogExporterDeprecatedWarning(UserWarning):
136-
"""Custom warning to indicate InMemoryLogExporter is deprecated.
137-
138-
This class is used to filter and handle these specific warnings separately
139-
from other warnings, ensuring that they are only shown once without
140-
interfering with default user warnings.
141-
"""
142-
143-
144-
warnings.simplefilter("once", LogRecordContextDeprecatedWarning)
145-
146-
147-
class ConsoleLogExporterDeprecatedWarning(UserWarning):
148-
"""Custom warning to indicate ConsoleLogExporter is deprecated.
149-
150-
This class is used to filter and handle these specific warnings separately
151-
from other warnings, ensuring that they are only shown once without
152-
interfering with default user warnings.
153-
"""
154-
155-
156-
warnings.simplefilter("once", ConsoleLogExporterDeprecatedWarning)
96+
warnings.simplefilter("once", LogDeprecatedInitWarning)
15797

15898

15999
class LogLimits:
@@ -209,7 +149,7 @@ def __init__(
209149

210150
warnings.warn(
211151
"LogLimits will be deprecated in 1.39.0 and then renamed to LogRecordLimits",
212-
LogLimitsInitDeprecatedWarning,
152+
LogDeprecatedInitWarning,
213153
stacklevel=0,
214154
)
215155

@@ -302,7 +242,7 @@ def __init__( # pylint:disable=too-many-locals
302242
):
303243
warnings.warn(
304244
"LogRecord will be substituted in 1.39.0 by ReadWriteLogRecord and ReadableLogRecord",
305-
LogRecordInitDeprecatedWarning,
245+
LogDeprecatedInitWarning,
306246
stacklevel=0,
307247
)
308248
if not context:
@@ -311,7 +251,7 @@ def __init__( # pylint:disable=too-many-locals
311251
if trace_id or span_id or trace_flags:
312252
warnings.warn(
313253
"LogRecord init with `trace_id`, `span_id`, and/or `trace_flags` is deprecated since 1.35.0. Use `context` instead.",
314-
LogRecordContextDeprecatedWarning,
254+
LogDeprecatedInitWarning,
315255
stacklevel=2,
316256
)
317257

@@ -431,7 +371,7 @@ def __init__(
431371
):
432372
warnings.warn(
433373
"LogData will be substituted in 1.39.0 by ReadWriteLogRecord and ReadableLogRecord",
434-
LogDataInitDeprecatedWarning,
374+
LogDeprecatedInitWarning,
435375
stacklevel=0,
436376
)
437377
self.log_record = log_record

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from opentelemetry.sdk._logs import (
3131
LogData,
32-
ConsoleLogExporterDeprecatedWarning,
32+
LogDeprecatedInitWarning,
3333
LogRecord,
3434
LogRecordProcessor,
3535
)
@@ -101,7 +101,7 @@ def __init__(
101101

102102
warnings.warn(
103103
"ConsoleLogExporter will be deprecated in 1.39.0 and then renamed to ConsoleLogRecordExporter",
104-
ConsoleLogExporterDeprecatedWarning,
104+
LogDeprecatedInitWarning,
105105
stacklevel=0,
106106
)
107107

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/in_memory_log_exporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import typing
1717
import warnings
1818

19-
from opentelemetry.sdk._logs import LogData, InMemoryLogExporterDeprecatedWarning
19+
from opentelemetry.sdk._logs import LogData, LogDeprecatedInitWarning
2020
from opentelemetry.sdk._logs.export import LogExporter, LogExportResult
2121

2222

@@ -35,7 +35,7 @@ def __init__(self):
3535

3636
warnings.warn(
3737
"InMemoryLogExporter will be deprecated in 1.39.0 and then renamed to InMemoryLogRecordExporter",
38-
InMemoryLogExporterDeprecatedWarning,
38+
LogDeprecatedInitWarning,
3939
stacklevel=0,
4040
)
4141

opentelemetry-sdk/tests/logs/test_export.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
from opentelemetry._logs import SeverityNumber
2828
from opentelemetry.sdk import trace
2929
from opentelemetry.sdk._logs import (
30-
ConsoleLogExporterDeprecatedWarning,
31-
InMemoryLogExporterDeprecatedWarning,
3230
LogData,
31+
LogDeprecatedInitWarning,
3332
LoggerProvider,
3433
LoggingHandler,
3534
LogRecord,
@@ -657,19 +656,17 @@ def test_console_log_exporter_deprecated_warning(self):
657656
warnings.simplefilter("always")
658657
ConsoleLogExporter()
659658

660-
# Check that at least one ConsoleLogExporterDeprecatedWarning was emitted
659+
# Check that at least one LogDeprecatedInitWarning, was emitted
661660
console_warnings = [
662-
w
663-
for w in cw
664-
if isinstance(w.message, ConsoleLogExporterDeprecatedWarning)
661+
w for w in cw if isinstance(w.message, LogDeprecatedInitWarning)
665662
]
666663
self.assertGreater(
667664
len(console_warnings),
668665
0,
669-
"Expected at least one ConsoleLogExporterDeprecatedWarning",
666+
"Expected at least one LogDeprecatedInitWarning",
670667
)
671668

672-
# Check the message content of the ConsoleLogExporterDeprecatedWarning
669+
# Check the message content of the warning
673670
warning_message = str(console_warnings[0].message)
674671
self.assertIn(
675672
"ConsoleLogExporter will be deprecated in 1.39.0 and then renamed to ConsoleLogRecordExporter",
@@ -683,16 +680,14 @@ def test_console_log_exporter_deprecated_warning_once(self):
683680
for _ in range(10):
684681
ConsoleLogExporter()
685682

686-
# Check that exactly one ConsoleLogExporterDeprecatedWarning was emitted
683+
# Check that exactly one LogDeprecatedInitWarning was emitted
687684
console_warnings = [
688-
w
689-
for w in cw
690-
if isinstance(w.message, ConsoleLogExporterDeprecatedWarning)
685+
w for w in cw if isinstance(w.message, LogDeprecatedInitWarning)
691686
]
692687
self.assertEqual(
693688
len(console_warnings),
694689
1,
695-
"Expected exactly one ConsoleLogExporterDeprecatedWarning due to simplefilter('once')",
690+
"Expected exactly one LogDeprecatedInitWarning due to simplefilter('once')",
696691
)
697692

698693
# Check the message content
@@ -710,19 +705,17 @@ def test_in_memory_log_exporter_deprecated_warning(self):
710705
warnings.simplefilter("always")
711706
InMemoryLogExporter()
712707

713-
# Check that at least one InMemoryLogExporterDeprecatedWarning was emitted
708+
# Check that at least one LogDeprecatedInitWarning was emitted
714709
in_memory_warnings = [
715-
w
716-
for w in cw
717-
if isinstance(w.message, InMemoryLogExporterDeprecatedWarning)
710+
w for w in cw if isinstance(w.message, LogDeprecatedInitWarning)
718711
]
719712
self.assertGreater(
720713
len(in_memory_warnings),
721714
0,
722-
"Expected at least one InMemoryLogExporterDeprecatedWarning",
715+
"Expected at least one LogDeprecatedInitWarning",
723716
)
724717

725-
# Check the message content of the InMemoryLogExporterDeprecatedWarning
718+
# Check the message content of the warning
726719
warning_message = str(in_memory_warnings[0].message)
727720
self.assertIn(
728721
"InMemoryLogExporter will be deprecated in 1.39.0 and then renamed to InMemoryLogRecordExporter",
@@ -736,16 +729,14 @@ def test_in_memory_log_exporter_deprecated_warning_once(self):
736729
for _ in range(10):
737730
InMemoryLogExporter()
738731

739-
# Check that exactly one InMemoryLogExporterDeprecatedWarning was emitted
732+
# Check that exactly one LogDeprecatedInitWarning was emitted
740733
in_memory_warnings = [
741-
w
742-
for w in cw
743-
if isinstance(w.message, InMemoryLogExporterDeprecatedWarning)
734+
w for w in cw if isinstance(w.message, LogDeprecatedInitWarning)
744735
]
745736
self.assertEqual(
746737
len(in_memory_warnings),
747738
1,
748-
"Expected exactly one InMemoryLogExporterDeprecatedWarning due to simplefilter('once')",
739+
"Expected exactly one LogDeprecatedInitWarning due to simplefilter('once')",
749740
)
750741

751742
# Check the message content

opentelemetry-sdk/tests/logs/test_log_limits.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import warnings
1717
from unittest.mock import patch
1818

19-
from opentelemetry.sdk._logs import LogLimits, LogLimitsInitDeprecatedWarning
19+
from opentelemetry.sdk._logs import LogDeprecatedInitWarning, LogLimits
2020
from opentelemetry.sdk._logs._internal import (
2121
_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT,
2222
)
@@ -79,7 +79,7 @@ def test_log_limits_init_deprecated_warning(self):
7979
LogLimits()
8080

8181
self.assertEqual(len(cw), 1)
82-
self.assertIsInstance(cw[-1].message, LogLimitsInitDeprecatedWarning)
82+
self.assertIsInstance(cw[-1].message, LogDeprecatedInitWarning)
8383
self.assertIn(
8484
"LogLimits will be deprecated in 1.39.0 and then renamed to LogRecordLimits",
8585
str(cw[-1].message),
@@ -92,7 +92,7 @@ def test_log_limits_init_deprecated_warning_with_params(self):
9292
LogLimits(max_attributes=10, max_attribute_length=100)
9393

9494
self.assertEqual(len(cw), 1)
95-
self.assertIsInstance(cw[-1].message, LogLimitsInitDeprecatedWarning)
95+
self.assertIsInstance(cw[-1].message, LogDeprecatedInitWarning)
9696
self.assertIn(
9797
"LogLimits will be deprecated in 1.39.0 and then renamed to LogRecordLimits",
9898
str(cw[-1].message),
@@ -106,7 +106,7 @@ def test_log_limits_init_deprecated_warning_once(self):
106106
LogLimits()
107107

108108
self.assertEqual(len(cw), 1)
109-
self.assertIsInstance(cw[-1].message, LogLimitsInitDeprecatedWarning)
109+
self.assertIsInstance(cw[-1].message, LogDeprecatedInitWarning)
110110
self.assertIn(
111111
"LogLimits will be deprecated in 1.39.0 and then renamed to LogRecordLimits",
112112
str(cw[-1].message),

0 commit comments

Comments
 (0)