@azure/monitor-opentelemetry-exporter 1.0.0-beta.32 → 1.0.0-beta.34
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/LICENSE +21 -0
- package/dist/commonjs/Declarations/Constants.d.ts +10 -0
- package/dist/commonjs/Declarations/Constants.d.ts.map +1 -1
- package/dist/commonjs/Declarations/Constants.js +11 -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/customerSDKStats.d.ts +133 -0
- package/dist/commonjs/export/statsbeat/customerSDKStats.d.ts.map +1 -0
- package/dist/commonjs/export/statsbeat/customerSDKStats.js +528 -0
- package/dist/commonjs/export/statsbeat/customerSDKStats.js.map +1 -0
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js +35 -11
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js +52 -21
- 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 +77 -0
- package/dist/commonjs/export/statsbeat/types.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/types.js +105 -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 +92 -31
- 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 +3 -1
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +4 -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 +2 -1
- package/dist/commonjs/utils/constants/applicationinsights.d.ts.map +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.js +3 -2
- 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.d.ts.map +1 -1
- package/dist/commonjs/utils/logUtils.js +34 -15
- 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 +29 -14
- package/dist/commonjs/utils/spanUtils.js.map +1 -1
- package/dist/esm/Declarations/Constants.d.ts +10 -0
- package/dist/esm/Declarations/Constants.d.ts.map +1 -1
- package/dist/esm/Declarations/Constants.js +10 -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/customerSDKStats.d.ts +133 -0
- package/dist/esm/export/statsbeat/customerSDKStats.d.ts.map +1 -0
- package/dist/esm/export/statsbeat/customerSDKStats.js +523 -0
- package/dist/esm/export/statsbeat/customerSDKStats.js.map +1 -0
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js +35 -11
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js +52 -21
- 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 +77 -0
- package/dist/esm/export/statsbeat/types.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/types.js +103 -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 +91 -30
- 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 +3 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +4 -0
- 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 +2 -1
- package/dist/esm/utils/constants/applicationinsights.d.ts.map +1 -1
- package/dist/esm/utils/constants/applicationinsights.js +2 -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.d.ts.map +1 -1
- package/dist/esm/utils/logUtils.js +31 -12
- 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 +32 -17
- package/dist/esm/utils/spanUtils.js.map +1 -1
- package/package.json +34 -35
- 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
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CustomerSDKStatsMetrics = void 0;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const api_1 = require("@opentelemetry/api");
|
|
8
|
+
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
9
|
+
const ai = tslib_1.__importStar(require("../../utils/constants/applicationinsights.js"));
|
|
10
|
+
const statsbeatMetrics_js_1 = require("./statsbeatMetrics.js");
|
|
11
|
+
const types_js_1 = require("./types.js");
|
|
12
|
+
const types_js_2 = require("./types.js");
|
|
13
|
+
const metricUtils_js_1 = require("../../utils/metricUtils.js");
|
|
14
|
+
const statsbeatExporter_js_1 = require("./statsbeatExporter.js");
|
|
15
|
+
const types_js_3 = require("../../types.js");
|
|
16
|
+
/**
|
|
17
|
+
* Class that handles customer-facing SDK Stats metrics
|
|
18
|
+
* These metrics are sent to the customer's breeze endpoint
|
|
19
|
+
*
|
|
20
|
+
* Implements a singleton pattern to ensure only one set of customer SDK Stats metrics
|
|
21
|
+
* is exported every 15 minutes, regardless of the number of exporters or senders.
|
|
22
|
+
*/
|
|
23
|
+
class CustomerSDKStatsMetrics extends statsbeatMetrics_js_1.StatsbeatMetrics {
|
|
24
|
+
static _instance;
|
|
25
|
+
statsCollectionInterval = 900000; // 15 minutes
|
|
26
|
+
customerSDKStatsMeter;
|
|
27
|
+
customerSDKStatsMeterProvider;
|
|
28
|
+
customerSDKStatsExporter;
|
|
29
|
+
customerSDKStatsCounter;
|
|
30
|
+
customerSDKStatsMetricReader;
|
|
31
|
+
isInitialized = false;
|
|
32
|
+
// Custom dimensions
|
|
33
|
+
language;
|
|
34
|
+
version;
|
|
35
|
+
attach = (0, metricUtils_js_1.getAttachType)();
|
|
36
|
+
// Observable Gauges
|
|
37
|
+
itemSuccessCountGauge;
|
|
38
|
+
itemDropCountGauge;
|
|
39
|
+
itemRetryCountGauge;
|
|
40
|
+
// Customer SDK Stats properties
|
|
41
|
+
customerProperties;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super();
|
|
44
|
+
const exporterConfig = {
|
|
45
|
+
connectionString: `InstrumentationKey=${options.instrumentationKey};IngestionEndpoint=${options.endpointUrl}`,
|
|
46
|
+
};
|
|
47
|
+
this.customerSDKStatsExporter = new statsbeatExporter_js_1.AzureMonitorStatsbeatExporter(exporterConfig);
|
|
48
|
+
// Exports Customer SDK Stats every 15 minutes
|
|
49
|
+
const customerMetricReaderOptions = {
|
|
50
|
+
exporter: this.customerSDKStatsExporter,
|
|
51
|
+
exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionInterval,
|
|
52
|
+
};
|
|
53
|
+
this.customerSDKStatsMetricReader = new sdk_metrics_1.PeriodicExportingMetricReader(customerMetricReaderOptions);
|
|
54
|
+
this.customerSDKStatsMeterProvider = new sdk_metrics_1.MeterProvider({
|
|
55
|
+
readers: [this.customerSDKStatsMetricReader],
|
|
56
|
+
});
|
|
57
|
+
this.customerSDKStatsMeter = this.customerSDKStatsMeterProvider.getMeter("Azure Monitor Customer SDK Stats");
|
|
58
|
+
this.language = types_js_2.STATSBEAT_LANGUAGE;
|
|
59
|
+
this.version = ai.packageVersion;
|
|
60
|
+
this.itemSuccessCountGauge = this.customerSDKStatsMeter.createObservableGauge(types_js_2.CustomSDKStatsCounter.ITEM_SUCCESS_COUNT);
|
|
61
|
+
this.itemDropCountGauge = this.customerSDKStatsMeter.createObservableGauge(types_js_2.CustomSDKStatsCounter.ITEM_DROP_COUNT);
|
|
62
|
+
this.itemRetryCountGauge = this.customerSDKStatsMeter.createObservableGauge(types_js_2.CustomSDKStatsCounter.ITEM_RETRY_COUNT);
|
|
63
|
+
if (!this.isInitialized) {
|
|
64
|
+
this.initialize();
|
|
65
|
+
}
|
|
66
|
+
this.isInitialized = true;
|
|
67
|
+
// Initialize the single customer SDK Stats counter
|
|
68
|
+
this.customerSDKStatsCounter = new types_js_1.CustomerSDKStats();
|
|
69
|
+
this.customerProperties = {
|
|
70
|
+
language: this.language,
|
|
71
|
+
version: this.version,
|
|
72
|
+
computeType: this.attach,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get singleton instance of CustomerSDKStatsMetrics
|
|
77
|
+
* @param options - Configuration options for customer SDK Stats metrics
|
|
78
|
+
* @returns The singleton instance
|
|
79
|
+
*/
|
|
80
|
+
static getInstance(options) {
|
|
81
|
+
if (!CustomerSDKStatsMetrics._instance) {
|
|
82
|
+
CustomerSDKStatsMetrics._instance = new CustomerSDKStatsMetrics(options);
|
|
83
|
+
}
|
|
84
|
+
return CustomerSDKStatsMetrics._instance;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Shutdown the singleton instance
|
|
88
|
+
* Used for cleanup and complete shutdown
|
|
89
|
+
*/
|
|
90
|
+
static shutdown() {
|
|
91
|
+
if (CustomerSDKStatsMetrics._instance) {
|
|
92
|
+
const shutdownPromise = CustomerSDKStatsMetrics._instance.shutdown();
|
|
93
|
+
CustomerSDKStatsMetrics._instance = undefined;
|
|
94
|
+
return shutdownPromise;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Shuts down the customer SDK Stats metrics provider
|
|
100
|
+
* @returns Promise<void>
|
|
101
|
+
*/
|
|
102
|
+
shutdown() {
|
|
103
|
+
return this.customerSDKStatsMeterProvider.shutdown();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Initializes the customer SDK Stats metrics
|
|
107
|
+
* Sets up the resource provider and adds observable callbacks for each metric
|
|
108
|
+
* @returns Promise<void>
|
|
109
|
+
*/
|
|
110
|
+
async initialize() {
|
|
111
|
+
try {
|
|
112
|
+
await super.getResourceProvider();
|
|
113
|
+
this.customerSDKStatsMeter.addBatchObservableCallback(this.itemSuccessCallback.bind(this), [
|
|
114
|
+
this.itemSuccessCountGauge,
|
|
115
|
+
]);
|
|
116
|
+
this.customerSDKStatsMeter.addBatchObservableCallback(this.itemDropCallback.bind(this), [
|
|
117
|
+
this.itemDropCountGauge,
|
|
118
|
+
]);
|
|
119
|
+
this.customerSDKStatsMeter.addBatchObservableCallback(this.itemRetryCallback.bind(this), [
|
|
120
|
+
this.itemRetryCountGauge,
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
api_1.diag.debug("Call to get the resource provider failed for customer SDK Stats metrics.");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Observable gauge callbacks
|
|
128
|
+
itemSuccessCallback(observableResult) {
|
|
129
|
+
const counter = this.customerSDKStatsCounter;
|
|
130
|
+
const attributes = { ...this.customerProperties, telemetry_type: types_js_2.TelemetryType.UNKNOWN };
|
|
131
|
+
// For each { telemetry_type -> count } mapping, call observe, passing the count and attributes that include the telemetry_type
|
|
132
|
+
for (const [telemetry_type, count] of counter.totalItemSuccessCount.entries()) {
|
|
133
|
+
// Only send metrics if count is greater than zero
|
|
134
|
+
if (count > 0) {
|
|
135
|
+
attributes.telemetry_type = telemetry_type;
|
|
136
|
+
observableResult.observe(this.itemSuccessCountGauge, count, {
|
|
137
|
+
...attributes,
|
|
138
|
+
});
|
|
139
|
+
counter.totalItemSuccessCount.set(telemetry_type, 0);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
itemDropCallback(observableResult) {
|
|
144
|
+
const counter = this.customerSDKStatsCounter;
|
|
145
|
+
const baseAttributes = {
|
|
146
|
+
...this.customerProperties,
|
|
147
|
+
"drop.code": types_js_1.DropCode.UNKNOWN,
|
|
148
|
+
telemetry_type: types_js_2.TelemetryType.UNKNOWN,
|
|
149
|
+
};
|
|
150
|
+
// Iterate through the nested Map structure: telemetry_type -> drop.code -> reason -> telemetry_success -> count
|
|
151
|
+
for (const [telemetryType, dropCodeMap] of counter.totalItemDropCount.entries()) {
|
|
152
|
+
for (const [dropCode, reasonMap] of dropCodeMap.entries()) {
|
|
153
|
+
for (const [reason, successMap] of reasonMap.entries()) {
|
|
154
|
+
for (const [success, count] of successMap.entries()) {
|
|
155
|
+
const attributes = { ...baseAttributes };
|
|
156
|
+
attributes.telemetry_type = telemetryType;
|
|
157
|
+
attributes["drop.code"] = dropCode;
|
|
158
|
+
// Include drop.reason for all cases
|
|
159
|
+
if (reason) {
|
|
160
|
+
attributes["drop.reason"] = reason;
|
|
161
|
+
}
|
|
162
|
+
// Include telemetry_success only for request/dependency telemetry when success is not null
|
|
163
|
+
if ((telemetryType === types_js_2.TelemetryType.REQUEST ||
|
|
164
|
+
telemetryType === types_js_2.TelemetryType.DEPENDENCY) &&
|
|
165
|
+
success !== null) {
|
|
166
|
+
attributes["telemetry_success"] = success;
|
|
167
|
+
}
|
|
168
|
+
// Only send metrics if count is greater than zero
|
|
169
|
+
if (count > 0) {
|
|
170
|
+
observableResult.observe(this.itemDropCountGauge, count, {
|
|
171
|
+
...attributes,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
// Reset the count to 0
|
|
175
|
+
successMap.set(success, 0);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
itemRetryCallback(observableResult) {
|
|
182
|
+
const counter = this.customerSDKStatsCounter;
|
|
183
|
+
const baseAttributes = {
|
|
184
|
+
...this.customerProperties,
|
|
185
|
+
"retry.code": types_js_1.RetryCode.UNKNOWN,
|
|
186
|
+
telemetry_type: types_js_2.TelemetryType.UNKNOWN,
|
|
187
|
+
};
|
|
188
|
+
// Iterate through the nested Map structure: telemetry_type -> retry.code -> reason -> count
|
|
189
|
+
for (const [telemetryType, retryCodeMap] of counter.totalItemRetryCount.entries()) {
|
|
190
|
+
for (const [retryCode, reasonMap] of retryCodeMap.entries()) {
|
|
191
|
+
for (const [reason, count] of reasonMap.entries()) {
|
|
192
|
+
const attributes = { ...baseAttributes };
|
|
193
|
+
attributes.telemetry_type = telemetryType;
|
|
194
|
+
attributes["retry.code"] = retryCode;
|
|
195
|
+
// Include retry.reason for all cases
|
|
196
|
+
if (reason) {
|
|
197
|
+
attributes["retry.reason"] = reason;
|
|
198
|
+
}
|
|
199
|
+
// Only send metrics if count is greater than zero
|
|
200
|
+
if (count > 0) {
|
|
201
|
+
observableResult.observe(this.itemRetryCountGauge, count, {
|
|
202
|
+
...attributes,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// Reset the count to 0
|
|
206
|
+
reasonMap.set(reason, 0);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Public methods to track metrics
|
|
212
|
+
/**
|
|
213
|
+
* Tracks succcessful items
|
|
214
|
+
* @param envelopes - Number of successful envelopes
|
|
215
|
+
* @param telemetry_type - The type of telemetry being tracked
|
|
216
|
+
*/
|
|
217
|
+
countSuccessfulItems(envelopes) {
|
|
218
|
+
const counter = this.customerSDKStatsCounter;
|
|
219
|
+
let telemetry_type;
|
|
220
|
+
// Get the current count for this telemetry type, or 0 if it doesn't exist
|
|
221
|
+
for (const envelope of envelopes) {
|
|
222
|
+
telemetry_type = this.getTelemetryTypeFromEnvelope(envelope);
|
|
223
|
+
const currentCount = counter.totalItemSuccessCount.get(telemetry_type) || 0;
|
|
224
|
+
counter.totalItemSuccessCount.set(telemetry_type, currentCount + 1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Tracks dropped items
|
|
229
|
+
* @param envelopes - Array of envelopes dropped
|
|
230
|
+
* @param dropCode - The drop code indicating the reason for drop
|
|
231
|
+
* @param exceptionMessage - Optional exception message when dropCode is CLIENT_EXCEPTION
|
|
232
|
+
* @param exceptionType - Optional explicit exception type override when dropCode is CLIENT_EXCEPTION
|
|
233
|
+
*/
|
|
234
|
+
countDroppedItems(envelopes, dropCode, exceptionMessage, exceptionType) {
|
|
235
|
+
const counter = this.customerSDKStatsCounter;
|
|
236
|
+
let telemetry_type;
|
|
237
|
+
for (const envelope of envelopes) {
|
|
238
|
+
telemetry_type = this.getTelemetryTypeFromEnvelope(envelope);
|
|
239
|
+
let dropCodeMap = counter.totalItemDropCount.get(telemetry_type);
|
|
240
|
+
if (!dropCodeMap) {
|
|
241
|
+
dropCodeMap = new Map();
|
|
242
|
+
counter.totalItemDropCount.set(telemetry_type, dropCodeMap);
|
|
243
|
+
}
|
|
244
|
+
// Get or create the reason map for this dropCode
|
|
245
|
+
let reasonMap = dropCodeMap.get(dropCode);
|
|
246
|
+
if (!reasonMap) {
|
|
247
|
+
reasonMap = new Map();
|
|
248
|
+
dropCodeMap.set(dropCode, reasonMap);
|
|
249
|
+
}
|
|
250
|
+
// Generate a low-cardinality, informative reason description
|
|
251
|
+
const reason = this.getDropReason(dropCode, exceptionMessage, exceptionType);
|
|
252
|
+
// Get or create the success map for this reason
|
|
253
|
+
let successMap = reasonMap.get(reason);
|
|
254
|
+
if (!successMap) {
|
|
255
|
+
successMap = new Map();
|
|
256
|
+
reasonMap.set(reason, successMap);
|
|
257
|
+
}
|
|
258
|
+
// For non-request/dependency telemetry or when success is not provided, use null as the success key
|
|
259
|
+
const individualTelemetrySuccess = this.getTelemetrySuccessFromEnvelope(envelope);
|
|
260
|
+
const successKey = (telemetry_type === types_js_2.TelemetryType.REQUEST || telemetry_type === types_js_2.TelemetryType.DEPENDENCY) &&
|
|
261
|
+
individualTelemetrySuccess !== undefined
|
|
262
|
+
? individualTelemetrySuccess
|
|
263
|
+
: null;
|
|
264
|
+
// Update the count for this reason and success combination
|
|
265
|
+
const currentCount = successMap.get(successKey) || 0;
|
|
266
|
+
successMap.set(successKey, currentCount + 1);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Generates a low-cardinality, informative description for drop reasons
|
|
271
|
+
* @param dropCode - The drop code (enum value or status code number)
|
|
272
|
+
* @param exceptionMessage - Optional exception message for CLIENT_EXCEPTION
|
|
273
|
+
* @param exceptionType - Optional explicit exception type override for CLIENT_EXCEPTION
|
|
274
|
+
* @returns A descriptive reason string with low cardinality
|
|
275
|
+
*/
|
|
276
|
+
getDropReason(dropCode, exceptionMessage, exceptionType) {
|
|
277
|
+
if (dropCode === types_js_1.DropCode.CLIENT_EXCEPTION) {
|
|
278
|
+
// If an explicit exception type is provided, use it
|
|
279
|
+
if (exceptionType) {
|
|
280
|
+
return exceptionType;
|
|
281
|
+
}
|
|
282
|
+
// For client exceptions, derive a well-known exception category from the exception message
|
|
283
|
+
if (exceptionMessage) {
|
|
284
|
+
return this.categorizeExceptionMessage(exceptionMessage);
|
|
285
|
+
}
|
|
286
|
+
return types_js_1.ExceptionType.CLIENT_EXCEPTION; // Default to "Client exception" if no message provided
|
|
287
|
+
}
|
|
288
|
+
// Handle status code drop codes (numeric values)
|
|
289
|
+
if (typeof dropCode === "number") {
|
|
290
|
+
return this.categorizeStatusCode(dropCode);
|
|
291
|
+
}
|
|
292
|
+
// Handle other enum drop codes
|
|
293
|
+
switch (dropCode) {
|
|
294
|
+
case types_js_1.DropCode.CLIENT_READONLY:
|
|
295
|
+
return types_js_1.DropReason.CLIENT_READONLY;
|
|
296
|
+
case types_js_1.DropCode.CLIENT_PERSISTENCE_CAPACITY:
|
|
297
|
+
return types_js_1.DropReason.CLIENT_PERSISTENCE_CAPACITY;
|
|
298
|
+
case types_js_1.DropCode.CLIENT_STORAGE_DISABLED:
|
|
299
|
+
return types_js_1.DropReason.CLIENT_STORAGE_DISABLED;
|
|
300
|
+
case types_js_1.DropCode.UNKNOWN:
|
|
301
|
+
default:
|
|
302
|
+
return types_js_1.DropReason.UNKNOWN;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Categorizes exception messages into well-known exception categories
|
|
307
|
+
* @param exceptionMessage - The exception message to categorize
|
|
308
|
+
* @returns A well-known exception category string
|
|
309
|
+
*/
|
|
310
|
+
categorizeExceptionMessage(exceptionMessage) {
|
|
311
|
+
const message = exceptionMessage.toLowerCase();
|
|
312
|
+
if (message.includes("timeout") || message.includes("timed out")) {
|
|
313
|
+
return types_js_1.ExceptionType.TIMEOUT_EXCEPTION;
|
|
314
|
+
}
|
|
315
|
+
if (message.includes("network") ||
|
|
316
|
+
message.includes("connection") ||
|
|
317
|
+
message.includes("dns") ||
|
|
318
|
+
message.includes("socket")) {
|
|
319
|
+
return types_js_1.ExceptionType.NETWORK_EXCEPTION;
|
|
320
|
+
}
|
|
321
|
+
if (message.includes("disk") ||
|
|
322
|
+
message.includes("storage") ||
|
|
323
|
+
message.includes("file") ||
|
|
324
|
+
message.includes("persist")) {
|
|
325
|
+
return types_js_1.ExceptionType.STORAGE_EXCEPTION;
|
|
326
|
+
}
|
|
327
|
+
// Default to Client exception for any other cases
|
|
328
|
+
return types_js_1.ExceptionType.CLIENT_EXCEPTION;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Categorizes HTTP status codes into informative descriptions
|
|
332
|
+
* @param statusCode - The HTTP status code
|
|
333
|
+
* @returns A descriptive category string
|
|
334
|
+
*/
|
|
335
|
+
categorizeStatusCode(statusCode) {
|
|
336
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
337
|
+
switch (statusCode) {
|
|
338
|
+
case 400:
|
|
339
|
+
return "Bad request";
|
|
340
|
+
case 401:
|
|
341
|
+
return "Unauthorized";
|
|
342
|
+
case 403:
|
|
343
|
+
return "Forbidden";
|
|
344
|
+
case 404:
|
|
345
|
+
return "Not found";
|
|
346
|
+
case 408:
|
|
347
|
+
return "Request timeout";
|
|
348
|
+
case 413:
|
|
349
|
+
return "Payload too large";
|
|
350
|
+
case 429:
|
|
351
|
+
return "Too many requests";
|
|
352
|
+
default:
|
|
353
|
+
return "Client error 4xx";
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (statusCode >= 500 && statusCode < 600) {
|
|
357
|
+
switch (statusCode) {
|
|
358
|
+
case 500:
|
|
359
|
+
return "Internal server error";
|
|
360
|
+
case 502:
|
|
361
|
+
return "Bad gateway";
|
|
362
|
+
case 503:
|
|
363
|
+
return "Service unavailable";
|
|
364
|
+
case 504:
|
|
365
|
+
return "Gateway timeout";
|
|
366
|
+
default:
|
|
367
|
+
return "Server error 5xx";
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return `status_${statusCode}`;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Tracks retried envelopes
|
|
374
|
+
* @param envelopes - Number of envelopes retried
|
|
375
|
+
* @param retryCode - The retry code indicating the reason for retry
|
|
376
|
+
* @param exceptionMessage - Optional exception message when retryCode is CLIENT_EXCEPTION
|
|
377
|
+
* @param exceptionType - Optional explicit exception type override when retryCode is CLIENT_EXCEPTION
|
|
378
|
+
*/
|
|
379
|
+
countRetryItems(envelopes, retryCode, exceptionMessage, exceptionType) {
|
|
380
|
+
const counter = this.customerSDKStatsCounter;
|
|
381
|
+
let telemetry_type;
|
|
382
|
+
for (const envelope of envelopes) {
|
|
383
|
+
telemetry_type = this.getTelemetryTypeFromEnvelope(envelope);
|
|
384
|
+
// Get or create the retryCode map for this telemetry_type
|
|
385
|
+
let retryCodeMap = counter.totalItemRetryCount.get(telemetry_type);
|
|
386
|
+
if (!retryCodeMap) {
|
|
387
|
+
retryCodeMap = new Map();
|
|
388
|
+
counter.totalItemRetryCount.set(telemetry_type, retryCodeMap);
|
|
389
|
+
}
|
|
390
|
+
// Get or create the reason map for this retryCode
|
|
391
|
+
let reasonMap = retryCodeMap.get(retryCode);
|
|
392
|
+
if (!reasonMap) {
|
|
393
|
+
reasonMap = new Map();
|
|
394
|
+
retryCodeMap.set(retryCode, reasonMap);
|
|
395
|
+
}
|
|
396
|
+
// Generate a low-cardinality, informative reason description
|
|
397
|
+
const reason = this.getRetryReason(retryCode, exceptionMessage, exceptionType);
|
|
398
|
+
// Update the count for this reason
|
|
399
|
+
const currentCount = reasonMap.get(reason) || 0;
|
|
400
|
+
reasonMap.set(reason, currentCount + 1);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Generates a low-cardinality, informative description for retry reasons
|
|
405
|
+
* @param retryCode - The retry code (enum value or status code number)
|
|
406
|
+
* @param exceptionMessage - Optional exception message for CLIENT_EXCEPTION
|
|
407
|
+
* @param exceptionType - Optional explicit exception type override for CLIENT_EXCEPTION
|
|
408
|
+
* @returns A descriptive reason string with low cardinality
|
|
409
|
+
*/
|
|
410
|
+
getRetryReason(retryCode, exceptionMessage, exceptionType) {
|
|
411
|
+
if (retryCode === types_js_1.RetryCode.CLIENT_EXCEPTION) {
|
|
412
|
+
// If an explicit exception type is provided, use it
|
|
413
|
+
if (exceptionType) {
|
|
414
|
+
return exceptionType;
|
|
415
|
+
}
|
|
416
|
+
// For client exceptions, derive a low-cardinality reason from the exception message
|
|
417
|
+
if (exceptionMessage) {
|
|
418
|
+
return this.categorizeExceptionMessage(exceptionMessage);
|
|
419
|
+
}
|
|
420
|
+
return types_js_1.ExceptionType.CLIENT_EXCEPTION;
|
|
421
|
+
}
|
|
422
|
+
// Handle status code retry codes (numeric values)
|
|
423
|
+
if (typeof retryCode === "number") {
|
|
424
|
+
return this.categorizeStatusCode(retryCode);
|
|
425
|
+
}
|
|
426
|
+
// Handle other enum retry codes
|
|
427
|
+
switch (retryCode) {
|
|
428
|
+
case types_js_1.RetryCode.CLIENT_TIMEOUT:
|
|
429
|
+
return types_js_1.RetryReason.CLIENT_TIMEOUT;
|
|
430
|
+
case types_js_1.RetryCode.UNKNOWN:
|
|
431
|
+
default:
|
|
432
|
+
return types_js_1.RetryReason.UNKNOWN;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Check if a metric name corresponds to a performance counter
|
|
437
|
+
* @param metricName - The name of the metric to check
|
|
438
|
+
* @returns true if the metric name is a performance counter, false otherwise
|
|
439
|
+
*/
|
|
440
|
+
isPerformanceCounterMetric(metricName) {
|
|
441
|
+
return Object.values(types_js_3.BreezePerformanceCounterNames).includes(metricName);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Extract telemetry type from an envelope based on its baseType
|
|
445
|
+
* @param envelope - The envelope to extract telemetry type from
|
|
446
|
+
* @returns The corresponding telemetry type
|
|
447
|
+
*/
|
|
448
|
+
getTelemetryTypeFromEnvelope(envelope) {
|
|
449
|
+
if (envelope.data && envelope.data.baseType) {
|
|
450
|
+
switch (envelope.data.baseType) {
|
|
451
|
+
case "MessageData":
|
|
452
|
+
return types_js_2.TelemetryType.TRACE;
|
|
453
|
+
case "AvailabilityData":
|
|
454
|
+
return types_js_2.TelemetryType.AVAILABILITY;
|
|
455
|
+
case "TelemetryEventData":
|
|
456
|
+
return types_js_2.TelemetryType.CUSTOM_EVENT;
|
|
457
|
+
case "TelemetryExceptionData":
|
|
458
|
+
return types_js_2.TelemetryType.EXCEPTION;
|
|
459
|
+
case "PageViewData":
|
|
460
|
+
return types_js_2.TelemetryType.PAGE_VIEW;
|
|
461
|
+
case "RemoteDependencyData":
|
|
462
|
+
return types_js_2.TelemetryType.DEPENDENCY;
|
|
463
|
+
case "RequestData":
|
|
464
|
+
return types_js_2.TelemetryType.REQUEST;
|
|
465
|
+
case "MetricData": {
|
|
466
|
+
const metricsData = envelope.data.baseData;
|
|
467
|
+
if (metricsData && metricsData.metrics && metricsData.metrics.length > 0) {
|
|
468
|
+
// Check if any of the metrics are performance counters
|
|
469
|
+
const hasPerformanceCounter = metricsData.metrics.some((metric) => this.isPerformanceCounterMetric(metric.name));
|
|
470
|
+
return hasPerformanceCounter
|
|
471
|
+
? types_js_2.TelemetryType.PERFORMANCE_COUNTER
|
|
472
|
+
: types_js_2.TelemetryType.CUSTOM_METRIC;
|
|
473
|
+
}
|
|
474
|
+
return types_js_2.TelemetryType.CUSTOM_METRIC;
|
|
475
|
+
}
|
|
476
|
+
default:
|
|
477
|
+
return types_js_2.TelemetryType.UNKNOWN;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return types_js_2.TelemetryType.UNKNOWN;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Extract telemetry success value from an envelope for REQUEST and DEPENDENCY telemetry types
|
|
484
|
+
* @param envelope - The envelope to extract success value from
|
|
485
|
+
* @returns The success value if available, undefined otherwise
|
|
486
|
+
*/
|
|
487
|
+
getTelemetrySuccessFromEnvelope(envelope) {
|
|
488
|
+
if (!envelope.data || !envelope.data.baseData) {
|
|
489
|
+
return undefined;
|
|
490
|
+
}
|
|
491
|
+
const baseType = envelope.data.baseType;
|
|
492
|
+
if (baseType === "RequestData") {
|
|
493
|
+
const requestData = envelope.data.baseData;
|
|
494
|
+
return requestData.success;
|
|
495
|
+
}
|
|
496
|
+
else if (baseType === "RemoteDependencyData") {
|
|
497
|
+
const dependencyData = envelope.data.baseData;
|
|
498
|
+
return dependencyData.success;
|
|
499
|
+
}
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Checks if the given error is a timeout-related error
|
|
504
|
+
* @param error - The error to check
|
|
505
|
+
* @returns true if the error is timeout-related, false otherwise
|
|
506
|
+
*/
|
|
507
|
+
isTimeoutError(error) {
|
|
508
|
+
// Check for various timeout error codes that indicate client timeouts
|
|
509
|
+
const timeoutErrorCodes = [
|
|
510
|
+
"ETIMEDOUT", // Connection timed out
|
|
511
|
+
"ESOCKETTIMEDOUT", // Socket timeout
|
|
512
|
+
"ECONNRESET", // Connection reset (often due to timeout)
|
|
513
|
+
"ENOTFOUND", // DNS lookup failed/timeout
|
|
514
|
+
];
|
|
515
|
+
if (error && error.code && timeoutErrorCodes.includes(error.code)) {
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
// Also check if the error message contains timeout-related keywords
|
|
519
|
+
if (error && error.message) {
|
|
520
|
+
const timeoutKeywords = ["timeout", "timed out", "connection reset"];
|
|
521
|
+
const errorMessage = error.message.toLowerCase();
|
|
522
|
+
return timeoutKeywords.some((keyword) => errorMessage.includes(keyword));
|
|
523
|
+
}
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
exports.CustomerSDKStatsMetrics = CustomerSDKStatsMetrics;
|
|
528
|
+
//# sourceMappingURL=customerSDKStats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customerSDKStats.js","sourceRoot":"","sources":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CAAC,IAAI,CAAC,QAAuB,CAAC;YAC1D,OAAO,WAAW,CAAC,OAAO,CAAC;QAC7B,CAAC;aAAM,IAAI,QAAQ,KAAK,sBAAsB,EAAE,CAAC;YAC/C,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAgC,CAAC;YACtE,OAAO,cAAc,CAAC,OAAO,CAAC;QAChC,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,KAA0C;QAC9D,sEAAsE;QACtE,MAAM,iBAAiB,GAAG;YACxB,WAAW,EAAE,uBAAuB;YACpC,iBAAiB,EAAE,iBAAiB;YACpC,YAAY,EAAE,0CAA0C;YACxD,WAAW,EAAE,4BAA4B;SAC1C,CAAC;QAEF,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,oEAAoE;QACpE,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAC3B,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC;YACrE,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACjD,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlmBD,0DAkmBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BatchObservableResult, Meter, ObservableGauge } from \"@opentelemetry/api\";\nimport { diag } from \"@opentelemetry/api\";\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 { CustomerSDKStatsProperties, StatsbeatOptions } from \"./types.js\";\nimport {\n CustomerSDKStats,\n DropCode,\n RetryCode,\n ExceptionType,\n DropReason,\n RetryReason,\n} from \"./types.js\";\nimport { CustomSDKStatsCounter, STATSBEAT_LANGUAGE, TelemetryType } from \"./types.js\";\nimport { getAttachType } from \"../../utils/metricUtils.js\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter.js\";\nimport { BreezePerformanceCounterNames } from \"../../types.js\";\nimport type { MetricsData, RemoteDependencyData, RequestData } from \"../../generated/index.js\";\nimport type { TelemetryItem as Envelope } from \"../../generated/index.js\";\n\n/**\n * Class that handles customer-facing SDK Stats metrics\n * These metrics are sent to the customer's breeze endpoint\n *\n * Implements a singleton pattern to ensure only one set of customer SDK Stats metrics\n * is exported every 15 minutes, regardless of the number of exporters or senders.\n */\nexport class CustomerSDKStatsMetrics extends StatsbeatMetrics {\n private static _instance: CustomerSDKStatsMetrics | undefined;\n\n private statsCollectionInterval: number = 900000; // 15 minutes\n private customerSDKStatsMeter: Meter;\n private customerSDKStatsMeterProvider: MeterProvider;\n private customerSDKStatsExporter: AzureMonitorStatsbeatExporter;\n private customerSDKStatsCounter: CustomerSDKStats;\n private customerSDKStatsMetricReader: PeriodicExportingMetricReader;\n private isInitialized: boolean = false;\n\n // Custom dimensions\n private language: string;\n private version: string;\n private attach: string = getAttachType();\n\n // Observable Gauges\n private itemSuccessCountGauge: ObservableGauge;\n private itemDropCountGauge: ObservableGauge;\n private itemRetryCountGauge: ObservableGauge;\n\n // Customer SDK Stats properties\n private customerProperties: CustomerSDKStatsProperties;\n\n private constructor(options: StatsbeatOptions) {\n super();\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: `InstrumentationKey=${options.instrumentationKey};IngestionEndpoint=${options.endpointUrl}`,\n };\n\n this.customerSDKStatsExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n // Exports Customer SDK Stats every 15 minutes\n const customerMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.customerSDKStatsExporter,\n exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionInterval,\n };\n this.customerSDKStatsMetricReader = new PeriodicExportingMetricReader(\n customerMetricReaderOptions,\n );\n this.customerSDKStatsMeterProvider = new MeterProvider({\n readers: [this.customerSDKStatsMetricReader],\n });\n\n this.customerSDKStatsMeter = this.customerSDKStatsMeterProvider.getMeter(\n \"Azure Monitor Customer SDK Stats\",\n );\n\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n\n this.itemSuccessCountGauge = this.customerSDKStatsMeter.createObservableGauge(\n CustomSDKStatsCounter.ITEM_SUCCESS_COUNT,\n );\n this.itemDropCountGauge = this.customerSDKStatsMeter.createObservableGauge(\n CustomSDKStatsCounter.ITEM_DROP_COUNT,\n );\n this.itemRetryCountGauge = this.customerSDKStatsMeter.createObservableGauge(\n CustomSDKStatsCounter.ITEM_RETRY_COUNT,\n );\n\n if (!this.isInitialized) {\n this.initialize();\n }\n this.isInitialized = true;\n\n // Initialize the single customer SDK Stats counter\n this.customerSDKStatsCounter = new CustomerSDKStats();\n\n this.customerProperties = {\n language: this.language,\n version: this.version,\n computeType: this.attach,\n };\n }\n\n /**\n * Get singleton instance of CustomerSDKStatsMetrics\n * @param options - Configuration options for customer SDK Stats metrics\n * @returns The singleton instance\n */\n public static getInstance(options: StatsbeatOptions): CustomerSDKStatsMetrics {\n if (!CustomerSDKStatsMetrics._instance) {\n CustomerSDKStatsMetrics._instance = new CustomerSDKStatsMetrics(options);\n }\n return CustomerSDKStatsMetrics._instance;\n }\n\n /**\n * Shutdown the singleton instance\n * Used for cleanup and complete shutdown\n */\n public static shutdown(): Promise<void> | undefined {\n if (CustomerSDKStatsMetrics._instance) {\n const shutdownPromise = CustomerSDKStatsMetrics._instance.shutdown();\n CustomerSDKStatsMetrics._instance = undefined;\n return shutdownPromise;\n }\n return undefined;\n }\n\n /**\n * Shuts down the customer SDK Stats metrics provider\n * @returns Promise<void>\n */\n public shutdown(): Promise<void> {\n return this.customerSDKStatsMeterProvider.shutdown();\n }\n\n /**\n * Initializes the customer SDK Stats metrics\n * Sets up the resource provider and adds observable callbacks for each metric\n * @returns Promise<void>\n */\n private async initialize(): Promise<void> {\n try {\n await super.getResourceProvider();\n this.customerSDKStatsMeter.addBatchObservableCallback(this.itemSuccessCallback.bind(this), [\n this.itemSuccessCountGauge,\n ]);\n this.customerSDKStatsMeter.addBatchObservableCallback(this.itemDropCallback.bind(this), [\n this.itemDropCountGauge,\n ]);\n this.customerSDKStatsMeter.addBatchObservableCallback(this.itemRetryCallback.bind(this), [\n this.itemRetryCountGauge,\n ]);\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed for customer SDK Stats metrics.\");\n }\n }\n\n // Observable gauge callbacks\n private itemSuccessCallback(observableResult: BatchObservableResult): void {\n const counter: CustomerSDKStats = this.customerSDKStatsCounter;\n const attributes = { ...this.customerProperties, telemetry_type: TelemetryType.UNKNOWN };\n\n // For each { telemetry_type -> count } mapping, call observe, passing the count and attributes that include the telemetry_type\n for (const [telemetry_type, count] of counter.totalItemSuccessCount.entries()) {\n // Only send metrics if count is greater than zero\n if (count > 0) {\n attributes.telemetry_type = telemetry_type;\n observableResult.observe(this.itemSuccessCountGauge, count, {\n ...attributes,\n });\n counter.totalItemSuccessCount.set(telemetry_type, 0);\n }\n }\n }\n\n private itemDropCallback(observableResult: BatchObservableResult): void {\n const counter: CustomerSDKStats = this.customerSDKStatsCounter;\n const baseAttributes: CustomerSDKStatsProperties & {\n \"drop.code\": DropCode | number;\n telemetry_type: TelemetryType;\n } = {\n ...this.customerProperties,\n \"drop.code\": DropCode.UNKNOWN,\n telemetry_type: TelemetryType.UNKNOWN,\n };\n\n // Iterate through the nested Map structure: telemetry_type -> drop.code -> reason -> telemetry_success -> count\n for (const [telemetryType, dropCodeMap] of counter.totalItemDropCount.entries()) {\n for (const [dropCode, reasonMap] of dropCodeMap.entries()) {\n for (const [reason, successMap] of reasonMap.entries()) {\n for (const [success, count] of successMap.entries()) {\n const attributes = { ...baseAttributes };\n attributes.telemetry_type = telemetryType;\n attributes[\"drop.code\"] = dropCode;\n\n // Include drop.reason for all cases\n if (reason) {\n (attributes as any)[\"drop.reason\"] = reason;\n }\n\n // Include telemetry_success only for request/dependency telemetry when success is not null\n if (\n (telemetryType === TelemetryType.REQUEST ||\n telemetryType === TelemetryType.DEPENDENCY) &&\n success !== null\n ) {\n (attributes as any)[\"telemetry_success\"] = success;\n }\n\n // Only send metrics if count is greater than zero\n if (count > 0) {\n observableResult.observe(this.itemDropCountGauge, count, {\n ...attributes,\n });\n }\n\n // Reset the count to 0\n successMap.set(success, 0);\n }\n }\n }\n }\n }\n\n private itemRetryCallback(observableResult: BatchObservableResult): void {\n const counter: CustomerSDKStats = this.customerSDKStatsCounter;\n const baseAttributes: CustomerSDKStatsProperties & {\n \"retry.code\": RetryCode | number;\n telemetry_type: TelemetryType;\n } = {\n ...this.customerProperties,\n \"retry.code\": RetryCode.UNKNOWN,\n telemetry_type: TelemetryType.UNKNOWN,\n };\n\n // Iterate through the nested Map structure: telemetry_type -> retry.code -> reason -> count\n for (const [telemetryType, retryCodeMap] of counter.totalItemRetryCount.entries()) {\n for (const [retryCode, reasonMap] of retryCodeMap.entries()) {\n for (const [reason, count] of reasonMap.entries()) {\n const attributes = { ...baseAttributes };\n attributes.telemetry_type = telemetryType;\n attributes[\"retry.code\"] = retryCode;\n\n // Include retry.reason for all cases\n if (reason) {\n (attributes as any)[\"retry.reason\"] = reason;\n }\n\n // Only send metrics if count is greater than zero\n if (count > 0) {\n observableResult.observe(this.itemRetryCountGauge, count, {\n ...attributes,\n });\n }\n\n // Reset the count to 0\n reasonMap.set(reason, 0);\n }\n }\n }\n }\n\n // Public methods to track metrics\n /**\n * Tracks succcessful items\n * @param envelopes - Number of successful envelopes\n * @param telemetry_type - The type of telemetry being tracked\n */\n public countSuccessfulItems(envelopes: Envelope[]): void {\n const counter: CustomerSDKStats = this.customerSDKStatsCounter;\n let telemetry_type: TelemetryType;\n\n // Get the current count for this telemetry type, or 0 if it doesn't exist\n for (const envelope of envelopes) {\n telemetry_type = this.getTelemetryTypeFromEnvelope(envelope);\n const currentCount = counter.totalItemSuccessCount.get(telemetry_type) || 0;\n counter.totalItemSuccessCount.set(telemetry_type, currentCount + 1);\n }\n }\n\n /**\n * Tracks dropped items\n * @param envelopes - Array of envelopes dropped\n * @param dropCode - The drop code indicating the reason for drop\n * @param exceptionMessage - Optional exception message when dropCode is CLIENT_EXCEPTION\n * @param exceptionType - Optional explicit exception type override when dropCode is CLIENT_EXCEPTION\n */\n public countDroppedItems(\n envelopes: Envelope[],\n dropCode: DropCode | number,\n exceptionMessage?: string,\n exceptionType?: ExceptionType,\n ): void {\n const counter: CustomerSDKStats = this.customerSDKStatsCounter;\n let telemetry_type: TelemetryType;\n\n for (const envelope of envelopes) {\n telemetry_type = this.getTelemetryTypeFromEnvelope(envelope);\n\n let dropCodeMap = counter.totalItemDropCount.get(telemetry_type);\n if (!dropCodeMap) {\n dropCodeMap = new Map<DropCode | number, Map<string, Map<boolean | null, number>>>();\n counter.totalItemDropCount.set(telemetry_type, dropCodeMap);\n }\n\n // Get or create the reason map for this dropCode\n let reasonMap = dropCodeMap.get(dropCode);\n if (!reasonMap) {\n reasonMap = new Map<string, Map<boolean | null, number>>();\n dropCodeMap.set(dropCode, reasonMap);\n }\n\n // Generate a low-cardinality, informative reason description\n const reason = this.getDropReason(dropCode, exceptionMessage, exceptionType);\n\n // Get or create the success map for this reason\n let successMap = reasonMap.get(reason);\n if (!successMap) {\n successMap = new Map<boolean | null, number>();\n reasonMap.set(reason, successMap);\n }\n\n // For non-request/dependency telemetry or when success is not provided, use null as the success key\n const individualTelemetrySuccess = this.getTelemetrySuccessFromEnvelope(envelope);\n const successKey =\n (telemetry_type === TelemetryType.REQUEST || telemetry_type === TelemetryType.DEPENDENCY) &&\n individualTelemetrySuccess !== undefined\n ? individualTelemetrySuccess\n : null;\n\n // Update the count for this reason and success combination\n const currentCount = successMap.get(successKey) || 0;\n successMap.set(successKey, currentCount + 1);\n }\n }\n\n /**\n * Generates a low-cardinality, informative description for drop reasons\n * @param dropCode - The drop code (enum value or status code number)\n * @param exceptionMessage - Optional exception message for CLIENT_EXCEPTION\n * @param exceptionType - Optional explicit exception type override for CLIENT_EXCEPTION\n * @returns A descriptive reason string with low cardinality\n */\n private getDropReason(\n dropCode: DropCode | number,\n exceptionMessage?: string,\n exceptionType?: ExceptionType,\n ): string {\n if (dropCode === DropCode.CLIENT_EXCEPTION) {\n // If an explicit exception type is provided, use it\n if (exceptionType) {\n return exceptionType;\n }\n // For client exceptions, derive a well-known exception category from the exception message\n if (exceptionMessage) {\n return this.categorizeExceptionMessage(exceptionMessage);\n }\n return ExceptionType.CLIENT_EXCEPTION; // Default to \"Client exception\" if no message provided\n }\n\n // Handle status code drop codes (numeric values)\n if (typeof dropCode === \"number\") {\n return this.categorizeStatusCode(dropCode);\n }\n\n // Handle other enum drop codes\n switch (dropCode) {\n case DropCode.CLIENT_READONLY:\n return DropReason.CLIENT_READONLY;\n case DropCode.CLIENT_PERSISTENCE_CAPACITY:\n return DropReason.CLIENT_PERSISTENCE_CAPACITY;\n case DropCode.CLIENT_STORAGE_DISABLED:\n return DropReason.CLIENT_STORAGE_DISABLED;\n case DropCode.UNKNOWN:\n default:\n return DropReason.UNKNOWN;\n }\n }\n\n /**\n * Categorizes exception messages into well-known exception categories\n * @param exceptionMessage - The exception message to categorize\n * @returns A well-known exception category string\n */\n private categorizeExceptionMessage(exceptionMessage: string): ExceptionType {\n const message = exceptionMessage.toLowerCase();\n\n if (message.includes(\"timeout\") || message.includes(\"timed out\")) {\n return ExceptionType.TIMEOUT_EXCEPTION;\n }\n if (\n message.includes(\"network\") ||\n message.includes(\"connection\") ||\n message.includes(\"dns\") ||\n message.includes(\"socket\")\n ) {\n return ExceptionType.NETWORK_EXCEPTION;\n }\n if (\n message.includes(\"disk\") ||\n message.includes(\"storage\") ||\n message.includes(\"file\") ||\n message.includes(\"persist\")\n ) {\n return ExceptionType.STORAGE_EXCEPTION;\n }\n\n // Default to Client exception for any other cases\n return ExceptionType.CLIENT_EXCEPTION;\n }\n\n /**\n * Categorizes HTTP status codes into informative descriptions\n * @param statusCode - The HTTP status code\n * @returns A descriptive category string\n */\n private categorizeStatusCode(statusCode: number): string {\n if (statusCode >= 400 && statusCode < 500) {\n switch (statusCode) {\n case 400:\n return \"Bad request\";\n case 401:\n return \"Unauthorized\";\n case 403:\n return \"Forbidden\";\n case 404:\n return \"Not found\";\n case 408:\n return \"Request timeout\";\n case 413:\n return \"Payload too large\";\n case 429:\n return \"Too many requests\";\n default:\n return \"Client error 4xx\";\n }\n }\n\n if (statusCode >= 500 && statusCode < 600) {\n switch (statusCode) {\n case 500:\n return \"Internal server error\";\n case 502:\n return \"Bad gateway\";\n case 503:\n return \"Service unavailable\";\n case 504:\n return \"Gateway timeout\";\n default:\n return \"Server error 5xx\";\n }\n }\n\n return `status_${statusCode}`;\n }\n /**\n * Tracks retried envelopes\n * @param envelopes - Number of envelopes retried\n * @param retryCode - The retry code indicating the reason for retry\n * @param exceptionMessage - Optional exception message when retryCode is CLIENT_EXCEPTION\n * @param exceptionType - Optional explicit exception type override when retryCode is CLIENT_EXCEPTION\n */\n public countRetryItems(\n envelopes: Envelope[],\n retryCode: RetryCode | number,\n exceptionMessage?: string,\n exceptionType?: ExceptionType,\n ): void {\n const counter: CustomerSDKStats = this.customerSDKStatsCounter;\n let telemetry_type: TelemetryType;\n\n for (const envelope of envelopes) {\n telemetry_type = this.getTelemetryTypeFromEnvelope(envelope);\n // Get or create the retryCode map for this telemetry_type\n let retryCodeMap = counter.totalItemRetryCount.get(telemetry_type);\n if (!retryCodeMap) {\n retryCodeMap = new Map<RetryCode | number, Map<string, number>>();\n counter.totalItemRetryCount.set(telemetry_type, retryCodeMap);\n }\n\n // Get or create the reason map for this retryCode\n let reasonMap = retryCodeMap.get(retryCode);\n if (!reasonMap) {\n reasonMap = new Map<string, number>();\n retryCodeMap.set(retryCode, reasonMap);\n }\n\n // Generate a low-cardinality, informative reason description\n const reason = this.getRetryReason(retryCode, exceptionMessage, exceptionType);\n\n // Update the count for this reason\n const currentCount = reasonMap.get(reason) || 0;\n reasonMap.set(reason, currentCount + 1);\n }\n }\n\n /**\n * Generates a low-cardinality, informative description for retry reasons\n * @param retryCode - The retry code (enum value or status code number)\n * @param exceptionMessage - Optional exception message for CLIENT_EXCEPTION\n * @param exceptionType - Optional explicit exception type override for CLIENT_EXCEPTION\n * @returns A descriptive reason string with low cardinality\n */\n private getRetryReason(\n retryCode: RetryCode | number,\n exceptionMessage?: string,\n exceptionType?: ExceptionType,\n ): string {\n if (retryCode === RetryCode.CLIENT_EXCEPTION) {\n // If an explicit exception type is provided, use it\n if (exceptionType) {\n return exceptionType;\n }\n // For client exceptions, derive a low-cardinality reason from the exception message\n if (exceptionMessage) {\n return this.categorizeExceptionMessage(exceptionMessage);\n }\n return ExceptionType.CLIENT_EXCEPTION;\n }\n\n // Handle status code retry codes (numeric values)\n if (typeof retryCode === \"number\") {\n return this.categorizeStatusCode(retryCode);\n }\n\n // Handle other enum retry codes\n switch (retryCode) {\n case RetryCode.CLIENT_TIMEOUT:\n return RetryReason.CLIENT_TIMEOUT;\n case RetryCode.UNKNOWN:\n default:\n return RetryReason.UNKNOWN;\n }\n }\n\n /**\n * Check if a metric name corresponds to a performance counter\n * @param metricName - The name of the metric to check\n * @returns true if the metric name is a performance counter, false otherwise\n */\n private isPerformanceCounterMetric(metricName: string): boolean {\n return Object.values(BreezePerformanceCounterNames).includes(\n metricName as BreezePerformanceCounterNames,\n );\n }\n\n /**\n * Extract telemetry type from an envelope based on its baseType\n * @param envelope - The envelope to extract telemetry type from\n * @returns The corresponding telemetry type\n */\n public getTelemetryTypeFromEnvelope(envelope: Envelope): TelemetryType {\n if (envelope.data && envelope.data.baseType) {\n switch (envelope.data.baseType) {\n case \"MessageData\":\n return TelemetryType.TRACE;\n case \"AvailabilityData\":\n return TelemetryType.AVAILABILITY;\n case \"TelemetryEventData\":\n return TelemetryType.CUSTOM_EVENT;\n case \"TelemetryExceptionData\":\n return TelemetryType.EXCEPTION;\n case \"PageViewData\":\n return TelemetryType.PAGE_VIEW;\n case \"RemoteDependencyData\":\n return TelemetryType.DEPENDENCY;\n case \"RequestData\":\n return TelemetryType.REQUEST;\n case \"MetricData\": {\n const metricsData = envelope.data.baseData as MetricsData;\n if (metricsData && metricsData.metrics && metricsData.metrics.length > 0) {\n // Check if any of the metrics are performance counters\n const hasPerformanceCounter = metricsData.metrics.some((metric) =>\n this.isPerformanceCounterMetric(metric.name),\n );\n return hasPerformanceCounter\n ? TelemetryType.PERFORMANCE_COUNTER\n : TelemetryType.CUSTOM_METRIC;\n }\n return TelemetryType.CUSTOM_METRIC;\n }\n default:\n return TelemetryType.UNKNOWN;\n }\n }\n return TelemetryType.UNKNOWN;\n }\n\n /**\n * Extract telemetry success value from an envelope for REQUEST and DEPENDENCY telemetry types\n * @param envelope - The envelope to extract success value from\n * @returns The success value if available, undefined otherwise\n */\n public getTelemetrySuccessFromEnvelope(envelope: Envelope): boolean | undefined {\n if (!envelope.data || !envelope.data.baseData) {\n return undefined;\n }\n\n const baseType = envelope.data.baseType;\n if (baseType === \"RequestData\") {\n const requestData = envelope.data.baseData as RequestData;\n return requestData.success;\n } else if (baseType === \"RemoteDependencyData\") {\n const dependencyData = envelope.data.baseData as RemoteDependencyData;\n return dependencyData.success;\n }\n\n return undefined;\n }\n\n /**\n * Checks if the given error is a timeout-related error\n * @param error - The error to check\n * @returns true if the error is timeout-related, false otherwise\n */\n public isTimeoutError(error: { code?: string; message?: string }): boolean {\n // Check for various timeout error codes that indicate client timeouts\n const timeoutErrorCodes = [\n \"ETIMEDOUT\", // Connection timed out\n \"ESOCKETTIMEDOUT\", // Socket timeout\n \"ECONNRESET\", // Connection reset (often due to timeout)\n \"ENOTFOUND\", // DNS lookup failed/timeout\n ];\n\n if (error && error.code && timeoutErrorCodes.includes(error.code)) {\n return true;\n }\n\n // Also check if the error message contains timeout-related keywords\n if (error && error.message) {\n const timeoutKeywords = [\"timeout\", \"timed out\", \"connection reset\"];\n const errorMessage = error.message.toLowerCase();\n return timeoutKeywords.some((keyword) => errorMessage.includes(keyword));\n }\n\n return false;\n }\n}\n"]}
|