|
27 | 27 | LoggingHandler, |
28 | 28 | LogRecordProcessor, |
29 | 29 | ) |
30 | | -from opentelemetry.sdk._logs._internal import LogLimits |
31 | 30 | from opentelemetry.sdk.environment_variables import OTEL_ATTRIBUTE_COUNT_LIMIT |
32 | 31 | from opentelemetry.semconv._incubating.attributes import code_attributes |
33 | 32 | from opentelemetry.semconv.attributes import exception_attributes |
@@ -474,91 +473,6 @@ def test_logging_handler_without_env_var_uses_default_limit(self): |
474 | 473 | f"Should have 25 dropped attributes, got {log_record.dropped_attributes}", |
475 | 474 | ) |
476 | 475 |
|
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 | | - |
562 | 476 |
|
563 | 477 | def set_up_test_logging(level, formatter=None, root_logger=False): |
564 | 478 | logger_provider = LoggerProvider() |
|
0 commit comments