From b4cf6dbd87236a4f23896a2b05143cd2ca563e24 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 10:18:32 -0700 Subject: [PATCH 1/8] replace --- CHANGELOG.md | 2 ++ .../azure/monitor/opentelemetry/_configure.py | 3 --- .../azure/monitor/opentelemetry/_constants.py | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3587f593..eae52b36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Unpin OTel SDK/API version ([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310)) +- Replace custom log processor exporter interval env var with OT SDK env var + ([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310)) ## [1.0.0b15](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b15) - 2023-07-17 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 9538a386..13127bcb 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -113,14 +113,11 @@ def _setup_tracing(configurations: Dict[str, ConfigurationValue]): def _setup_logging(configurations: Dict[str, ConfigurationValue]): - # TODO: Remove after upgrading to OTel SDK 1.18 - logging_export_interval_ms = configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] logger_provider = LoggerProvider() set_logger_provider(logger_provider) log_exporter = AzureMonitorLogExporter(**configurations) log_record_processor = BatchLogRecordProcessor( log_exporter, - schedule_delay_millis=logging_export_interval_ms, ) get_logger_provider().add_log_record_processor(log_record_processor) handler = LoggingHandler(logger_provider=get_logger_provider()) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py index fbc7d332..5001107c 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py @@ -21,7 +21,6 @@ DISABLE_METRICS_ARG = "disable_metrics" DISABLE_TRACING_ARG = "disable_tracing" DISABLED_INSTRUMENTATIONS_ARG = "disabled_instrumentations" -LOGGING_EXPORT_INTERVAL_MS_ARG = "logging_export_interval_ms" SAMPLING_RATIO_ARG = "sampling_ratio" From b6be40e02dc5d1f70118c724a06c77186c916ba3 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 10:53:23 -0700 Subject: [PATCH 2/8] remove --- .../azure/monitor/opentelemetry/_configure.py | 1 - .../opentelemetry/util/configurations.py | 25 ------------------- 2 files changed, 26 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 13127bcb..36e33b80 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -14,7 +14,6 @@ DISABLE_METRICS_ARG, DISABLE_TRACING_ARG, DISABLED_INSTRUMENTATIONS_ARG, - LOGGING_EXPORT_INTERVAL_MS_ARG, SAMPLING_RATIO_ARG, ) from azure.monitor.opentelemetry._types import ConfigurationValue diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index e5a37523..2a065345 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -14,7 +14,6 @@ DISABLE_METRICS_ARG, DISABLE_TRACING_ARG, DISABLED_INSTRUMENTATIONS_ARG, - LOGGING_EXPORT_INTERVAL_MS_ARG, SAMPLING_RATIO_ARG, ) from azure.monitor.opentelemetry._types import ConfigurationValue @@ -32,8 +31,6 @@ _INVALID_INT_MESSAGE = "Value of %s must be a integer. Defaulting to %s: %s" -# Speced out but unused by OTel SDK as of 1.17.0 -LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = "OTEL_BLRP_SCHEDULE_DELAY" # TODO: remove when sampler uses env var instead SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG @@ -51,16 +48,9 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]: _default_disable_metrics(configurations) _default_disable_tracing(configurations) _default_disabled_instrumentations(configurations) - _default_logging_export_interval_ms(configurations) _default_sampling_ratio(configurations) _default_disable_azure_core_tracing(configurations) - # TODO: remove when validation added to BLRP - if configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] <= 0: - raise ValueError( - "%s must be positive." % LOGGING_EXPORT_INTERVAL_MS_ARG - ) - return configurations @@ -101,21 +91,6 @@ def _default_disabled_instrumentations(configurations): configurations[DISABLED_INSTRUMENTATIONS_ARG] = disabled_instrumentation -def _default_logging_export_interval_ms(configurations): - default = 5000 - if LOGGING_EXPORT_INTERVAL_MS_ENV_VAR in environ: - try: - default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR]) - except ValueError as e: - _logger.error( - _INVALID_INT_MESSAGE, - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, - default, - e, - ) - configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default - - # TODO: remove when sampler uses env var instead def _default_sampling_ratio(configurations): default = 1.0 From f49748a5985bc5bd529fb7412244800c8915b62c Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 10:53:37 -0700 Subject: [PATCH 3/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eae52b36..e03c63d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Unpin OTel SDK/API version ([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310)) - Replace custom log processor exporter interval env var with OT SDK env var - ([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310)) + ([#311](https://github.com/microsoft/ApplicationInsights-Python/pull/311)) ## [1.0.0b15](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b15) - 2023-07-17 From f3845956ee9120d7fa9436d2150c1c2c475a666d Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 11:01:10 -0700 Subject: [PATCH 4/8] tests --- .../tests/configuration/test_util.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 48487c1d..3866535e 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -19,7 +19,6 @@ OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, ) from azure.monitor.opentelemetry.util.configurations import ( - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, SAMPLING_RATIO_ENV_VAR, _get_configurations, ) @@ -63,21 +62,10 @@ def test_get_configurations_defaults(self): self.assertTrue("credential" not in configurations) self.assertTrue("storage_directory" not in configurations) - @patch.dict( - "os.environ", - { - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "-1", - }, - clear=True, - ) - def test_get_configurations_logging_export_validation(self): - self.assertRaises(ValueError, _get_configurations) - @patch.dict( "os.environ", { OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: "flask , requests,fastapi", - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", SAMPLING_RATIO_ENV_VAR: "0.5", OTEL_TRACES_EXPORTER: "None", OTEL_LOGS_EXPORTER: "none", @@ -98,12 +86,10 @@ def test_get_configurations_env_vars(self): ["flask", "requests", "fastapi"], ) self.assertEqual(configurations["sampling_ratio"], 0.5) - self.assertEqual(configurations["logging_export_interval_ms"], 10000) @patch.dict( "os.environ", { - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand", SAMPLING_RATIO_ENV_VAR: "Half", OTEL_TRACES_EXPORTER: "False", OTEL_LOGS_EXPORTER: "no", @@ -120,4 +106,3 @@ def test_get_configurations_env_vars_validation(self): self.assertEqual(configurations["disable_metrics"], False) self.assertEqual(configurations["disable_tracing"], False) self.assertEqual(configurations["sampling_ratio"], 1.0) - self.assertEqual(configurations["logging_export_interval_ms"], 5000) From 0eea1150d286b0bc5a3ac10947d8334012535369 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 11:03:21 -0700 Subject: [PATCH 5/8] tests --- .../tests/configuration/test_configure.py | 1 - azure-monitor-opentelemetry/tests/configuration/test_util.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/azure-monitor-opentelemetry/tests/configuration/test_configure.py index 40c5b618..1b9d492d 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -270,7 +270,6 @@ def test_setup_logging( configurations = { "connection_string": "test_cs", - "logging_export_interval_ms": 10000, } _setup_logging(configurations) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 3866535e..cd86a3bc 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -43,7 +43,6 @@ def test_get_configurations(self): self.assertEqual(configurations["disable_tracing"], False) self.assertEqual(configurations["disabled_instrumentations"], []) self.assertEqual(configurations["sampling_ratio"], 1.0) - self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertEqual(configurations["credential"], ("test_credential")) self.assertTrue("storage_directory" not in configurations) @@ -58,7 +57,6 @@ def test_get_configurations_defaults(self): self.assertEqual(configurations["disable_tracing"], False) self.assertEqual(configurations["disabled_instrumentations"], []) self.assertEqual(configurations["sampling_ratio"], 1.0) - self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertTrue("credential" not in configurations) self.assertTrue("storage_directory" not in configurations) From 344b3f7842d9aad39f1c86326931a586f12b79f1 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 11:10:09 -0700 Subject: [PATCH 6/8] mock --- .../tests/configuration/test_configure.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/azure-monitor-opentelemetry/tests/configuration/test_configure.py index 1b9d492d..729d563d 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -277,9 +277,7 @@ def test_setup_logging( set_logger_provider_mock.assert_called_once_with(lp_init_mock) get_logger_provider_mock.assert_called() log_exporter_mock.assert_called_once_with(**configurations) - blrp_mock.assert_called_once_with( - log_exp_init_mock, schedule_delay_millis=10000 - ) + blrp_mock.assert_called_once_with(log_exp_init_mock,) lp_init_mock.add_log_record_processor.assert_called_once_with( blrp_init_mock ) From 04f08980158af2bea26ed84a6590830ae61d5838 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 11:12:09 -0700 Subject: [PATCH 7/8] lint --- .../tests/configuration/test_configure.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/azure-monitor-opentelemetry/tests/configuration/test_configure.py index 729d563d..33160ec5 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -277,7 +277,9 @@ def test_setup_logging( set_logger_provider_mock.assert_called_once_with(lp_init_mock) get_logger_provider_mock.assert_called() log_exporter_mock.assert_called_once_with(**configurations) - blrp_mock.assert_called_once_with(log_exp_init_mock,) + blrp_mock.assert_called_once_with( + log_exp_init_mock, + ) lp_init_mock.add_log_record_processor.assert_called_once_with( blrp_init_mock ) From 3a7379b81e6dd9488bbdaaaf140dcdc86d1dd1c2 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Aug 2023 15:45:49 -0700 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e03c63d7..451ccb65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Unpin OTel SDK/API version ([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310)) -- Replace custom log processor exporter interval env var with OT SDK env var +- Replace explicit log processor exporter interval env var with OT SDK env var ([#311](https://github.com/microsoft/ApplicationInsights-Python/pull/311)) ## [1.0.0b15](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b15) - 2023-07-17