@@ -34,116 +34,115 @@ let instance: LongIntervalStatsbeatMetrics | null = null;
34
34
* @internal
35
35
*/
36
36
class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
37
- private _AZURE_MONITOR_STATSBEAT_FEATURES = process . env . AZURE_MONITOR_STATSBEAT_FEATURES ;
38
- private _statsCollectionLongInterval : number = 86400000 ; // 1 day
39
- private _isInitialized : boolean = false ;
40
-
37
+ private AZURE_MONITOR_STATSBEAT_FEATURES = process . env . AZURE_MONITOR_STATSBEAT_FEATURES ;
38
+ private statsCollectionLongInterval : number = 86400000 ; // 1 day
41
39
// Custom dimensions
42
- private _cikey : string ;
43
- private _runtimeVersion : string ;
44
- private _language : string ;
45
- private _version : string ;
46
- private _attach : string = "sdk" ;
40
+ private cikey : string ;
41
+ private runtimeVersion : string ;
42
+ private language : string ;
43
+ private version : string ;
44
+ private attach : string = "sdk" ;
47
45
48
- private _commonProperties : CommonStatsbeatProperties ;
49
- private _attachProperties : AttachStatsbeatProperties ;
46
+ private commonProperties : CommonStatsbeatProperties ;
47
+ private attachProperties : AttachStatsbeatProperties ;
50
48
51
- private _feature : number = 0 ;
52
- private _instrumentation : number = 0 ;
49
+ private feature : number = 0 ;
50
+ private instrumentation : number = 0 ;
53
51
54
- private _longIntervalStatsbeatMeterProvider : MeterProvider ;
55
- private _longIntervalAzureExporter : AzureMonitorStatsbeatExporter ;
56
- private _longIntervalMetricReader : PeriodicExportingMetricReader ;
57
- private _longIntervalStatsbeatMeter : Meter ;
52
+ private longIntervalStatsbeatMeterProvider : MeterProvider ;
53
+ private longIntervalAzureExporter : AzureMonitorStatsbeatExporter ;
54
+ private longIntervalMetricReader : PeriodicExportingMetricReader ;
55
+ private longIntervalStatsbeatMeter : Meter ;
58
56
59
57
// Network Attributes
60
- private _connectionString : string ;
58
+ private connectionString : string ;
61
59
62
60
// Observable Gauges
63
- private _featureStatsbeatGauge : ObservableGauge ;
64
- private _attachStatsbeatGauge : ObservableGauge ;
61
+ private featureStatsbeatGauge : ObservableGauge ;
62
+ private attachStatsbeatGauge : ObservableGauge ;
63
+
64
+ public isInitialized : boolean = false ;
65
65
66
66
constructor ( options : StatsbeatOptions ) {
67
67
super ( ) ;
68
- this . _connectionString = super . _getConnectionString ( options . endpointUrl ) ;
68
+ this . connectionString = super . getConnectionString ( options . endpointUrl ) ;
69
69
const exporterConfig : AzureMonitorExporterOptions = {
70
- connectionString : this . _connectionString ,
70
+ connectionString : this . connectionString ,
71
71
} ;
72
72
73
- if ( this . _AZURE_MONITOR_STATSBEAT_FEATURES ) {
73
+ if ( this . AZURE_MONITOR_STATSBEAT_FEATURES ) {
74
74
try {
75
- this . _feature = JSON . parse ( this . _AZURE_MONITOR_STATSBEAT_FEATURES ) . feature ;
76
- this . _instrumentation = JSON . parse ( this . _AZURE_MONITOR_STATSBEAT_FEATURES ) . instrumentation ;
77
- } catch ( error ) {
75
+ this . feature = JSON . parse ( this . AZURE_MONITOR_STATSBEAT_FEATURES ) . feature ;
76
+ this . instrumentation = JSON . parse ( this . AZURE_MONITOR_STATSBEAT_FEATURES ) . instrumentation ;
77
+ } catch ( error : any ) {
78
78
diag . error (
79
79
`LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${ error } )`
80
80
) ;
81
81
}
82
82
}
83
83
84
- this . _longIntervalStatsbeatMeterProvider = new MeterProvider ( ) ;
85
- this . _longIntervalAzureExporter = new AzureMonitorStatsbeatExporter ( exporterConfig ) ;
84
+ this . longIntervalStatsbeatMeterProvider = new MeterProvider ( ) ;
85
+ this . longIntervalAzureExporter = new AzureMonitorStatsbeatExporter ( exporterConfig ) ;
86
86
87
87
// Export Long Interval Statsbeats every day
88
88
const longIntervalMetricReaderOptions : PeriodicExportingMetricReaderOptions = {
89
- exporter : this . _longIntervalAzureExporter ,
89
+ exporter : this . longIntervalAzureExporter ,
90
90
exportIntervalMillis :
91
- Number ( process . env . LONG_INTERVAL_EXPORT_MILLIS ) || this . _statsCollectionLongInterval , // 1 day
91
+ Number ( process . env . LONG_INTERVAL_EXPORT_MILLIS ) || this . statsCollectionLongInterval , // 1 day
92
92
} ;
93
93
94
- this . _longIntervalMetricReader = new PeriodicExportingMetricReader (
94
+ this . longIntervalMetricReader = new PeriodicExportingMetricReader (
95
95
longIntervalMetricReaderOptions
96
96
) ;
97
- this . _longIntervalStatsbeatMeterProvider . addMetricReader ( this . _longIntervalMetricReader ) ;
98
- this . _longIntervalStatsbeatMeter = this . _longIntervalStatsbeatMeterProvider . getMeter (
97
+ this . longIntervalStatsbeatMeterProvider . addMetricReader ( this . longIntervalMetricReader ) ;
98
+ this . longIntervalStatsbeatMeter = this . longIntervalStatsbeatMeterProvider . getMeter (
99
99
"Azure Monitor Long Interval Statsbeat"
100
100
) ;
101
101
102
102
// Assign Common Properties
103
- this . _runtimeVersion = process . version ;
104
- this . _language = STATSBEAT_LANGUAGE ;
105
- this . _version = ai . packageVersion ;
106
- this . _cikey = options . instrumentationKey ;
103
+ this . runtimeVersion = process . version ;
104
+ this . language = STATSBEAT_LANGUAGE ;
105
+ this . version = ai . packageVersion ;
106
+ this . cikey = options . instrumentationKey ;
107
107
108
- this . _featureStatsbeatGauge = this . _longIntervalStatsbeatMeter . createObservableGauge (
108
+ this . featureStatsbeatGauge = this . longIntervalStatsbeatMeter . createObservableGauge (
109
109
StatsbeatCounter . FEATURE
110
110
) ;
111
- this . _attachStatsbeatGauge = this . _longIntervalStatsbeatMeter . createObservableGauge (
111
+ this . attachStatsbeatGauge = this . longIntervalStatsbeatMeter . createObservableGauge (
112
112
StatsbeatCounter . ATTACH
113
113
) ;
114
114
115
- this . _commonProperties = {
116
- os : super . _os ,
117
- rp : super . _resourceProvider ,
118
- cikey : this . _cikey ,
119
- runtimeVersion : this . _runtimeVersion ,
120
- language : this . _language ,
121
- version : this . _version ,
122
- attach : this . _attach ,
115
+ this . commonProperties = {
116
+ os : super . os ,
117
+ rp : super . resourceProvider ,
118
+ cikey : this . cikey ,
119
+ runtimeVersion : this . runtimeVersion ,
120
+ language : this . language ,
121
+ version : this . version ,
122
+ attach : this . attach ,
123
123
} ;
124
124
125
- this . _attachProperties = {
126
- rpId : super . _resourceIdentifier ,
125
+ this . attachProperties = {
126
+ rpId : super . resourceIdentifier ,
127
127
} ;
128
128
129
- this . _isInitialized = true ;
130
- this . _initialize ( ) ;
129
+ this . isInitialized = true ;
130
+ this . initialize ( ) ;
131
131
}
132
132
133
- private async _initialize ( ) {
133
+ private async initialize ( ) {
134
134
try {
135
- await this . _getResourceProvider ( ) ;
135
+ await this . getResourceProvider ( ) ;
136
136
137
137
// Add long interval observable callbacks
138
- this . _attachStatsbeatGauge . addCallback ( this . _attachCallback . bind ( this ) ) ;
139
- this . _longIntervalStatsbeatMeter . addBatchObservableCallback (
140
- this . _featureCallback . bind ( this ) ,
141
- [ this . _featureStatsbeatGauge ]
142
- ) ;
138
+ this . attachStatsbeatGauge . addCallback ( this . attachCallback . bind ( this ) ) ;
139
+ this . longIntervalStatsbeatMeter . addBatchObservableCallback ( this . featureCallback . bind ( this ) , [
140
+ this . featureStatsbeatGauge ,
141
+ ] ) ;
143
142
144
143
// Export Feature/Attach Statsbeat once upon app initialization
145
- this . _longIntervalAzureExporter . export (
146
- ( await this . _longIntervalMetricReader . collect ( ) ) . resourceMetrics ,
144
+ this . longIntervalAzureExporter . export (
145
+ ( await this . longIntervalMetricReader . collect ( ) ) . resourceMetrics ,
147
146
( result : ExportResult ) => {
148
147
if ( result . code !== ExportResultCode . SUCCESS ) {
149
148
diag . error ( `LongIntervalStatsbeat: metrics export failed (error ${ result . error } )` ) ;
@@ -155,38 +154,34 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
155
154
}
156
155
}
157
156
158
- private _featureCallback ( observableResult : BatchObservableResult ) {
157
+ private featureCallback ( observableResult : BatchObservableResult ) {
159
158
let attributes ;
160
- if ( this . _instrumentation ) {
159
+ if ( this . instrumentation ) {
161
160
attributes = {
162
- ...this . _commonProperties ,
163
- feature : this . _instrumentation ,
161
+ ...this . commonProperties ,
162
+ feature : this . instrumentation ,
164
163
type : StatsbeatFeatureType . INSTRUMENTATION ,
165
164
} ;
166
- observableResult . observe ( this . _featureStatsbeatGauge , 1 , { ...attributes } ) ;
165
+ observableResult . observe ( this . featureStatsbeatGauge , 1 , { ...attributes } ) ;
167
166
}
168
167
169
- if ( this . _feature ) {
168
+ if ( this . feature ) {
170
169
attributes = {
171
- ...this . _commonProperties ,
172
- feature : this . _feature ,
170
+ ...this . commonProperties ,
171
+ feature : this . feature ,
173
172
type : StatsbeatFeatureType . FEATURE ,
174
173
} ;
175
- observableResult . observe ( this . _featureStatsbeatGauge , 1 , { ...attributes } ) ;
174
+ observableResult . observe ( this . featureStatsbeatGauge , 1 , { ...attributes } ) ;
176
175
}
177
176
}
178
177
179
- private _attachCallback ( observableResult : ObservableResult ) {
180
- let attributes = { ...this . _commonProperties , ...this . _attachProperties } ;
178
+ private attachCallback ( observableResult : ObservableResult ) {
179
+ const attributes = { ...this . commonProperties , ...this . attachProperties } ;
181
180
observableResult . observe ( 1 , attributes ) ;
182
181
}
183
182
184
- public isInitialized ( ) {
185
- return this . _isInitialized ;
186
- }
187
-
188
- public shutdown ( ) {
189
- this . _longIntervalStatsbeatMeterProvider . shutdown ( ) ;
183
+ public shutdown ( ) : Promise < void > {
184
+ return this . longIntervalStatsbeatMeterProvider . shutdown ( ) ;
190
185
}
191
186
}
192
187
0 commit comments