diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index eedace1506c1..1e10f0231fc7 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -3,6 +3,8 @@ ## 1.0.0b47 (Unreleased) ### Features Added +- Rename metric names for customer sdk stats and set it on by default + ([#44849](https://github.com/Azure/azure-sdk-for-python/pull/44849)) - Add auto detection for application ID from connection string if not set ([#44644](https://github.com/Azure/azure-sdk-for-python/pull/44644)) - Add support for user id and authId diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py index 543210445eb2..cc8f19702a6d 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py @@ -158,7 +158,7 @@ # Customer Facing SDKStats -_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW = "APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW" +_APPLICATIONINSIGHTS_SDKSTATS_DISABLED = "APPLICATIONINSIGHTS_SDKSTATS_DISABLED" _APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL = "APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL" _CUSTOMER_SDKSTATS_LANGUAGE = "python" @@ -184,9 +184,9 @@ class RetryCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): class CustomerSdkStatsMetricName(str, Enum, metaclass=CaseInsensitiveEnumMeta): - ITEM_SUCCESS_COUNT = "preview.item.success.count" - ITEM_DROP_COUNT = "preview.item.dropped.count" - ITEM_RETRY_COUNT = "preview.item.retry.count" + ITEM_SUCCESS_COUNT = "Item_Success_Count" + ITEM_DROP_COUNT = "Item_Dropped_Count" + ITEM_RETRY_COUNT = "Item_Retry_Count" ## Map from Azure Monitor envelope base_types to TelemetryType diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/customer/_utils.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/customer/_utils.py index 5cf9f0d97c7d..3a0ca0285d47 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/customer/_utils.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/customer/_utils.py @@ -16,7 +16,7 @@ _DEPENDENCY, _APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL, _DEFAULT_STATS_SHORT_EXPORT_INTERVAL, - _APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, + _APPLICATIONINSIGHTS_SDKSTATS_DISABLED, _exception_categories, ) from azure.monitor.opentelemetry.exporter._utils import _get_telemetry_type @@ -48,7 +48,8 @@ def is_customer_sdkstats_enabled() -> bool: :return: True if enabled, False otherwise :rtype: bool """ - return os.environ.get(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, "").lower() == "true" + disabled = os.environ.get(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED) + return disabled is None or disabled.lower() != "true" def categorize_status_code(status_code: int) -> str: diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_customer_sdkstats.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_customer_sdkstats.py index 1044668bb2a5..85e98347c502 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_customer_sdkstats.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_customer_sdkstats.py @@ -6,7 +6,7 @@ from unittest import mock from azure.monitor.opentelemetry.exporter._constants import ( - _APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, + _APPLICATIONINSIGHTS_SDKSTATS_DISABLED, ) from azure.monitor.opentelemetry.exporter.statsbeat.customer._state import ( get_customer_stats_manager, @@ -23,7 +23,7 @@ class TestCustomerSdkStats(unittest.TestCase): def setUp(self): """Set up test environment and ensure customer SDKStats is enabled.""" # Enable customer SDK stats for testing - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false" # Reset the customer stats manager for each test manager = get_customer_stats_manager() @@ -32,7 +32,7 @@ def setUp(self): def tearDown(self): """Clean up test environment.""" # Clean up environment variables - os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None) + os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None) # Shutdown customer stats manager = get_customer_stats_manager() diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_manager.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_manager.py index 19c9841d5488..24f5502c4010 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_manager.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_manager.py @@ -10,7 +10,7 @@ from azure.monitor.opentelemetry.exporter._constants import ( DropCode, RetryCode, - _APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, + _APPLICATIONINSIGHTS_SDKSTATS_DISABLED, _REQUEST, _DEPENDENCY, _CUSTOM_EVENT, @@ -31,7 +31,7 @@ class TestCustomerSdkStatsManager(unittest.TestCase): def setUp(self): """Set up test environment.""" # Enable customer SDK stats for testing - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false" # Reset singleton state - only clear CustomerSdkStatsManager instances if CustomerSdkStatsManager in CustomerSdkStatsManager._instances: @@ -43,7 +43,7 @@ def setUp(self): def tearDown(self): """Clean up test environment.""" # Clean up environment variables - os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None) + os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None) # Shutdown manager if needed try: @@ -65,7 +65,7 @@ def test_manager_initialization_enabled(self): def test_manager_initialization_disabled(self): """Test manager initialization when customer SDK stats is disabled.""" # Disable customer SDK stats - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "false" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "true" # Create new manager with disabled state if hasattr(CustomerSdkStatsManager, "_instances"): @@ -112,7 +112,7 @@ def test_initialize_success(self, mock_meter_provider, mock_metric_reader, mock_ def test_initialize_disabled_manager(self): """Test that initialization fails when manager is disabled.""" # Disable customer SDK stats - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "false" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "true" # Create disabled manager if hasattr(CustomerSdkStatsManager, "_instances"): diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_utlities.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_utlities.py index 5f62016ab92b..8ee8634937ad 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_utlities.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_utlities.py @@ -19,7 +19,7 @@ from azure.monitor.opentelemetry.exporter._constants import ( DropCode, RetryCode, - _APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, + _APPLICATIONINSIGHTS_SDKSTATS_DISABLED, _APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL, _DEFAULT_STATS_SHORT_EXPORT_INTERVAL, _exception_categories, @@ -47,7 +47,7 @@ class TestCustomerSdkStatsUtils(unittest.TestCase): def setUp(self): """Set up test environment.""" # Enable customer SDK stats for testing - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false" # Reset the customer stats manager for each test manager = get_customer_stats_manager() @@ -59,7 +59,7 @@ def setUp(self): def tearDown(self): """Clean up test environment.""" # Clean up environment variables - os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None) + os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None) os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL, None) # Shutdown customer stats @@ -191,7 +191,7 @@ def test_get_customer_sdkstats_export_interval_empty(self): def test_is_customer_sdkstats_enabled_true(self): """Test checking if customer SDK stats is enabled (true case).""" - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false" result = is_customer_sdkstats_enabled() @@ -199,7 +199,7 @@ def test_is_customer_sdkstats_enabled_true(self): def test_is_customer_sdkstats_enabled_false(self): """Test checking if customer SDK stats is enabled (false case).""" - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "false" + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "true" result = is_customer_sdkstats_enabled() @@ -207,19 +207,19 @@ def test_is_customer_sdkstats_enabled_false(self): def test_is_customer_sdkstats_enabled_not_set(self): """Test checking if customer SDK stats is enabled when not set.""" - os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None) + os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None) result = is_customer_sdkstats_enabled() - self.assertFalse(result) + self.assertTrue(result) def test_is_customer_sdkstats_enabled_case_insensitive(self): """Test that enabled check is case insensitive.""" - test_cases = ["TRUE", "True", "tRuE", "true"] + test_cases = ["FALSE", "False", "fAlSe", "false"] for case in test_cases: with self.subTest(case=case): - os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = case + os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = case result = is_customer_sdkstats_enabled() self.assertTrue(result) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_customer_sdkstats.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_customer_sdkstats.py index d5d09ca13b49..80fdd28be1ab 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_customer_sdkstats.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_customer_sdkstats.py @@ -61,8 +61,8 @@ def setUpClass(cls): """Set up class-level resources including a single customer stats manager""" from azure.monitor.opentelemetry.exporter._generated.models import TelemetryEventData, MonitorBase - os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW", None) - os.environ["APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW"] = "true" + os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_DISABLED", None) + os.environ["APPLICATIONINSIGHTS_SDKSTATS_DISABLED"] = "false" # Patch _should_collect_customer_sdkstats instance method to always return True for all tests cls._should_collect_patch = mock.patch( @@ -99,7 +99,7 @@ def tearDownClass(cls): cls._collect_customer_sdkstats_patch.stop() # Clean up environment - os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW", None) + os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_DISABLED", None) def _create_exporter_with_customer_sdkstats_enabled(self, disable_offline_storage=True): """Helper method to create an exporter with customer sdkstats enabled""" diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py index 181e0f195678..f1ca99984f1b 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py @@ -87,10 +87,10 @@ def setUpClass(cls): # Clear environ so the mocks from past tests do not interfere. os.environ.pop("APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL", None) os.environ.pop("APPINSIGHTS_INSTRUMENTATIONKEY", None) - os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW", None) + os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_DISABLED", None) os.environ["APPINSIGHTS_INSTRUMENTATIONKEY"] = "1234abcd-5678-4efa-8abc-1234567890ab" os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true" - os.environ["APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW"] = "false" + os.environ["APPLICATIONINSIGHTS_SDKSTATS_DISABLED"] = "true" cls._base = BaseExporter() cls._envelopes_to_export = [TelemetryItem(name="Test", time=datetime.now())] @@ -797,7 +797,7 @@ def test_transmission_empty(self): os.environ, { "APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL": "false", - "APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW": "false", + "APPLICATIONINSIGHTS_SDKSTATS_DISABLED": "false", }, ) @mock.patch("azure.monitor.opentelemetry.exporter.statsbeat._statsbeat.collect_statsbeat_metrics") @@ -821,7 +821,7 @@ def test_transmit_request_exception(self): os.environ, { "APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL": "false", - "APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW": "false", + "APPLICATIONINSIGHTS_SDKSTATS_DISABLED": "false", }, ) @mock.patch("azure.monitor.opentelemetry.exporter.statsbeat._statsbeat.collect_statsbeat_metrics")