1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
- """Customer Statsbeat implementation for Azure Monitor OpenTelemetry Exporter.
3
+ """Customer SDKStats implementation for Azure Monitor OpenTelemetry Exporter.
4
4
5
- This module provides the implementation for collecting and reporting customer statsbeat
5
+ This module provides the implementation for collecting and reporting Customer SDKStats
6
6
metrics that track the usage and performance of the Azure Monitor OpenTelemetry Exporter.
7
7
"""
8
8
15
15
from opentelemetry .sdk .metrics .export import PeriodicExportingMetricReader
16
16
17
17
from azure .monitor .opentelemetry .exporter ._constants import (
18
- _APPLICATIONINSIGHTS_STATSBEAT_ENABLED_PREVIEW ,
19
- CustomerStatsbeatProperties ,
18
+ _APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW ,
19
+ CustomerSdkStatsProperties ,
20
20
DropCode ,
21
21
DropCodeType ,
22
22
RetryCode ,
23
23
RetryCodeType ,
24
- CustomerStatsbeatMetricName ,
25
- _CUSTOMER_STATSBEAT_LANGUAGE ,
24
+ CustomerSdkStatsMetricName ,
25
+ _CUSTOMER_SDKSTATS_LANGUAGE ,
26
26
)
27
27
28
28
from azure .monitor .opentelemetry .exporter .export .metrics ._exporter import AzureMonitorMetricExporter
38
38
from azure .monitor .opentelemetry .exporter import VERSION
39
39
40
40
from azure .monitor .opentelemetry .exporter .statsbeat ._state import (
41
- _CUSTOMER_STATSBEAT_STATE ,
42
- _CUSTOMER_STATSBEAT_STATE_LOCK ,
41
+ _CUSTOMER_SDKSTATS_STATE ,
42
+ _CUSTOMER_SDKSTATS_STATE_LOCK ,
43
43
)
44
44
45
- _CUSTOMER_STATSBEAT_MAP_LOCK = threading .Lock ()
46
-
47
- class _CustomerStatsbeatTelemetryCounters :
45
+ class _CustomerSdkStatsTelemetryCounters :
48
46
def __init__ (self ):
49
47
self .total_item_success_count : Dict [str , Any ] = {}
50
48
self .total_item_drop_count : Dict [str , Dict [DropCodeType , Dict [str , int ]]] = {}
51
49
self .total_item_retry_count : Dict [str , Dict [RetryCodeType , Dict [str , int ]]] = {}
52
50
53
- class CustomerStatsbeatMetrics (metaclass = Singleton ): # pylint: disable=too-many-instance-attributes
51
+ class CustomerSdkStatsMetrics (metaclass = Singleton ): # pylint: disable=too-many-instance-attributes
54
52
def __init__ (self , connection_string ):
55
- self ._counters = _CustomerStatsbeatTelemetryCounters ()
56
- self ._language = _CUSTOMER_STATSBEAT_LANGUAGE
57
- self ._is_enabled = os .environ .get (_APPLICATIONINSIGHTS_STATSBEAT_ENABLED_PREVIEW , "" ).lower () in ("true" )
53
+ self ._counters = _CustomerSdkStatsTelemetryCounters ()
54
+ self ._language = _CUSTOMER_SDKSTATS_LANGUAGE
55
+ self ._is_enabled = os .environ .get (_APPLICATIONINSIGHTS_SDKSTATS_ENABLED_PREVIEW , "" ).lower () in ("true" )
58
56
if not self ._is_enabled :
59
57
return
60
58
@@ -63,36 +61,36 @@ def __init__(self, connection_string):
63
61
"instrumentation_collection" : True , # Prevent circular dependency
64
62
}
65
63
66
- self ._customer_statsbeat_exporter = AzureMonitorMetricExporter (** exporter_config )
67
- self ._customer_statsbeat_exporter . _is_customer_statsbeat = True
64
+ self ._customer_sdkstats_exporter = AzureMonitorMetricExporter (** exporter_config )
65
+ self ._customer_sdkstats_exporter . _is_customer_sdkstats = True
68
66
metric_reader_options = {
69
- "exporter" : self ._customer_statsbeat_exporter ,
67
+ "exporter" : self ._customer_sdkstats_exporter ,
70
68
"export_interval_millis" : _get_customer_sdkstats_export_interval ()
71
69
}
72
- self ._customer_statsbeat_metric_reader = PeriodicExportingMetricReader (** metric_reader_options )
73
- self ._customer_statsbeat_meter_provider = MeterProvider (
74
- metric_readers = [self ._customer_statsbeat_metric_reader ]
70
+ self ._customer_sdkstats_metric_reader = PeriodicExportingMetricReader (** metric_reader_options )
71
+ self ._customer_sdkstats_meter_provider = MeterProvider (
72
+ metric_readers = [self ._customer_sdkstats_metric_reader ]
75
73
)
76
- self ._customer_statsbeat_meter = self ._customer_statsbeat_meter_provider .get_meter (__name__ )
74
+ self ._customer_sdkstats_meter = self ._customer_sdkstats_meter_provider .get_meter (__name__ )
77
75
78
- self ._customer_properties = CustomerStatsbeatProperties (
76
+ self ._customer_properties = CustomerSdkStatsProperties (
79
77
language = self ._language ,
80
78
version = VERSION ,
81
79
compute_type = get_compute_type (),
82
80
)
83
81
84
- self ._success_gauge = self ._customer_statsbeat_meter .create_observable_gauge (
85
- name = CustomerStatsbeatMetricName .ITEM_SUCCESS_COUNT .value ,
82
+ self ._success_gauge = self ._customer_sdkstats_meter .create_observable_gauge (
83
+ name = CustomerSdkStatsMetricName .ITEM_SUCCESS_COUNT .value ,
86
84
description = "Tracks successful telemetry items sent to Azure Monitor" ,
87
85
callbacks = [self ._item_success_callback ]
88
86
)
89
- self ._dropped_gauge = self ._customer_statsbeat_meter .create_observable_gauge (
90
- name = CustomerStatsbeatMetricName .ITEM_DROP_COUNT .value ,
87
+ self ._dropped_gauge = self ._customer_sdkstats_meter .create_observable_gauge (
88
+ name = CustomerSdkStatsMetricName .ITEM_DROP_COUNT .value ,
91
89
description = "Tracks dropped telemetry items sent to Azure Monitor" ,
92
90
callbacks = [self ._item_drop_callback ]
93
91
)
94
- self ._retry_gauge = self ._customer_statsbeat_meter .create_observable_gauge (
95
- name = CustomerStatsbeatMetricName .ITEM_RETRY_COUNT .value ,
92
+ self ._retry_gauge = self ._customer_sdkstats_meter .create_observable_gauge (
93
+ name = CustomerSdkStatsMetricName .ITEM_RETRY_COUNT .value ,
96
94
description = "Tracks retry attempts for telemetry items sent to Azure Monitor" ,
97
95
callbacks = [self ._item_retry_callback ]
98
96
)
@@ -236,44 +234,44 @@ def _get_retry_reason(self, retry_code: RetryCodeType, exception_message: Option
236
234
}
237
235
return retry_code_reasons .get (retry_code , "unknown_reason" )
238
236
239
- # Global customer statsbeat singleton
240
- _CUSTOMER_STATSBEAT_METRICS = None
241
- _CUSTOMER_STATSBEAT_LOCK = threading .Lock ()
237
+ # Global customer sdkstats singleton
238
+ _CUSTOMER_SDKSTATS_METRICS = None
239
+ _CUSTOMER_SDKSTATS_LOCK = threading .Lock ()
242
240
243
241
244
242
# pylint: disable=global-statement
245
243
# pylint: disable=protected-access
246
- def collect_customer_statsbeat (exporter ):
247
- global _CUSTOMER_STATSBEAT_METRICS
248
- # Only start customer statsbeat if did not exist before
249
- if _CUSTOMER_STATSBEAT_METRICS is None :
250
- with _CUSTOMER_STATSBEAT_LOCK :
244
+ def collect_customer_sdkstats (exporter ):
245
+ global _CUSTOMER_SDKSTATS_METRICS
246
+ # Only start customer sdkstats if did not exist before
247
+ if _CUSTOMER_SDKSTATS_METRICS is None :
248
+ with _CUSTOMER_SDKSTATS_LOCK :
251
249
# Double-check inside the lock to avoid race conditions
252
- if _CUSTOMER_STATSBEAT_METRICS is None :
250
+ if _CUSTOMER_SDKSTATS_METRICS is None :
253
251
254
252
connection_string = (
255
253
f"InstrumentationKey={ exporter ._instrumentation_key } ;"
256
254
f"IngestionEndpoint={ exporter ._endpoint } "
257
255
)
258
- _CUSTOMER_STATSBEAT_METRICS = CustomerStatsbeatMetrics (connection_string )
256
+ _CUSTOMER_SDKSTATS_METRICS = CustomerSdkStatsMetrics (connection_string )
259
257
260
- exporter ._customer_statsbeat_metrics = _CUSTOMER_STATSBEAT_METRICS
258
+ exporter ._customer_sdkstats_metrics = _CUSTOMER_SDKSTATS_METRICS
261
259
if hasattr (exporter , 'storage' ) and exporter .storage :
262
- exporter .storage ._customer_statsbeat_metrics = _CUSTOMER_STATSBEAT_METRICS
260
+ exporter .storage ._customer_sdkstats_metrics = _CUSTOMER_SDKSTATS_METRICS
263
261
264
262
265
- def shutdown_customer_statsbeat_metrics () -> None :
266
- global _CUSTOMER_STATSBEAT_METRICS
263
+ def shutdown_customer_sdkstats_metrics () -> None :
264
+ global _CUSTOMER_SDKSTATS_METRICS
267
265
shutdown_success = False
268
- if _CUSTOMER_STATSBEAT_METRICS is not None :
269
- with _CUSTOMER_STATSBEAT_LOCK :
266
+ if _CUSTOMER_SDKSTATS_METRICS is not None :
267
+ with _CUSTOMER_SDKSTATS_LOCK :
270
268
try :
271
- if _CUSTOMER_STATSBEAT_METRICS . _meter_provider is not None :
272
- _CUSTOMER_STATSBEAT_METRICS . _meter_provider .shutdown ()
273
- _CUSTOMER_STATSBEAT_METRICS = None
269
+ if _CUSTOMER_SDKSTATS_METRICS . _customer_sdkstats_meter_provider is not None :
270
+ _CUSTOMER_SDKSTATS_METRICS . _customer_sdkstats_meter_provider .shutdown ()
271
+ _CUSTOMER_SDKSTATS_METRICS = None
274
272
shutdown_success = True
275
273
except : # pylint: disable=bare-except
276
274
pass
277
275
if shutdown_success :
278
- with _CUSTOMER_STATSBEAT_STATE_LOCK :
279
- _CUSTOMER_STATSBEAT_STATE ["SHUTDOWN" ] = True
276
+ with _CUSTOMER_SDKSTATS_STATE_LOCK :
277
+ _CUSTOMER_SDKSTATS_STATE ["SHUTDOWN" ] = True
0 commit comments