Skip to content

Commit df9af37

Browse files
committed
Update rollback loglimits as arg to loggerprovider
1 parent a0adda0 commit df9af37

File tree

2 files changed

+0
-89
lines changed

2 files changed

+0
-89
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,6 @@ def _translate(self, record: logging.LogRecord) -> LogRecord:
622622
body=body,
623623
resource=logger.resource,
624624
attributes=attributes,
625-
limits=self._logger_provider._log_limits,
626625
)
627626

628627
def emit(self, record: logging.LogRecord) -> None:
@@ -685,7 +684,6 @@ def __init__(
685684
multi_log_record_processor: SynchronousMultiLogRecordProcessor
686685
| ConcurrentMultiLogRecordProcessor
687686
| None = None,
688-
log_limits: LogLimits | None = None,
689687
):
690688
if resource is None:
691689
self._resource = Resource.create({})
@@ -701,7 +699,6 @@ def __init__(
701699
self._at_exit_handler = atexit.register(self.shutdown)
702700
self._logger_cache = {}
703701
self._logger_cache_lock = Lock()
704-
self._log_limits = log_limits or LogLimits()
705702

706703
@property
707704
def resource(self):

opentelemetry-sdk/tests/logs/test_handler.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
LoggingHandler,
2828
LogRecordProcessor,
2929
)
30-
from opentelemetry.sdk._logs._internal import LogLimits
3130
from opentelemetry.sdk.environment_variables import OTEL_ATTRIBUTE_COUNT_LIMIT
3231
from opentelemetry.semconv._incubating.attributes import code_attributes
3332
from opentelemetry.semconv.attributes import exception_attributes
@@ -474,91 +473,6 @@ def test_logging_handler_without_env_var_uses_default_limit(self):
474473
f"Should have 25 dropped attributes, got {log_record.dropped_attributes}",
475474
)
476475

477-
def test_custom_log_limits_from_logger_provider(self):
478-
"""Test that LoggingHandler uses custom LogLimits from LoggerProvider."""
479-
# Create a LoggerProvider with custom LogLimits (max_attributes=4)
480-
logger_provider = LoggerProvider(
481-
log_limits=LogLimits(max_attributes=4)
482-
)
483-
484-
# Set up logging with this provider
485-
processor = FakeProcessor()
486-
logger_provider.add_log_record_processor(processor)
487-
logger = logging.getLogger("custom_limits_test")
488-
handler = LoggingHandler(
489-
level=logging.WARNING, logger_provider=logger_provider
490-
)
491-
logger.addHandler(handler)
492-
493-
# Create a log record with many extra attributes
494-
extra_attrs = {f"custom_attr_{i}": f"value_{i}" for i in range(10)}
495-
496-
with self.assertLogs(level=logging.WARNING):
497-
logger.warning(
498-
"Test message with custom limits", extra=extra_attrs
499-
)
500-
501-
log_record = processor.get_log_record(0)
502-
503-
# With custom max_attributes=4, should have exactly 4 attributes
504-
total_attrs = len(log_record.attributes)
505-
self.assertEqual(
506-
total_attrs,
507-
4,
508-
f"Should have exactly 4 attributes due to custom limit, got {total_attrs}",
509-
)
510-
511-
# Should have 9 dropped attributes (10 custom + 3 code - 4 kept = 9 dropped)
512-
self.assertEqual(
513-
log_record.dropped_attributes,
514-
9,
515-
f"Should have 9 dropped attributes, got {log_record.dropped_attributes}",
516-
)
517-
518-
@patch.dict(os.environ, {OTEL_ATTRIBUTE_COUNT_LIMIT: "10"})
519-
def test_custom_log_limits_override_env_vars(self):
520-
"""Test that custom LogLimits from LoggerProvider override environment variables."""
521-
# Create a LoggerProvider with custom LogLimits (max_attributes=3)
522-
# This should override the OTEL_ATTRIBUTE_COUNT_LIMIT=10 from the environment
523-
logger_provider = LoggerProvider(
524-
log_limits=LogLimits(max_attributes=3)
525-
)
526-
527-
# Set up logging with this provider
528-
processor = FakeProcessor()
529-
logger_provider.add_log_record_processor(processor)
530-
logger = logging.getLogger("override_env_test")
531-
handler = LoggingHandler(
532-
level=logging.WARNING, logger_provider=logger_provider
533-
)
534-
logger.addHandler(handler)
535-
536-
# Create a log record with many extra attributes
537-
extra_attrs = {f"custom_attr_{i}": f"value_{i}" for i in range(8)}
538-
539-
with self.assertLogs(level=logging.WARNING):
540-
logger.warning(
541-
"Test message with custom limits", extra=extra_attrs
542-
)
543-
544-
log_record = processor.get_log_record(0)
545-
546-
# With custom max_attributes=3, should have exactly 3 attributes
547-
# (even though OTEL_ATTRIBUTE_COUNT_LIMIT=10)
548-
total_attrs = len(log_record.attributes)
549-
self.assertEqual(
550-
total_attrs,
551-
3,
552-
f"Should have exactly 3 attributes due to custom limit, got {total_attrs}",
553-
)
554-
555-
# Should have 8 dropped attributes (8 custom + 3 code - 3 kept = 8 dropped)
556-
self.assertEqual(
557-
log_record.dropped_attributes,
558-
8,
559-
f"Should have 8 dropped attributes, got {log_record.dropped_attributes}",
560-
)
561-
562476

563477
def set_up_test_logging(level, formatter=None, root_logger=False):
564478
logger_provider = LoggerProvider()

0 commit comments

Comments
 (0)