Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from azure.monitor.opentelemetry.exporter._constants import (
DropCode,
RetryCode,
_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW,
_APPLICATIONINSIGHTS_SDKSTATS_DISABLED,
_REQUEST,
_DEPENDENCY,
_CUSTOM_EVENT,
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"):
Expand Down Expand Up @@ -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"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -191,35 +191,35 @@ 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()

self.assertTrue(result)

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()

self.assertFalse(result)

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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())]

Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down