Skip to content

Commit f316a58

Browse files
authored
Fix logging_formatter keyerror breaking change (#42122)
1 parent 4e688ad commit f316a58

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
### Bugs Fixed
1010

11+
- Fix logging formatter breaking change
12+
([#42122](https://github.com/Azure/azure-sdk-for-python/pull/42122))
13+
1114
### Other Changes
1215

1316
## 1.6.11 (2025-07-17)

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# --------------------------------------------------------------------------
66
from functools import cached_property
77
from logging import getLogger, Formatter
8-
from typing import Dict, List, cast
8+
from typing import Dict, List, Optional, cast
99

1010
from opentelemetry.instrumentation.instrumentor import ( # type: ignore
1111
BaseInstrumentor,
@@ -194,7 +194,7 @@ def _setup_logging(configurations: Dict[str, ConfigurationValue]):
194194
logger_provider.add_log_record_processor(log_record_processor)
195195
set_logger_provider(logger_provider)
196196
logger_name: str = configurations[LOGGER_NAME_ARG] # type: ignore
197-
logging_formatter: Formatter = configurations[LOGGING_FORMATTER_ARG] # type: ignore
197+
logging_formatter: Optional[Formatter] = configurations.get(LOGGING_FORMATTER_ARG) # type: ignore
198198
logger = getLogger(logger_name)
199199
# Only add OpenTelemetry LoggingHandler if logger does not already have the handler
200200
# This is to prevent most duplicate logging telemetry

sdk/monitor/azure-monitor-opentelemetry/tests/utils/test_configurations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_get_configurations_logging_format_env_var_invalid_format(self, mock_log
330330
configurations = _get_configurations()
331331

332332
# Should be None when format is invalid
333-
self.assertIsNone(configurations["logging_formatter"])
333+
self.assertIsNone(configurations.get("logging_formatter"))
334334
# Should log a warning
335335
mock_logger.warning.assert_called_once()
336336
call_args = mock_logger.warning.call_args[0]

0 commit comments

Comments
 (0)