Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit c566447

Browse files
authored
Add AAD feature stats, fix incorrect counting of retry stats (#1093)
1 parent 15c122d commit c566447

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Fix statsbeats metric names
66
([#1089](https://github.com/census-instrumentation/opencensus-python/pull/1089))
7+
- Add AAD statsbeat feature, fix incorrect counting of retry
8+
([#1093](https://github.com/census-instrumentation/opencensus-python/pull/1093))
79

810
## 1.1.0
911
Released 2021-10-05

contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _transmit(self, envelopes):
9696
'Retrying due to transient client side error %s.', ex)
9797
if self._check_stats_collection():
9898
with _requests_lock:
99-
_requests_map['exception'] = _requests_map.get('exception', 0) + 1 # noqa: E501
99+
_requests_map['retry'] = _requests_map.get('retry', 0) + 1 # noqa: E501
100100
# client side error (retryable)
101101
exception = self.options.minimum_retry_interval
102102
except CredentialUnavailableError as ex:

contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/statsbeat_metrics/statsbeat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class _FEATURE_TYPES:
6363
class _StatsbeatFeature:
6464
NONE = 0
6565
DISK_RETRY = 1
66-
AAD_HANDLING = 2
66+
AAD = 2
6767

6868

6969
def _get_stats_connection_string():
@@ -191,6 +191,8 @@ def __init__(self, options):
191191
self._feature = _StatsbeatFeature.NONE
192192
if options.enable_local_storage:
193193
self._feature |= _StatsbeatFeature.DISK_RETRY
194+
if options.credential:
195+
self._feature |= _StatsbeatFeature.AAD
194196
self._stats_lock = threading.Lock()
195197
self._vm_data = {}
196198
self._vm_retry = True

contrib/opencensus-ext-azure/tests/test_azure_statsbeat_metrics.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
instrumentation_key="ikey",
5353
enable_local_storage=True,
5454
endpoint="test-endpoint",
55+
credential=None,
5556
)
5657

5758

@@ -61,6 +62,11 @@ def __init__(self, status_code, text):
6162
self.text = text
6263

6364

65+
class MockCredential(object):
66+
def get_token():
67+
pass
68+
69+
6470
def throw(exc_type, *args, **kwargs):
6571
def func(*_args, **_kwargs):
6672
raise exc_type(*args, **kwargs)
@@ -320,6 +326,28 @@ def test_get_feature_metric(self):
320326
self.assertEqual(
321327
properties[8].value, ext_version) # noqa: E501
322328

329+
def test_get_feature_metric_wtih_aad(self):
330+
aad_options = Options(
331+
instrumentation_key="ikey",
332+
enable_local_storage=True,
333+
endpoint="test-endpoint",
334+
credential=MockCredential(),
335+
)
336+
stats = _StatsbeatMetrics(aad_options)
337+
metric = stats._get_feature_metric()
338+
properties = metric._time_series[0]._label_values
339+
self.assertEqual(len(properties), 9)
340+
self.assertEqual(properties[0].value, _RP_NAMES[3])
341+
self.assertEqual(properties[1].value, "sdk")
342+
self.assertEqual(properties[2].value, "ikey")
343+
self.assertEqual(properties[3].value, platform.python_version())
344+
self.assertEqual(properties[4].value, _FEATURE_TYPES.FEATURE)
345+
self.assertEqual(properties[5].value, 3)
346+
self.assertEqual(properties[6].value, platform.system())
347+
self.assertEqual(properties[7].value, "python")
348+
self.assertEqual(
349+
properties[8].value, ext_version) # noqa: E501
350+
323351
def test_get_instrumentation_metric(self):
324352
original_integrations = integrations._INTEGRATIONS_BIT_MASK
325353
integrations._INTEGRATIONS_BIT_MASK = 1024

0 commit comments

Comments
 (0)