@azure/monitor-opentelemetry-exporter 1.0.0-beta.31 → 1.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/commonjs/Declarations/Constants.d.ts +5 -0
- package/dist/commonjs/Declarations/Constants.d.ts.map +1 -1
- package/dist/commonjs/Declarations/Constants.js +6 -1
- package/dist/commonjs/Declarations/Constants.js.map +1 -1
- package/dist/commonjs/export/base.js +25 -14
- package/dist/commonjs/export/base.js.map +1 -1
- package/dist/commonjs/export/log.js +5 -4
- package/dist/commonjs/export/log.js.map +1 -1
- package/dist/commonjs/export/metric.js +5 -4
- package/dist/commonjs/export/metric.js.map +1 -1
- package/dist/commonjs/export/statsbeat/customerStatsbeat.d.ts +125 -0
- package/dist/commonjs/export/statsbeat/customerStatsbeat.d.ts.map +1 -0
- package/dist/commonjs/export/statsbeat/customerStatsbeat.js +480 -0
- package/dist/commonjs/export/statsbeat/customerStatsbeat.js.map +1 -0
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.d.ts +7 -7
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js +69 -30
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.d.ts +6 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js +115 -43
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatExporter.d.ts +7 -0
- package/dist/commonjs/export/statsbeat/statsbeatExporter.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatExporter.js +25 -5
- package/dist/commonjs/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatMetrics.js +6 -8
- package/dist/commonjs/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/types.d.ts +52 -0
- package/dist/commonjs/export/statsbeat/types.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/types.js +75 -1
- package/dist/commonjs/export/statsbeat/types.js.map +1 -1
- package/dist/commonjs/export/trace.js +6 -5
- package/dist/commonjs/export/trace.js.map +1 -1
- package/dist/commonjs/generated/applicationInsightsClient.js +9 -4
- package/dist/commonjs/generated/applicationInsightsClient.js.map +1 -1
- package/dist/commonjs/generated/models/mappers.js +145 -68
- package/dist/commonjs/generated/models/mappers.js.map +1 -1
- package/dist/commonjs/index.d.ts +2 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +5 -3
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/platform/nodejs/baseSender.d.ts +1 -0
- package/dist/commonjs/platform/nodejs/baseSender.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/baseSender.js +101 -34
- package/dist/commonjs/platform/nodejs/baseSender.js.map +1 -1
- package/dist/commonjs/platform/nodejs/context/context.d.ts +0 -1
- package/dist/commonjs/platform/nodejs/context/context.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/context/context.js +4 -8
- package/dist/commonjs/platform/nodejs/context/context.js.map +1 -1
- package/dist/commonjs/platform/nodejs/httpSender.js +11 -4
- package/dist/commonjs/platform/nodejs/httpSender.js.map +1 -1
- package/dist/commonjs/platform/nodejs/index.d.ts +1 -0
- package/dist/commonjs/platform/nodejs/index.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/index.js +1 -0
- package/dist/commonjs/platform/nodejs/index.js.map +1 -1
- package/dist/commonjs/platform/nodejs/persist/fileAccessControl.js +7 -7
- package/dist/commonjs/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.d.ts +9 -1
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.js +37 -16
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist/commonjs/{sampling.d.ts → sampling/percentageSampler.d.ts} +2 -3
- package/dist/commonjs/sampling/percentageSampler.d.ts.map +1 -0
- package/dist/commonjs/{sampling.js → sampling/percentageSampler.js} +6 -39
- package/dist/commonjs/sampling/percentageSampler.js.map +1 -0
- package/dist/commonjs/sampling/rateLimitedSampler.d.ts +58 -0
- package/dist/commonjs/sampling/rateLimitedSampler.d.ts.map +1 -0
- package/dist/commonjs/sampling/rateLimitedSampler.js +118 -0
- package/dist/commonjs/sampling/rateLimitedSampler.js.map +1 -0
- package/dist/commonjs/sampling/samplingUtils.d.ts +17 -0
- package/dist/commonjs/sampling/samplingUtils.d.ts.map +1 -0
- package/dist/commonjs/sampling/samplingUtils.js +94 -0
- package/dist/commonjs/sampling/samplingUtils.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +1 -0
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/utils/common.js +2 -3
- package/dist/commonjs/utils/common.js.map +1 -1
- package/dist/commonjs/utils/connectionStringParser.js +3 -3
- package/dist/commonjs/utils/connectionStringParser.js.map +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.d.ts +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.js +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.js.map +1 -1
- package/dist/commonjs/utils/eventhub.js +5 -2
- package/dist/commonjs/utils/eventhub.js.map +1 -1
- package/dist/commonjs/utils/logUtils.js +10 -9
- package/dist/commonjs/utils/logUtils.js.map +1 -1
- package/dist/commonjs/utils/metricUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/metricUtils.js +6 -6
- package/dist/commonjs/utils/metricUtils.js.map +1 -1
- package/dist/commonjs/utils/spanUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/spanUtils.js +16 -14
- package/dist/commonjs/utils/spanUtils.js.map +1 -1
- package/dist/esm/Declarations/Constants.d.ts +5 -0
- package/dist/esm/Declarations/Constants.d.ts.map +1 -1
- package/dist/esm/Declarations/Constants.js +5 -0
- package/dist/esm/Declarations/Constants.js.map +1 -1
- package/dist/esm/export/base.js +25 -14
- package/dist/esm/export/base.js.map +1 -1
- package/dist/esm/export/log.js +5 -4
- package/dist/esm/export/log.js.map +1 -1
- package/dist/esm/export/metric.js +5 -4
- package/dist/esm/export/metric.js.map +1 -1
- package/dist/esm/export/statsbeat/customerStatsbeat.d.ts +125 -0
- package/dist/esm/export/statsbeat/customerStatsbeat.d.ts.map +1 -0
- package/dist/esm/export/statsbeat/customerStatsbeat.js +475 -0
- package/dist/esm/export/statsbeat/customerStatsbeat.js.map +1 -0
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.d.ts +7 -7
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js +68 -30
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.d.ts +6 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js +115 -43
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatExporter.d.ts +7 -0
- package/dist/esm/export/statsbeat/statsbeatExporter.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatExporter.js +25 -5
- package/dist/esm/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatMetrics.js +6 -8
- package/dist/esm/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/types.d.ts +52 -0
- package/dist/esm/export/statsbeat/types.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/types.js +73 -0
- package/dist/esm/export/statsbeat/types.js.map +1 -1
- package/dist/esm/export/trace.js +6 -5
- package/dist/esm/export/trace.js.map +1 -1
- package/dist/esm/generated/applicationInsightsClient.js +9 -4
- package/dist/esm/generated/applicationInsightsClient.js.map +1 -1
- package/dist/esm/generated/models/mappers.js +145 -68
- package/dist/esm/generated/models/mappers.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/platform/nodejs/baseSender.d.ts +1 -0
- package/dist/esm/platform/nodejs/baseSender.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/baseSender.js +104 -37
- package/dist/esm/platform/nodejs/baseSender.js.map +1 -1
- package/dist/esm/platform/nodejs/context/context.d.ts +0 -1
- package/dist/esm/platform/nodejs/context/context.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/context/context.js +4 -8
- package/dist/esm/platform/nodejs/context/context.js.map +1 -1
- package/dist/esm/platform/nodejs/httpSender.js +11 -4
- package/dist/esm/platform/nodejs/httpSender.js.map +1 -1
- package/dist/esm/platform/nodejs/index.d.ts +1 -0
- package/dist/esm/platform/nodejs/index.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/index.js +1 -0
- package/dist/esm/platform/nodejs/index.js.map +1 -1
- package/dist/esm/platform/nodejs/persist/fileAccessControl.js +7 -7
- package/dist/esm/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.d.ts +9 -1
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.js +37 -16
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist/esm/{sampling.d.ts → sampling/percentageSampler.d.ts} +2 -3
- package/dist/esm/sampling/percentageSampler.d.ts.map +1 -0
- package/dist/esm/{sampling.js → sampling/percentageSampler.js} +6 -39
- package/dist/esm/sampling/percentageSampler.js.map +1 -0
- package/dist/esm/sampling/rateLimitedSampler.d.ts +58 -0
- package/dist/esm/sampling/rateLimitedSampler.d.ts.map +1 -0
- package/dist/esm/sampling/rateLimitedSampler.js +114 -0
- package/dist/esm/sampling/rateLimitedSampler.js.map +1 -0
- package/dist/esm/sampling/samplingUtils.d.ts +17 -0
- package/dist/esm/sampling/samplingUtils.d.ts.map +1 -0
- package/dist/esm/sampling/samplingUtils.js +89 -0
- package/dist/esm/sampling/samplingUtils.js.map +1 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +2 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/common.js +2 -3
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/connectionStringParser.js +3 -3
- package/dist/esm/utils/connectionStringParser.js.map +1 -1
- package/dist/esm/utils/constants/applicationinsights.d.ts +1 -1
- package/dist/esm/utils/constants/applicationinsights.js +1 -1
- package/dist/esm/utils/constants/applicationinsights.js.map +1 -1
- package/dist/esm/utils/eventhub.js +5 -2
- package/dist/esm/utils/eventhub.js.map +1 -1
- package/dist/esm/utils/logUtils.js +10 -9
- package/dist/esm/utils/logUtils.js.map +1 -1
- package/dist/esm/utils/metricUtils.d.ts.map +1 -1
- package/dist/esm/utils/metricUtils.js +6 -6
- package/dist/esm/utils/metricUtils.js.map +1 -1
- package/dist/esm/utils/spanUtils.d.ts.map +1 -1
- package/dist/esm/utils/spanUtils.js +16 -14
- package/dist/esm/utils/spanUtils.js.map +1 -1
- package/package.json +21 -26
- package/dist/commonjs/sampling.d.ts.map +0 -1
- package/dist/commonjs/sampling.js.map +0 -1
- package/dist/esm/sampling.d.ts.map +0 -1
- package/dist/esm/sampling.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
5
|
+
exports.LongIntervalStatsbeatMetrics = void 0;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
const api_1 = require("@opentelemetry/api");
|
|
8
8
|
const core_1 = require("@opentelemetry/core");
|
|
@@ -12,26 +12,41 @@ const statsbeatMetrics_js_1 = require("./statsbeatMetrics.js");
|
|
|
12
12
|
const types_js_1 = require("./types.js");
|
|
13
13
|
const statsbeatExporter_js_1 = require("./statsbeatExporter.js");
|
|
14
14
|
const metricUtils_js_1 = require("../../utils/metricUtils.js");
|
|
15
|
-
let instance = null;
|
|
16
15
|
/**
|
|
17
16
|
* Long Interval Statsbeat Metrics
|
|
18
17
|
* @internal
|
|
19
18
|
*/
|
|
20
19
|
class LongIntervalStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
20
|
+
static instance = null;
|
|
21
|
+
statsCollectionLongInterval = 86400000; // 1 day
|
|
22
|
+
// Custom dimensions
|
|
23
|
+
cikey;
|
|
24
|
+
runtimeVersion;
|
|
25
|
+
language;
|
|
26
|
+
version;
|
|
27
|
+
attach = (0, metricUtils_js_1.getAttachType)();
|
|
28
|
+
commonProperties;
|
|
29
|
+
attachProperties;
|
|
30
|
+
feature = 0;
|
|
31
|
+
instrumentation = 0;
|
|
32
|
+
longIntervalStatsbeatMeterProvider;
|
|
33
|
+
longIntervalAzureExporter;
|
|
34
|
+
longIntervalMetricReader;
|
|
35
|
+
longIntervalStatsbeatMeter;
|
|
36
|
+
// Network Attributes
|
|
37
|
+
connectionString;
|
|
38
|
+
// Observable Gauges
|
|
39
|
+
featureStatsbeatGauge;
|
|
40
|
+
attachStatsbeatGauge;
|
|
41
|
+
isInitialized = false;
|
|
21
42
|
constructor(options) {
|
|
22
43
|
super();
|
|
23
|
-
this.statsCollectionLongInterval = 86400000; // 1 day
|
|
24
|
-
this.attach = (0, metricUtils_js_1.getAttachType)();
|
|
25
|
-
this.feature = 0;
|
|
26
|
-
this.instrumentation = 0;
|
|
27
|
-
this.isInitialized = false;
|
|
28
44
|
this.connectionString = super.getConnectionString(options.endpointUrl);
|
|
29
45
|
const exporterConfig = {
|
|
30
46
|
connectionString: this.connectionString,
|
|
31
47
|
disableOfflineStorage: options.disableOfflineStorage,
|
|
32
48
|
};
|
|
33
49
|
this.setFeatures();
|
|
34
|
-
this.longIntervalStatsbeatMeterProvider = new sdk_metrics_1.MeterProvider();
|
|
35
50
|
this.longIntervalAzureExporter = new statsbeatExporter_js_1.AzureMonitorStatsbeatExporter(exporterConfig);
|
|
36
51
|
// Export Long Interval Statsbeats every day
|
|
37
52
|
const longIntervalMetricReaderOptions = {
|
|
@@ -39,7 +54,9 @@ class LongIntervalStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetric
|
|
|
39
54
|
exportIntervalMillis: Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day
|
|
40
55
|
};
|
|
41
56
|
this.longIntervalMetricReader = new sdk_metrics_1.PeriodicExportingMetricReader(longIntervalMetricReaderOptions);
|
|
42
|
-
this.longIntervalStatsbeatMeterProvider.
|
|
57
|
+
this.longIntervalStatsbeatMeterProvider = new sdk_metrics_1.MeterProvider({
|
|
58
|
+
readers: [this.longIntervalMetricReader],
|
|
59
|
+
});
|
|
43
60
|
this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter("Azure Monitor Long Interval Statsbeat");
|
|
44
61
|
// Assign Common Properties
|
|
45
62
|
this.runtimeVersion = process.version;
|
|
@@ -71,11 +88,22 @@ class LongIntervalStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetric
|
|
|
71
88
|
this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.getEnvironmentStatus.bind(this), [this.featureStatsbeatGauge]);
|
|
72
89
|
// Export Feature/Attach Statsbeat once upon app initialization after 15 second delay
|
|
73
90
|
setTimeout(async () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
try {
|
|
92
|
+
const collectionResult = await this.longIntervalMetricReader.collect();
|
|
93
|
+
if (collectionResult) {
|
|
94
|
+
this.longIntervalAzureExporter.export(collectionResult.resourceMetrics, (result) => {
|
|
95
|
+
if (result.code !== core_1.ExportResultCode.SUCCESS) {
|
|
96
|
+
api_1.diag.debug(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
77
99
|
}
|
|
78
|
-
|
|
100
|
+
else {
|
|
101
|
+
api_1.diag.debug("LongIntervalStatsbeat: No metrics collected");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
api_1.diag.debug(`LongIntervalStatsbeat: Error collecting metrics: ${error}`);
|
|
106
|
+
}
|
|
79
107
|
}, 15000); // 15 seconds
|
|
80
108
|
}
|
|
81
109
|
catch (error) {
|
|
@@ -85,13 +113,23 @@ class LongIntervalStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetric
|
|
|
85
113
|
getEnvironmentStatus(observableResult) {
|
|
86
114
|
this.setFeatures();
|
|
87
115
|
let attributes;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
116
|
+
// Only send instrumentation statsbeat if value is greater than zero
|
|
117
|
+
if (this.instrumentation > 0) {
|
|
118
|
+
attributes = {
|
|
119
|
+
...this.commonProperties,
|
|
120
|
+
feature: this.instrumentation,
|
|
121
|
+
type: types_js_1.StatsbeatFeatureType.INSTRUMENTATION,
|
|
122
|
+
};
|
|
123
|
+
observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });
|
|
91
124
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
// Only send feature statsbeat if value is greater than zero
|
|
126
|
+
if (this.feature > 0) {
|
|
127
|
+
attributes = {
|
|
128
|
+
...this.commonProperties,
|
|
129
|
+
feature: this.feature,
|
|
130
|
+
type: types_js_1.StatsbeatFeatureType.FEATURE,
|
|
131
|
+
};
|
|
132
|
+
observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });
|
|
95
133
|
}
|
|
96
134
|
}
|
|
97
135
|
setFeatures() {
|
|
@@ -102,26 +140,27 @@ class LongIntervalStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetric
|
|
|
102
140
|
this.instrumentation = JSON.parse(statsbeatFeatures).instrumentation;
|
|
103
141
|
}
|
|
104
142
|
catch (error) {
|
|
105
|
-
api_1.diag.
|
|
143
|
+
api_1.diag.debug(`LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`);
|
|
106
144
|
}
|
|
107
145
|
}
|
|
108
146
|
}
|
|
109
147
|
attachCallback(observableResult) {
|
|
110
|
-
const attributes =
|
|
148
|
+
const attributes = { ...this.commonProperties, ...this.attachProperties };
|
|
111
149
|
observableResult.observe(1, attributes);
|
|
112
150
|
}
|
|
113
151
|
shutdown() {
|
|
114
152
|
return this.longIntervalStatsbeatMeterProvider.shutdown();
|
|
115
153
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Singleton LongIntervalStatsbeatMetrics instance.
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
static getInstance(options) {
|
|
159
|
+
if (!LongIntervalStatsbeatMetrics.instance) {
|
|
160
|
+
LongIntervalStatsbeatMetrics.instance = new LongIntervalStatsbeatMetrics(options);
|
|
161
|
+
}
|
|
162
|
+
return LongIntervalStatsbeatMetrics.instance;
|
|
124
163
|
}
|
|
125
|
-
return instance;
|
|
126
164
|
}
|
|
165
|
+
exports.LongIntervalStatsbeatMetrics = LongIntervalStatsbeatMetrics;
|
|
127
166
|
//# sourceMappingURL=longIntervalStatsbeatMetrics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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AC,OAAO,EACrB,IAAI,EAAE,+BAAoB,CAAC,OAAO,GACnC,CAAC;YACF,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,oBAAO,UAAU,EAAG,CAAC;QAC7E,CAAC;IACH,CAAC;IAEO,WAAW;QACjB,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC;QACvE,IAAI,iBAAiB,EAAE,CAAC;YACtB,IAAI,CAAC;gBACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC;gBACrD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,eAAe,CAAC;YACvE,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,UAAI,CAAC,KAAK,CACR,2EAA2E,KAAK,GAAG,CACpF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,gBAAkC;QACvD,MAAM,UAAU,mCAAQ,IAAI,CAAC,gBAAgB,GAAK,IAAI,CAAC,gBAAgB,CAAE,CAAC;QAC1E,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,CAAC;IAC5D,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { diag } from \"@opentelemetry/api\";\nimport type { ExportResult } from \"@opentelemetry/core\";\nimport { ExportResultCode } from \"@opentelemetry/core\";\nimport type { PeriodicExportingMetricReaderOptions } from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { AzureMonitorExporterOptions } from \"../../index.js\";\nimport * as ai from \"../../utils/constants/applicationinsights.js\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics.js\";\nimport type {\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types.js\";\nimport { StatsbeatCounter, STATSBEAT_LANGUAGE, StatsbeatFeatureType } from \"./types.js\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter.js\";\nimport { getAttachType } from \"../../utils/metricUtils.js\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = getAttachType();\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n disableOfflineStorage: options.disableOfflineStorage,\n };\n\n this.setFeatures();\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n this.isInitialized = true;\n this.initialize();\n\n this.commonProperties = {\n os: this.os,\n rp: this.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: this.resourceIdentifier,\n };\n }\n\n private async initialize(): Promise<void> {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(\n this.getEnvironmentStatus.bind(this),\n [this.featureStatsbeatGauge],\n );\n\n // Export Feature/Attach Statsbeat once upon app initialization after 15 second delay\n setTimeout(async () => {\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n },\n );\n }, 15000); // 15 seconds\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private getEnvironmentStatus(observableResult: BatchObservableResult): void {\n this.setFeatures();\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private setFeatures(): void {\n const statsbeatFeatures = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n if (statsbeatFeatures) {\n try {\n this.feature = JSON.parse(statsbeatFeatures).feature;\n this.instrumentation = JSON.parse(statsbeatFeatures).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n }\n\n private attachCallback(observableResult: ObservableResult): void {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAQlC,4CAA0C;AAE1C,8CAAuD;AAEvD,4DAA0F;AAE1F,yFAAmE;AACnE,+DAAyD;AAMzD,yCAAwF;AACxF,iEAAuE;AACvE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,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,CAAC;IAC5D,CAAC;IACD;;;OAGG;IACI,MAAM,CAAC,WAAW,CAAC,OAAyB;QACjD,IAAI,CAAC,4BAA4B,CAAC,QAAQ,EAAE,CAAC;YAC3C,4BAA4B,CAAC,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,4BAA4B,CAAC,QAAQ,CAAC;IAC/C,CAAC;;AArLH,oEAsLC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { diag } from \"@opentelemetry/api\";\nimport type { ExportResult } from \"@opentelemetry/core\";\nimport { ExportResultCode } from \"@opentelemetry/core\";\nimport type { PeriodicExportingMetricReaderOptions } from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { AzureMonitorExporterOptions } from \"../../index.js\";\nimport * as ai from \"../../utils/constants/applicationinsights.js\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics.js\";\nimport type {\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types.js\";\nimport { StatsbeatCounter, STATSBEAT_LANGUAGE, StatsbeatFeatureType } from \"./types.js\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter.js\";\nimport { getAttachType } from \"../../utils/metricUtils.js\";\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nexport class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private static instance: LongIntervalStatsbeatMetrics | null = null;\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = getAttachType();\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n disableOfflineStorage: options.disableOfflineStorage,\n };\n\n this.setFeatures();\n\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider = new MeterProvider({\n readers: [this.longIntervalMetricReader],\n });\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n this.isInitialized = true;\n this.initialize();\n\n this.commonProperties = {\n os: this.os,\n rp: this.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: this.resourceIdentifier,\n };\n }\n\n private async initialize(): Promise<void> {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(\n this.getEnvironmentStatus.bind(this),\n [this.featureStatsbeatGauge],\n );\n\n // Export Feature/Attach Statsbeat once upon app initialization after 15 second delay\n setTimeout(async () => {\n try {\n const collectionResult = await this.longIntervalMetricReader.collect();\n if (collectionResult) {\n this.longIntervalAzureExporter.export(\n collectionResult.resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.debug(\n `LongIntervalStatsbeat: metrics export failed (error ${result.error})`,\n );\n }\n },\n );\n } else {\n diag.debug(\"LongIntervalStatsbeat: No metrics collected\");\n }\n } catch (error) {\n diag.debug(`LongIntervalStatsbeat: Error collecting metrics: ${error}`);\n }\n }, 15000); // 15 seconds\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private getEnvironmentStatus(observableResult: BatchObservableResult): void {\n this.setFeatures();\n let attributes;\n // Only send instrumentation statsbeat if value is greater than zero\n if (this.instrumentation > 0) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n // Only send feature statsbeat if value is greater than zero\n if (this.feature > 0) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private setFeatures(): void {\n const statsbeatFeatures = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n if (statsbeatFeatures) {\n try {\n this.feature = JSON.parse(statsbeatFeatures).feature;\n this.instrumentation = JSON.parse(statsbeatFeatures).instrumentation;\n } catch (error: any) {\n diag.debug(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n }\n\n private attachCallback(observableResult: ObservableResult): void {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n /**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\n public static getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!LongIntervalStatsbeatMetrics.instance) {\n LongIntervalStatsbeatMetrics.instance = new LongIntervalStatsbeatMetrics(options);\n }\n return LongIntervalStatsbeatMetrics.instance;\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StatsbeatMetrics } from "./statsbeatMetrics.js";
|
|
2
2
|
import type { StatsbeatOptions } from "./types.js";
|
|
3
3
|
export declare class NetworkStatsbeatMetrics extends StatsbeatMetrics {
|
|
4
|
+
private static instance;
|
|
4
5
|
private disableNonEssentialStatsbeat;
|
|
5
6
|
private commonProperties;
|
|
6
7
|
private networkProperties;
|
|
@@ -10,7 +11,6 @@ export declare class NetworkStatsbeatMetrics extends StatsbeatMetrics {
|
|
|
10
11
|
private networkStatsbeatMeter;
|
|
11
12
|
private networkStatsbeatMeterProvider;
|
|
12
13
|
private networkAzureExporter;
|
|
13
|
-
private networkMetricReader;
|
|
14
14
|
private cikey;
|
|
15
15
|
private runtimeVersion;
|
|
16
16
|
private language;
|
|
@@ -47,5 +47,10 @@ export declare class NetworkStatsbeatMetrics extends StatsbeatMetrics {
|
|
|
47
47
|
countException(exceptionType: Error): void;
|
|
48
48
|
private getNetworkStatsbeatCounter;
|
|
49
49
|
private getShortHost;
|
|
50
|
+
/**
|
|
51
|
+
* Singleton Network Statsbeat Metrics instance.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
static getInstance(options: StatsbeatOptions): NetworkStatsbeatMetrics;
|
|
50
55
|
}
|
|
51
56
|
//# sourceMappingURL=networkStatsbeatMetrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networkStatsbeatMetrics.d.ts","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAMpB,qBAAa,uBAAwB,SAAQ,gBAAgB;IAC3D,OAAO,CAAC,4BAA4B,CAAiD;IACrF,OAAO,CAAC,gBAAgB,CAA4B;IACpD,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,4BAA4B,CAAkB;IAEtD,OAAO,CAAC,0BAA0B,CAA+B;IACjE,OAAO,CAAC,qBAAqB,CAAQ;IACrC,OAAO,CAAC,6BAA6B,CAAgB;IACrD,OAAO,CAAC,oBAAoB,CAAgC;
|
|
1
|
+
{"version":3,"file":"networkStatsbeatMetrics.d.ts","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAMpB,qBAAa,uBAAwB,SAAQ,gBAAgB;IAC3D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwC;IAC/D,OAAO,CAAC,4BAA4B,CAAiD;IACrF,OAAO,CAAC,gBAAgB,CAA4B;IACpD,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,4BAA4B,CAAkB;IAEtD,OAAO,CAAC,0BAA0B,CAA+B;IACjE,OAAO,CAAC,qBA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AAG,IAAI;IAgBjD,OAAO,CAAC,0BAA0B;IAiBlC,OAAO,CAAC,YAAY;IAepB;;;OAGG;WACW,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,uBAAuB;CAM9E"}
|
|
@@ -13,15 +13,39 @@ const statsbeatExporter_js_1 = require("./statsbeatExporter.js");
|
|
|
13
13
|
const Constants_js_1 = require("../../Declarations/Constants.js");
|
|
14
14
|
const metricUtils_js_1 = require("../../utils/metricUtils.js");
|
|
15
15
|
class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
16
|
+
static instance = null;
|
|
17
|
+
disableNonEssentialStatsbeat = !!process.env[Constants_js_1.ENV_DISABLE_STATSBEAT];
|
|
18
|
+
commonProperties;
|
|
19
|
+
networkProperties;
|
|
20
|
+
isInitialized = false;
|
|
21
|
+
statsCollectionShortInterval = 900000; // 15 minutes
|
|
22
|
+
networkStatsbeatCollection = [];
|
|
23
|
+
networkStatsbeatMeter;
|
|
24
|
+
networkStatsbeatMeterProvider;
|
|
25
|
+
networkAzureExporter;
|
|
26
|
+
// Custom dimensions
|
|
27
|
+
cikey;
|
|
28
|
+
runtimeVersion;
|
|
29
|
+
language;
|
|
30
|
+
version;
|
|
31
|
+
attach = (0, metricUtils_js_1.getAttachType)();
|
|
32
|
+
// Observable Gauges
|
|
33
|
+
successCountGauge;
|
|
34
|
+
failureCountGauge;
|
|
35
|
+
retryCountGauge;
|
|
36
|
+
throttleCountGauge;
|
|
37
|
+
exceptionCountGauge;
|
|
38
|
+
averageDurationGauge;
|
|
39
|
+
// Non-essential Statsbeat Gauges
|
|
40
|
+
readFailureGauge;
|
|
41
|
+
writeFailureGauge;
|
|
42
|
+
// Network attributes
|
|
43
|
+
connectionString;
|
|
44
|
+
endpointUrl;
|
|
45
|
+
host;
|
|
16
46
|
constructor(options) {
|
|
17
47
|
super();
|
|
18
|
-
this.disableNonEssentialStatsbeat = !!process.env[Constants_js_1.ENV_DISABLE_STATSBEAT];
|
|
19
|
-
this.isInitialized = false;
|
|
20
|
-
this.statsCollectionShortInterval = 900000; // 15 minutes
|
|
21
|
-
this.networkStatsbeatCollection = [];
|
|
22
|
-
this.attach = (0, metricUtils_js_1.getAttachType)();
|
|
23
48
|
this.connectionString = super.getConnectionString(options.endpointUrl);
|
|
24
|
-
this.networkStatsbeatMeterProvider = new sdk_metrics_1.MeterProvider();
|
|
25
49
|
const exporterConfig = {
|
|
26
50
|
connectionString: this.connectionString,
|
|
27
51
|
};
|
|
@@ -31,8 +55,9 @@ class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
|
31
55
|
exporter: this.networkAzureExporter,
|
|
32
56
|
exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionShortInterval, // 15 minutes
|
|
33
57
|
};
|
|
34
|
-
this.
|
|
35
|
-
|
|
58
|
+
this.networkStatsbeatMeterProvider = new sdk_metrics_1.MeterProvider({
|
|
59
|
+
readers: [new sdk_metrics_1.PeriodicExportingMetricReader(networkMetricReaderOptions)],
|
|
60
|
+
});
|
|
36
61
|
this.networkStatsbeatMeter = this.networkStatsbeatMeterProvider.getMeter("Azure Monitor Network Statsbeat");
|
|
37
62
|
this.endpointUrl = options.endpointUrl;
|
|
38
63
|
this.runtimeVersion = process.version;
|
|
@@ -70,7 +95,6 @@ class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
|
70
95
|
return this.networkStatsbeatMeterProvider.shutdown();
|
|
71
96
|
}
|
|
72
97
|
async initialize() {
|
|
73
|
-
var _a, _b;
|
|
74
98
|
try {
|
|
75
99
|
await super.getResourceProvider();
|
|
76
100
|
// Add network observable callbacks
|
|
@@ -88,8 +112,8 @@ class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
|
88
112
|
this.exceptionCountGauge,
|
|
89
113
|
]);
|
|
90
114
|
if (!this.disableNonEssentialStatsbeat) {
|
|
91
|
-
|
|
92
|
-
|
|
115
|
+
this.readFailureGauge?.addCallback(this.readFailureCallback.bind(this));
|
|
116
|
+
this.writeFailureGauge?.addCallback(this.writeFailureCallback.bind(this));
|
|
93
117
|
}
|
|
94
118
|
this.averageDurationGauge.addCallback(this.durationCallback.bind(this));
|
|
95
119
|
}
|
|
@@ -100,9 +124,12 @@ class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
|
100
124
|
// Observable gauge callbacks
|
|
101
125
|
successCallback(observableResult) {
|
|
102
126
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
127
|
+
// Only send metrics if count is greater than zero
|
|
128
|
+
if (counter.totalSuccessfulRequestCount > 0) {
|
|
129
|
+
const attributes = { ...this.commonProperties, ...this.networkProperties };
|
|
130
|
+
observableResult.observe(counter.totalSuccessfulRequestCount, attributes);
|
|
131
|
+
counter.totalSuccessfulRequestCount = 0;
|
|
132
|
+
}
|
|
106
133
|
}
|
|
107
134
|
failureCallback(observableResult) {
|
|
108
135
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
@@ -111,70 +138,105 @@ class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
|
111
138
|
create a unqiue counter based on statusCode as well
|
|
112
139
|
append statusCode to attributes so the newly created attributes are unique.
|
|
113
140
|
*/
|
|
114
|
-
const attributes =
|
|
141
|
+
const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };
|
|
115
142
|
// For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode
|
|
116
143
|
for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
// Only send metrics if count is greater than zero
|
|
145
|
+
if (counter.totalFailedRequestCount[i].count > 0) {
|
|
146
|
+
attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;
|
|
147
|
+
observableResult.observe(this.failureCountGauge, counter.totalFailedRequestCount[i].count, {
|
|
148
|
+
...attributes,
|
|
149
|
+
});
|
|
150
|
+
counter.totalFailedRequestCount[i].count = 0;
|
|
151
|
+
}
|
|
120
152
|
}
|
|
121
153
|
}
|
|
122
154
|
retryCallback(observableResult) {
|
|
123
155
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
124
|
-
const attributes =
|
|
156
|
+
const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };
|
|
125
157
|
for (let i = 0; i < counter.retryCount.length; i++) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
158
|
+
// Only send metrics if count is greater than zero
|
|
159
|
+
if (counter.retryCount[i].count > 0) {
|
|
160
|
+
attributes.statusCode = counter.retryCount[i].statusCode;
|
|
161
|
+
observableResult.observe(this.retryCountGauge, counter.retryCount[i].count, {
|
|
162
|
+
...attributes,
|
|
163
|
+
});
|
|
164
|
+
counter.retryCount[i].count = 0;
|
|
165
|
+
}
|
|
129
166
|
}
|
|
130
167
|
}
|
|
131
168
|
throttleCallback(observableResult) {
|
|
132
169
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
133
|
-
const attributes =
|
|
170
|
+
const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };
|
|
134
171
|
for (let i = 0; i < counter.throttleCount.length; i++) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
172
|
+
// Only send metrics if count is greater than zero
|
|
173
|
+
if (counter.throttleCount[i].count > 0) {
|
|
174
|
+
attributes.statusCode = counter.throttleCount[i].statusCode;
|
|
175
|
+
observableResult.observe(this.throttleCountGauge, counter.throttleCount[i].count, {
|
|
176
|
+
...attributes,
|
|
177
|
+
});
|
|
178
|
+
counter.throttleCount[i].count = 0;
|
|
179
|
+
}
|
|
138
180
|
}
|
|
139
181
|
}
|
|
140
182
|
exceptionCallback(observableResult) {
|
|
141
183
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
142
|
-
const attributes =
|
|
184
|
+
const attributes = { ...this.networkProperties, ...this.commonProperties, exceptionType: "" };
|
|
143
185
|
for (let i = 0; i < counter.exceptionCount.length; i++) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
186
|
+
// Only send metrics if count is greater than zero
|
|
187
|
+
if (counter.exceptionCount[i].count > 0) {
|
|
188
|
+
attributes.exceptionType = counter.exceptionCount[i].exceptionType;
|
|
189
|
+
observableResult.observe(this.exceptionCountGauge, counter.exceptionCount[i].count, {
|
|
190
|
+
...attributes,
|
|
191
|
+
});
|
|
192
|
+
counter.exceptionCount[i].count = 0;
|
|
193
|
+
}
|
|
147
194
|
}
|
|
148
195
|
}
|
|
149
196
|
durationCallback(observableResult) {
|
|
150
197
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
151
|
-
const attributes =
|
|
198
|
+
const attributes = { ...this.networkProperties, ...this.commonProperties };
|
|
152
199
|
for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {
|
|
153
200
|
const currentCounter = this.networkStatsbeatCollection[i];
|
|
154
201
|
currentCounter.time = Number(new Date());
|
|
155
202
|
const intervalRequests = currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
203
|
+
// Only calculate average if there were actual requests
|
|
204
|
+
if (intervalRequests > 0) {
|
|
205
|
+
currentCounter.averageRequestExecutionTime =
|
|
206
|
+
(currentCounter.intervalRequestExecutionTime -
|
|
207
|
+
currentCounter.lastIntervalRequestExecutionTime) /
|
|
208
|
+
intervalRequests || 0;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
currentCounter.averageRequestExecutionTime = 0;
|
|
212
|
+
}
|
|
160
213
|
currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset
|
|
161
214
|
currentCounter.lastRequestCount = currentCounter.totalRequestCount;
|
|
162
215
|
currentCounter.lastTime = currentCounter.time;
|
|
163
216
|
}
|
|
164
|
-
|
|
165
|
-
counter.averageRequestExecutionTime
|
|
217
|
+
// Only report if there's a non-zero average duration
|
|
218
|
+
if (counter.averageRequestExecutionTime > 0) {
|
|
219
|
+
observableResult.observe(counter.averageRequestExecutionTime, attributes);
|
|
220
|
+
counter.averageRequestExecutionTime = 0;
|
|
221
|
+
}
|
|
166
222
|
}
|
|
167
223
|
readFailureCallback(observableResult) {
|
|
168
224
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
225
|
+
// Only send metrics if count is greater than zero
|
|
226
|
+
if (counter.totalReadFailureCount > 0) {
|
|
227
|
+
const attributes = { ...this.commonProperties, ...this.networkProperties };
|
|
228
|
+
observableResult.observe(counter.totalReadFailureCount, attributes);
|
|
229
|
+
counter.totalReadFailureCount = 0;
|
|
230
|
+
}
|
|
172
231
|
}
|
|
173
232
|
writeFailureCallback(observableResult) {
|
|
174
233
|
const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
234
|
+
// Only send metrics if count is greater than zero
|
|
235
|
+
if (counter.totalWriteFailureCount > 0) {
|
|
236
|
+
const attributes = { ...this.commonProperties, ...this.networkProperties };
|
|
237
|
+
observableResult.observe(counter.totalWriteFailureCount, attributes);
|
|
238
|
+
counter.totalWriteFailureCount = 0;
|
|
239
|
+
}
|
|
178
240
|
}
|
|
179
241
|
// Public methods to increase counters
|
|
180
242
|
countSuccess(duration) {
|
|
@@ -284,6 +346,16 @@ class NetworkStatsbeatMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
|
284
346
|
}
|
|
285
347
|
return shortHost;
|
|
286
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Singleton Network Statsbeat Metrics instance.
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
static getInstance(options) {
|
|
354
|
+
if (!NetworkStatsbeatMetrics.instance) {
|
|
355
|
+
NetworkStatsbeatMetrics.instance = new NetworkStatsbeatMetrics(options);
|
|
356
|
+
}
|
|
357
|
+
return NetworkStatsbeatMetrics.instance;
|
|
358
|
+
}
|
|
287
359
|
}
|
|
288
360
|
exports.NetworkStatsbeatMetrics = NetworkStatsbeatMetrics;
|
|
289
361
|
//# sourceMappingURL=networkStatsbeatMetrics.js.map
|