Skip to content

Commit 3e52f4c

Browse files
authored
Customer SDKStats: Rename metric names and set the environment variable on by default (#44849)
* Update Customer SDK Stats to Metrics Naming and set it on by default * Added CHANGELOG * Update CHANGELOG * Fix format * Retrigger CI/CD pipeline
1 parent d1955dd commit 3e52f4c

File tree

8 files changed

+33
-30
lines changed

8 files changed

+33
-30
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## 1.0.0b47 (Unreleased)
44

55
### Features Added
6+
- Rename metric names for customer sdk stats and set it on by default
7+
([#44849](https://github.com/Azure/azure-sdk-for-python/pull/44849))
68
- Add auto detection for application ID from connection string if not set
79
([#44644](https://github.com/Azure/azure-sdk-for-python/pull/44644))
810
- Add support for user id and authId

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158

159159
# Customer Facing SDKStats
160160

161-
_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW = "APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW"
161+
_APPLICATIONINSIGHTS_SDKSTATS_DISABLED = "APPLICATIONINSIGHTS_SDKSTATS_DISABLED"
162162
_APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL = "APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL"
163163
_CUSTOMER_SDKSTATS_LANGUAGE = "python"
164164

@@ -184,9 +184,9 @@ class RetryCode(str, Enum, metaclass=CaseInsensitiveEnumMeta):
184184

185185

186186
class CustomerSdkStatsMetricName(str, Enum, metaclass=CaseInsensitiveEnumMeta):
187-
ITEM_SUCCESS_COUNT = "preview.item.success.count"
188-
ITEM_DROP_COUNT = "preview.item.dropped.count"
189-
ITEM_RETRY_COUNT = "preview.item.retry.count"
187+
ITEM_SUCCESS_COUNT = "Item_Success_Count"
188+
ITEM_DROP_COUNT = "Item_Dropped_Count"
189+
ITEM_RETRY_COUNT = "Item_Retry_Count"
190190

191191

192192
## Map from Azure Monitor envelope base_types to TelemetryType

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/customer/_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_DEPENDENCY,
1717
_APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL,
1818
_DEFAULT_STATS_SHORT_EXPORT_INTERVAL,
19-
_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW,
19+
_APPLICATIONINSIGHTS_SDKSTATS_DISABLED,
2020
_exception_categories,
2121
)
2222
from azure.monitor.opentelemetry.exporter._utils import _get_telemetry_type
@@ -48,7 +48,8 @@ def is_customer_sdkstats_enabled() -> bool:
4848
:return: True if enabled, False otherwise
4949
:rtype: bool
5050
"""
51-
return os.environ.get(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, "").lower() == "true"
51+
disabled = os.environ.get(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED)
52+
return disabled is None or disabled.lower() != "true"
5253

5354

5455
def categorize_status_code(status_code: int) -> str:

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_customer_sdkstats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from unittest import mock
77

88
from azure.monitor.opentelemetry.exporter._constants import (
9-
_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW,
9+
_APPLICATIONINSIGHTS_SDKSTATS_DISABLED,
1010
)
1111
from azure.monitor.opentelemetry.exporter.statsbeat.customer._state import (
1212
get_customer_stats_manager,
@@ -23,7 +23,7 @@ class TestCustomerSdkStats(unittest.TestCase):
2323
def setUp(self):
2424
"""Set up test environment and ensure customer SDKStats is enabled."""
2525
# Enable customer SDK stats for testing
26-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true"
26+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false"
2727

2828
# Reset the customer stats manager for each test
2929
manager = get_customer_stats_manager()
@@ -32,7 +32,7 @@ def setUp(self):
3232
def tearDown(self):
3333
"""Clean up test environment."""
3434
# Clean up environment variables
35-
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None)
35+
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None)
3636

3737
# Shutdown customer stats
3838
manager = get_customer_stats_manager()

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from azure.monitor.opentelemetry.exporter._constants import (
1111
DropCode,
1212
RetryCode,
13-
_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW,
13+
_APPLICATIONINSIGHTS_SDKSTATS_DISABLED,
1414
_REQUEST,
1515
_DEPENDENCY,
1616
_CUSTOM_EVENT,
@@ -31,7 +31,7 @@ class TestCustomerSdkStatsManager(unittest.TestCase):
3131
def setUp(self):
3232
"""Set up test environment."""
3333
# Enable customer SDK stats for testing
34-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true"
34+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false"
3535

3636
# Reset singleton state - only clear CustomerSdkStatsManager instances
3737
if CustomerSdkStatsManager in CustomerSdkStatsManager._instances:
@@ -43,7 +43,7 @@ def setUp(self):
4343
def tearDown(self):
4444
"""Clean up test environment."""
4545
# Clean up environment variables
46-
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None)
46+
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None)
4747

4848
# Shutdown manager if needed
4949
try:
@@ -65,7 +65,7 @@ def test_manager_initialization_enabled(self):
6565
def test_manager_initialization_disabled(self):
6666
"""Test manager initialization when customer SDK stats is disabled."""
6767
# Disable customer SDK stats
68-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "false"
68+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "true"
6969

7070
# Create new manager with disabled state
7171
if hasattr(CustomerSdkStatsManager, "_instances"):
@@ -112,7 +112,7 @@ def test_initialize_success(self, mock_meter_provider, mock_metric_reader, mock_
112112
def test_initialize_disabled_manager(self):
113113
"""Test that initialization fails when manager is disabled."""
114114
# Disable customer SDK stats
115-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "false"
115+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "true"
116116

117117
# Create disabled manager
118118
if hasattr(CustomerSdkStatsManager, "_instances"):

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_utlities.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from azure.monitor.opentelemetry.exporter._constants import (
2020
DropCode,
2121
RetryCode,
22-
_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW,
22+
_APPLICATIONINSIGHTS_SDKSTATS_DISABLED,
2323
_APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL,
2424
_DEFAULT_STATS_SHORT_EXPORT_INTERVAL,
2525
_exception_categories,
@@ -47,7 +47,7 @@ class TestCustomerSdkStatsUtils(unittest.TestCase):
4747
def setUp(self):
4848
"""Set up test environment."""
4949
# Enable customer SDK stats for testing
50-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true"
50+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false"
5151

5252
# Reset the customer stats manager for each test
5353
manager = get_customer_stats_manager()
@@ -59,7 +59,7 @@ def setUp(self):
5959
def tearDown(self):
6060
"""Clean up test environment."""
6161
# Clean up environment variables
62-
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None)
62+
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None)
6363
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL, None)
6464

6565
# Shutdown customer stats
@@ -191,35 +191,35 @@ def test_get_customer_sdkstats_export_interval_empty(self):
191191

192192
def test_is_customer_sdkstats_enabled_true(self):
193193
"""Test checking if customer SDK stats is enabled (true case)."""
194-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "true"
194+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "false"
195195

196196
result = is_customer_sdkstats_enabled()
197197

198198
self.assertTrue(result)
199199

200200
def test_is_customer_sdkstats_enabled_false(self):
201201
"""Test checking if customer SDK stats is enabled (false case)."""
202-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = "false"
202+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = "true"
203203

204204
result = is_customer_sdkstats_enabled()
205205

206206
self.assertFalse(result)
207207

208208
def test_is_customer_sdkstats_enabled_not_set(self):
209209
"""Test checking if customer SDK stats is enabled when not set."""
210-
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW, None)
210+
os.environ.pop(_APPLICATIONINSIGHTS_SDKSTATS_DISABLED, None)
211211

212212
result = is_customer_sdkstats_enabled()
213213

214-
self.assertFalse(result)
214+
self.assertTrue(result)
215215

216216
def test_is_customer_sdkstats_enabled_case_insensitive(self):
217217
"""Test that enabled check is case insensitive."""
218-
test_cases = ["TRUE", "True", "tRuE", "true"]
218+
test_cases = ["FALSE", "False", "fAlSe", "false"]
219219

220220
for case in test_cases:
221221
with self.subTest(case=case):
222-
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW] = case
222+
os.environ[_APPLICATIONINSIGHTS_SDKSTATS_DISABLED] = case
223223
result = is_customer_sdkstats_enabled()
224224
self.assertTrue(result)
225225

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_customer_sdkstats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def setUpClass(cls):
6161
"""Set up class-level resources including a single customer stats manager"""
6262
from azure.monitor.opentelemetry.exporter._generated.models import TelemetryEventData, MonitorBase
6363

64-
os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW", None)
65-
os.environ["APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW"] = "true"
64+
os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_DISABLED", None)
65+
os.environ["APPLICATIONINSIGHTS_SDKSTATS_DISABLED"] = "false"
6666

6767
# Patch _should_collect_customer_sdkstats instance method to always return True for all tests
6868
cls._should_collect_patch = mock.patch(
@@ -99,7 +99,7 @@ def tearDownClass(cls):
9999
cls._collect_customer_sdkstats_patch.stop()
100100

101101
# Clean up environment
102-
os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW", None)
102+
os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_DISABLED", None)
103103

104104
def _create_exporter_with_customer_sdkstats_enabled(self, disable_offline_storage=True):
105105
"""Helper method to create an exporter with customer sdkstats enabled"""

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def setUpClass(cls):
8787
# Clear environ so the mocks from past tests do not interfere.
8888
os.environ.pop("APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL", None)
8989
os.environ.pop("APPINSIGHTS_INSTRUMENTATIONKEY", None)
90-
os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW", None)
90+
os.environ.pop("APPLICATIONINSIGHTS_SDKSTATS_DISABLED", None)
9191
os.environ["APPINSIGHTS_INSTRUMENTATIONKEY"] = "1234abcd-5678-4efa-8abc-1234567890ab"
9292
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
93-
os.environ["APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW"] = "false"
93+
os.environ["APPLICATIONINSIGHTS_SDKSTATS_DISABLED"] = "true"
9494
cls._base = BaseExporter()
9595
cls._envelopes_to_export = [TelemetryItem(name="Test", time=datetime.now())]
9696

@@ -797,7 +797,7 @@ def test_transmission_empty(self):
797797
os.environ,
798798
{
799799
"APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL": "false",
800-
"APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW": "false",
800+
"APPLICATIONINSIGHTS_SDKSTATS_DISABLED": "false",
801801
},
802802
)
803803
@mock.patch("azure.monitor.opentelemetry.exporter.statsbeat._statsbeat.collect_statsbeat_metrics")
@@ -821,7 +821,7 @@ def test_transmit_request_exception(self):
821821
os.environ,
822822
{
823823
"APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL": "false",
824-
"APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW": "false",
824+
"APPLICATIONINSIGHTS_SDKSTATS_DISABLED": "false",
825825
},
826826
)
827827
@mock.patch("azure.monitor.opentelemetry.exporter.statsbeat._statsbeat.collect_statsbeat_metrics")

0 commit comments

Comments
 (0)