@azure/monitor-opentelemetry-exporter 1.0.0-beta.14 → 1.0.0-beta.15
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 +0 -1
- package/dist/index.js +430 -412
- package/dist-esm/src/config.js.map +1 -1
- package/dist-esm/src/export/base.js +16 -201
- package/dist-esm/src/export/base.js.map +1 -1
- package/dist-esm/src/export/log.js +5 -3
- package/dist-esm/src/export/log.js.map +1 -1
- package/dist-esm/src/export/metric.js +8 -6
- package/dist-esm/src/export/metric.js.map +1 -1
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +1 -1
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +1 -1
- package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/statsbeatExporter.js +5 -3
- package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist-esm/src/export/trace.js +7 -5
- package/dist-esm/src/export/trace.js.map +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
- package/dist-esm/src/index.js +0 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/platform/nodejs/baseSender.js +197 -0
- package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -0
- package/dist-esm/src/platform/nodejs/httpSender.js +9 -10
- package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
- package/dist-esm/src/sampling.js +4 -0
- package/dist-esm/src/sampling.js.map +1 -1
- package/dist-esm/src/types.js.map +1 -1
- package/dist-esm/src/utils/common.js +1 -1
- package/dist-esm/src/utils/common.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/logUtils.js +3 -0
- package/dist-esm/src/utils/logUtils.js.map +1 -1
- package/package.json +12 -12
- package/types/monitor-opentelemetry-exporter.d.ts +19 -93
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { ServiceApiVersion } from \"./Declarations/Constants\";\nimport { ApplicationInsightsClientOptionalParams } from \"./generated\";\n\n/**\n * Provides configuration options for AzureMonitorTraceExporter.\n */\nexport interface AzureMonitorExporterOptions extends ApplicationInsightsClientOptionalParams {\n /**\n * Azure Monitor Connection String, if not provided the exporter will try to use environment variable APPLICATIONINSIGHTS_CONNECTION_STRING\n * Ex: \"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://dc.services.visualstudio.com\"\n */\n connectionString?: string;\n /**\n * Azure service API version.\n */\n apiVersion?: ServiceApiVersion;\n /**\n *
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { ServiceApiVersion } from \"./Declarations/Constants\";\nimport { ApplicationInsightsClientOptionalParams } from \"./generated\";\n\n/**\n * Provides configuration options for AzureMonitorTraceExporter.\n */\nexport interface AzureMonitorExporterOptions extends ApplicationInsightsClientOptionalParams {\n /**\n * Azure Monitor Connection String, if not provided the exporter will try to use environment variable APPLICATIONINSIGHTS_CONNECTION_STRING\n * Ex: \"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://dc.services.visualstudio.com\"\n */\n connectionString?: string;\n /**\n * Azure service API version.\n */\n apiVersion?: ServiceApiVersion;\n /**\n * Token Credential\n */\n credential?: TokenCredential;\n /**\n * Directory to store retriable telemetry when it fails to export.\n */\n storageDirectory?: string;\n /**\n * Disable offline storage when telemetry cannot be exported.\n */\n disableOfflineStorage?: boolean;\n}\n"]}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { diag } from "@opentelemetry/api";
|
|
4
|
-
import { ExportResultCode } from "@opentelemetry/core";
|
|
5
4
|
import { ConnectionStringParser } from "../utils/connectionStringParser";
|
|
6
|
-
import { HttpSender, FileSystemPersist } from "../platform";
|
|
7
|
-
import { isRetriable } from "../utils/breezeUtils";
|
|
8
5
|
import { DEFAULT_BREEZE_ENDPOINT, ENV_CONNECTION_STRING, ENV_DISABLE_STATSBEAT, } from "../Declarations/Constants";
|
|
9
|
-
import { NetworkStatsbeatMetrics } from "./statsbeat/networkStatsbeatMetrics";
|
|
10
|
-
import { MAX_STATSBEAT_FAILURES } from "./statsbeat/types";
|
|
11
|
-
import { getInstance } from "./statsbeat/longIntervalStatsbeatMetrics";
|
|
12
|
-
const DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60000;
|
|
13
6
|
/**
|
|
14
7
|
* Azure Monitor OpenTelemetry Trace Exporter.
|
|
15
8
|
*/
|
|
@@ -23,212 +16,34 @@ export class AzureMonitorBaseExporter {
|
|
|
23
16
|
/**
|
|
24
17
|
* Instrumentation key to be used for exported envelopes
|
|
25
18
|
*/
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
this.instrumentationKey = "";
|
|
20
|
+
/**
|
|
21
|
+
* Ingestion Endpoint URL
|
|
22
|
+
*/
|
|
23
|
+
this.endpointUrl = "";
|
|
24
|
+
/**
|
|
25
|
+
*Flag to determine if exporter will generate Statsbeat data
|
|
26
|
+
*/
|
|
27
|
+
this.trackStatsbeat = false;
|
|
30
28
|
this._options = options;
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this._endpointUrl = DEFAULT_BREEZE_ENDPOINT;
|
|
29
|
+
this.instrumentationKey = "";
|
|
30
|
+
this.endpointUrl = DEFAULT_BREEZE_ENDPOINT;
|
|
34
31
|
const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];
|
|
35
32
|
this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;
|
|
36
33
|
if (connectionString) {
|
|
37
34
|
const parsedConnectionString = ConnectionStringParser.parse(connectionString);
|
|
38
|
-
this.
|
|
39
|
-
parsedConnectionString.instrumentationkey || this.
|
|
40
|
-
this.
|
|
35
|
+
this.instrumentationKey =
|
|
36
|
+
parsedConnectionString.instrumentationkey || this.instrumentationKey;
|
|
37
|
+
this.endpointUrl = ((_a = parsedConnectionString.ingestionendpoint) === null || _a === void 0 ? void 0 : _a.trim()) || this.endpointUrl;
|
|
41
38
|
}
|
|
42
39
|
// Instrumentation key is required
|
|
43
|
-
if (!this.
|
|
40
|
+
if (!this.instrumentationKey) {
|
|
44
41
|
const message = "No instrumentation key or connection string was provided to the Azure Monitor Exporter";
|
|
45
42
|
diag.error(message);
|
|
46
43
|
throw new Error(message);
|
|
47
44
|
}
|
|
48
|
-
this.
|
|
49
|
-
this._persister = new FileSystemPersist(this._instrumentationKey, this._options);
|
|
50
|
-
if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) {
|
|
51
|
-
// Initialize statsbeatMetrics
|
|
52
|
-
this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
|
|
53
|
-
instrumentationKey: this._instrumentationKey,
|
|
54
|
-
endpointUrl: this._endpointUrl,
|
|
55
|
-
});
|
|
56
|
-
this._longIntervalStatsbeatMetrics = getInstance({
|
|
57
|
-
instrumentationKey: this._instrumentationKey,
|
|
58
|
-
endpointUrl: this._endpointUrl,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
this._retryTimer = null;
|
|
45
|
+
this.trackStatsbeat = !this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];
|
|
62
46
|
diag.debug("AzureMonitorExporter was successfully setup");
|
|
63
47
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Persist envelopes to disk
|
|
66
|
-
*/
|
|
67
|
-
async _persist(envelopes) {
|
|
68
|
-
try {
|
|
69
|
-
const success = await this._persister.push(envelopes);
|
|
70
|
-
return success
|
|
71
|
-
? { code: ExportResultCode.SUCCESS }
|
|
72
|
-
: {
|
|
73
|
-
code: ExportResultCode.FAILED,
|
|
74
|
-
error: new Error("Failed to persist envelope in disk."),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch (ex) {
|
|
78
|
-
return { code: ExportResultCode.FAILED, error: ex };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Shutdown exporter
|
|
83
|
-
*/
|
|
84
|
-
async _shutdown() {
|
|
85
|
-
return this._sender.shutdown();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Export envelopes
|
|
89
|
-
*/
|
|
90
|
-
async _exportEnvelopes(envelopes) {
|
|
91
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
92
|
-
diag.info(`Exporting ${envelopes.length} envelope(s)`);
|
|
93
|
-
if (envelopes.length < 1) {
|
|
94
|
-
return { code: ExportResultCode.SUCCESS };
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const startTime = new Date().getTime();
|
|
98
|
-
const { result, statusCode } = await this._sender.send(envelopes);
|
|
99
|
-
const endTime = new Date().getTime();
|
|
100
|
-
const duration = endTime - startTime;
|
|
101
|
-
this._numConsecutiveRedirects = 0;
|
|
102
|
-
if (statusCode === 200) {
|
|
103
|
-
// Success -- @todo: start retry timer
|
|
104
|
-
if (!this._retryTimer) {
|
|
105
|
-
this._retryTimer = setTimeout(() => {
|
|
106
|
-
this._retryTimer = null;
|
|
107
|
-
this._sendFirstPersistedFile();
|
|
108
|
-
}, this._batchSendRetryIntervalMs);
|
|
109
|
-
this._retryTimer.unref();
|
|
110
|
-
}
|
|
111
|
-
// If we are not exportings statsbeat and statsbeat is not disabled -- count success
|
|
112
|
-
(_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countSuccess(duration);
|
|
113
|
-
return { code: ExportResultCode.SUCCESS };
|
|
114
|
-
}
|
|
115
|
-
else if (statusCode && isRetriable(statusCode)) {
|
|
116
|
-
// Failed -- persist failed data
|
|
117
|
-
if (statusCode === 429 || statusCode === 439) {
|
|
118
|
-
(_b = this._networkStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.countThrottle(statusCode);
|
|
119
|
-
}
|
|
120
|
-
if (result) {
|
|
121
|
-
diag.info(result);
|
|
122
|
-
const breezeResponse = JSON.parse(result);
|
|
123
|
-
const filteredEnvelopes = [];
|
|
124
|
-
if (breezeResponse.errors) {
|
|
125
|
-
breezeResponse.errors.forEach((error) => {
|
|
126
|
-
if (error.statusCode && isRetriable(error.statusCode)) {
|
|
127
|
-
filteredEnvelopes.push(envelopes[error.index]);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
if (filteredEnvelopes.length > 0) {
|
|
132
|
-
(_c = this._networkStatsbeatMetrics) === null || _c === void 0 ? void 0 : _c.countRetry(statusCode);
|
|
133
|
-
// calls resultCallback(ExportResult) based on result of persister.push
|
|
134
|
-
return await this._persist(filteredEnvelopes);
|
|
135
|
-
}
|
|
136
|
-
// Failed -- not retriable
|
|
137
|
-
(_d = this._networkStatsbeatMetrics) === null || _d === void 0 ? void 0 : _d.countFailure(duration, statusCode);
|
|
138
|
-
return {
|
|
139
|
-
code: ExportResultCode.FAILED,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
// calls resultCallback(ExportResult) based on result of persister.push
|
|
144
|
-
(_e = this._networkStatsbeatMetrics) === null || _e === void 0 ? void 0 : _e.countRetry(statusCode);
|
|
145
|
-
return await this._persist(envelopes);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
// Failed -- not retriable
|
|
150
|
-
if (this._networkStatsbeatMetrics) {
|
|
151
|
-
if (statusCode) {
|
|
152
|
-
this._networkStatsbeatMetrics.countFailure(duration, statusCode);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
this._incrementStatsbeatFailure();
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
code: ExportResultCode.FAILED,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
const restError = error;
|
|
165
|
-
if (restError.statusCode &&
|
|
166
|
-
(restError.statusCode === 307 || // Temporary redirect
|
|
167
|
-
restError.statusCode === 308)) {
|
|
168
|
-
// Permanent redirect
|
|
169
|
-
this._numConsecutiveRedirects++;
|
|
170
|
-
// To prevent circular redirects
|
|
171
|
-
if (this._numConsecutiveRedirects < 10) {
|
|
172
|
-
if (restError.response && restError.response.headers) {
|
|
173
|
-
const location = restError.response.headers.get("location");
|
|
174
|
-
if (location) {
|
|
175
|
-
// Update sender URL
|
|
176
|
-
this._sender.handlePermanentRedirect(location);
|
|
177
|
-
// Send to redirect endpoint as HTTPs library doesn't handle redirect automatically
|
|
178
|
-
return this._exportEnvelopes(envelopes);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
let redirectError = new Error("Circular redirect");
|
|
184
|
-
(_f = this._networkStatsbeatMetrics) === null || _f === void 0 ? void 0 : _f.countException(redirectError);
|
|
185
|
-
return { code: ExportResultCode.FAILED, error: redirectError };
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else if (restError.statusCode && isRetriable(restError.statusCode)) {
|
|
189
|
-
(_g = this._networkStatsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
|
|
190
|
-
return await this._persist(envelopes);
|
|
191
|
-
}
|
|
192
|
-
if (this._isNetworkError(restError)) {
|
|
193
|
-
if (restError.statusCode) {
|
|
194
|
-
(_h = this._networkStatsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
|
|
195
|
-
}
|
|
196
|
-
diag.error("Retrying due to transient client side error. Error message:", restError.message);
|
|
197
|
-
return await this._persist(envelopes);
|
|
198
|
-
}
|
|
199
|
-
(_j = this._networkStatsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
|
|
200
|
-
diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
|
|
201
|
-
return { code: ExportResultCode.FAILED, error: restError };
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
// Disable collection of statsbeat metrics after max failures
|
|
205
|
-
_incrementStatsbeatFailure() {
|
|
206
|
-
var _a, _b;
|
|
207
|
-
this._statsbeatFailureCount++;
|
|
208
|
-
if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {
|
|
209
|
-
this._isStatsbeatExporter = false;
|
|
210
|
-
(_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
|
|
211
|
-
(_b = this._longIntervalStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.shutdown();
|
|
212
|
-
this._networkStatsbeatMetrics = undefined;
|
|
213
|
-
this._statsbeatFailureCount = 0;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async _sendFirstPersistedFile() {
|
|
217
|
-
try {
|
|
218
|
-
const envelopes = (await this._persister.shift());
|
|
219
|
-
if (envelopes) {
|
|
220
|
-
await this._sender.send(envelopes);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
catch (err) {
|
|
224
|
-
diag.warn(`Failed to fetch persisted file`, err);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
_isNetworkError(error) {
|
|
228
|
-
if (error && error.code && error.code === "REQUEST_SEND_ERROR") {
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
48
|
}
|
|
234
49
|
//# sourceMappingURL=base.js.map
|
|
@@ -1 +1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CAAC;YACF,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;SAC5D;IACH,CAAC;IAED,6DAA6D;IACrD,0BAA0B;;QAChC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,EAAE;YACxD,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;YAClC,MAAA,IAAI,CAAC,wBAAwB,0CAAE,QAAQ,EAAE,CAAC;YAC1C,MAAA,IAAI,CAAC,6BAA6B,0CAAE,QAAQ,EAAE,CAAC;YAC/C,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACnC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAsB,CAAC;YACvE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACpC;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,eAAe,CAAC,KAAgB;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { HttpSender, FileSystemPersist } from \"../platform\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { PersistentStorage, Sender } from \"../types\";\nimport { isRetriable, BreezeResponse } from \"../utils/breezeUtils\";\nimport {\n DEFAULT_BREEZE_ENDPOINT,\n ENV_CONNECTION_STRING,\n ENV_DISABLE_STATSBEAT,\n} from \"../Declarations/Constants\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { NetworkStatsbeatMetrics } from \"./statsbeat/networkStatsbeatMetrics\";\nimport { MAX_STATSBEAT_FAILURES } from \"./statsbeat/types\";\nimport { getInstance } from \"./statsbeat/longIntervalStatsbeatMetrics\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport abstract class AzureMonitorBaseExporter {\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected _instrumentationKey: string = \"\";\n private _endpointUrl: string = \"\";\n private readonly _persister: PersistentStorage;\n private readonly _sender: Sender;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n private _networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private _longIntervalStatsbeatMetrics;\n private _isStatsbeatExporter: boolean;\n private _statsbeatFailureCount: number = 0;\n private _batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n /**\n * Exporter internal configuration\n */\n private readonly _options: AzureMonitorExporterOptions;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureMonitorExporterOptions - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {\n this._options = options;\n this._numConsecutiveRedirects = 0;\n this._instrumentationKey = \"\";\n this._endpointUrl = DEFAULT_BREEZE_ENDPOINT;\n const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];\n this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this._instrumentationKey =\n parsedConnectionString.instrumentationkey || this._instrumentationKey;\n this._endpointUrl = parsedConnectionString.ingestionendpoint?.trim() || this._endpointUrl;\n }\n\n // Instrumentation key is required\n if (!this._instrumentationKey) {\n const message =\n \"No instrumentation key or connection string was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n this._sender = new HttpSender(this._endpointUrl, this._options);\n this._persister = new FileSystemPersist(this._instrumentationKey, this._options);\n\n if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) {\n // Initialize statsbeatMetrics\n this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: this._instrumentationKey,\n endpointUrl: this._endpointUrl,\n });\n this._longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: this._instrumentationKey,\n endpointUrl: this._endpointUrl,\n });\n }\n this._retryTimer = null;\n diag.debug(\"AzureMonitorExporter was successfully setup\");\n }\n\n /**\n * Persist envelopes to disk\n */\n private async _persist(envelopes: unknown[]): Promise<ExportResult> {\n try {\n const success = await this._persister.push(envelopes);\n return success\n ? { code: ExportResultCode.SUCCESS }\n : {\n code: ExportResultCode.FAILED,\n error: new Error(\"Failed to persist envelope in disk.\"),\n };\n } catch (ex: any) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n /**\n * Shutdown exporter\n */\n protected async _shutdown(): Promise<void> {\n return this._sender.shutdown();\n }\n\n /**\n * Export envelopes\n */\n protected async _exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n if (envelopes.length < 1) {\n return { code: ExportResultCode.SUCCESS };\n }\n\n try {\n const startTime = new Date().getTime();\n const { result, statusCode } = await this._sender.send(envelopes);\n const endTime = new Date().getTime();\n const duration = endTime - startTime;\n this._numConsecutiveRedirects = 0;\n\n if (statusCode === 200) {\n // Success -- @todo: start retry timer\n if (!this._retryTimer) {\n this._retryTimer = setTimeout(() => {\n this._retryTimer = null;\n this._sendFirstPersistedFile();\n }, this._batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n // If we are not exportings statsbeat and statsbeat is not disabled -- count success\n this._networkStatsbeatMetrics?.countSuccess(duration);\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (statusCode === 429 || statusCode === 439) {\n this._networkStatsbeatMetrics?.countThrottle(statusCode);\n }\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n if (breezeResponse.errors) {\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n }\n if (filteredEnvelopes.length > 0) {\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n this._networkStatsbeatMetrics?.countFailure(duration, statusCode);\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n if (this._networkStatsbeatMetrics) {\n if (statusCode) {\n this._networkStatsbeatMetrics.countFailure(duration, statusCode);\n }\n } else {\n this._incrementStatsbeatFailure();\n }\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error: any) {\n const restError = error as RestError;\n if (\n restError.statusCode &&\n (restError.statusCode === 307 || // Temporary redirect\n restError.statusCode === 308)\n ) {\n // Permanent redirect\n this._numConsecutiveRedirects++;\n // To prevent circular redirects\n if (this._numConsecutiveRedirects < 10) {\n if (restError.response && restError.response.headers) {\n const location = restError.response.headers.get(\"location\");\n if (location) {\n // Update sender URL\n this._sender.handlePermanentRedirect(location);\n // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically\n return this._exportEnvelopes(envelopes);\n }\n }\n } else {\n let redirectError = new Error(\"Circular redirect\");\n this._networkStatsbeatMetrics?.countException(redirectError);\n return { code: ExportResultCode.FAILED, error: redirectError };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\n if (restError.statusCode) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n }\n diag.error(\n \"Retrying due to transient client side error. Error message:\",\n restError.message\n );\n return await this._persist(envelopes);\n }\n this._networkStatsbeatMetrics?.countException(restError);\n diag.error(\n \"Envelopes could not be exported and are not retriable. Error message:\",\n restError.message\n );\n return { code: ExportResultCode.FAILED, error: restError };\n }\n }\n\n // Disable collection of statsbeat metrics after max failures\n private _incrementStatsbeatFailure() {\n this._statsbeatFailureCount++;\n if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\n this._isStatsbeatExporter = false;\n this._networkStatsbeatMetrics?.shutdown();\n this._longIntervalStatsbeatMetrics?.shutdown();\n this._networkStatsbeatMetrics = undefined;\n this._statsbeatFailureCount = 0;\n }\n }\n\n private async _sendFirstPersistedFile(): Promise<void> {\n try {\n const envelopes = (await this._persister.shift()) as Envelope[] | null;\n if (envelopes) {\n await this._sender.send(envelopes);\n }\n } catch (err: any) {\n diag.warn(`Failed to fetch persisted file`, err);\n }\n }\n\n private _isNetworkError(error: RestError): boolean {\n if (error && error.code && error.code === \"REQUEST_SEND_ERROR\") {\n return true;\n }\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/export/base.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,2BA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AAK,CAAC,6CAA6C,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport {\n DEFAULT_BREEZE_ENDPOINT,\n ENV_CONNECTION_STRING,\n ENV_DISABLE_STATSBEAT,\n} from \"../Declarations/Constants\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport abstract class AzureMonitorBaseExporter {\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected instrumentationKey: string = \"\";\n /**\n * Ingestion Endpoint URL\n */\n protected endpointUrl: string = \"\";\n /**\n *Flag to determine if exporter will generate Statsbeat data\n */\n protected trackStatsbeat: boolean = false;\n private _isStatsbeatExporter: boolean;\n\n /**\n * Exporter internal configuration\n */\n private readonly _options: AzureMonitorExporterOptions;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureMonitorExporterOptions - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {\n this._options = options;\n this.instrumentationKey = \"\";\n this.endpointUrl = DEFAULT_BREEZE_ENDPOINT;\n const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];\n this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this.instrumentationKey =\n parsedConnectionString.instrumentationkey || this.instrumentationKey;\n this.endpointUrl = parsedConnectionString.ingestionendpoint?.trim() || this.endpointUrl;\n }\n\n // Instrumentation key is required\n if (!this.instrumentationKey) {\n const message =\n \"No instrumentation key or connection string was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n this.trackStatsbeat = !this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];\n\n diag.debug(\"AzureMonitorExporter was successfully setup\");\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { diag } from "@opentelemetry/api";
|
|
|
4
4
|
import { ExportResultCode } from "@opentelemetry/core";
|
|
5
5
|
import { AzureMonitorBaseExporter } from "./base";
|
|
6
6
|
import { logToEnvelope } from "../utils/logUtils";
|
|
7
|
+
import { HttpSender } from "../platform";
|
|
7
8
|
/**
|
|
8
9
|
* Azure Monitor OpenTelemetry Log Exporter.
|
|
9
10
|
*/
|
|
@@ -18,6 +19,7 @@ export class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
18
19
|
* Flag to determine if Exporter is shutdown.
|
|
19
20
|
*/
|
|
20
21
|
this._isShutdown = false;
|
|
22
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
21
23
|
diag.debug("AzureMonitorLogExporter was successfully setup");
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
@@ -34,12 +36,12 @@ export class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
34
36
|
diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);
|
|
35
37
|
let envelopes = [];
|
|
36
38
|
logs.forEach((log) => {
|
|
37
|
-
let envelope = logToEnvelope(log, this.
|
|
39
|
+
let envelope = logToEnvelope(log, this.instrumentationKey);
|
|
38
40
|
if (envelope) {
|
|
39
41
|
envelopes.push(envelope);
|
|
40
42
|
}
|
|
41
43
|
});
|
|
42
|
-
resultCallback(await this.
|
|
44
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Shutdown AzureMonitorLogExporter.
|
|
@@ -47,7 +49,7 @@ export class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
47
49
|
async shutdown() {
|
|
48
50
|
this._isShutdown = true;
|
|
49
51
|
diag.info("AzureMonitorLogExporter shutting down");
|
|
50
|
-
return this.
|
|
52
|
+
return this._sender.shutdown();
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
//# sourceMappingURL=log.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/export/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/export/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,wBAAwB;IAOnE;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAZjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAC3B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,cAAc,EACnB,OAAO,CACR,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CAAC,IAAyB,EAAE,cAA8C;QAC3F,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;YACzD,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;SACR;QACD,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,MAAM,sCAAsC,CAAC,CAAC;QAE1E,IAAI,SAAS,GAAe,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,QAAQ,GAAG,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC3D,IAAI,QAAQ,EAAE;gBACZ,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { logToEnvelope } from \"../utils/logUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\n\nimport type { ReadableLogRecord, LogRecordExporter } from \"@opentelemetry/sdk-logs\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Log Exporter.\n */\nexport class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements LogRecordExporter {\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private readonly _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorLogExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender(\n this.endpointUrl,\n this.instrumentationKey,\n this.trackStatsbeat,\n options\n );\n diag.debug(\"AzureMonitorLogExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry logs.\n * @param logs - Logs to export.\n * @param resultCallback - Result callback.\n */\n public async export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void) {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);\n\n let envelopes: Envelope[] = [];\n logs.forEach((log) => {\n let envelope = logToEnvelope(log, this.instrumentationKey);\n if (envelope) {\n envelopes.push(envelope);\n }\n });\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n }\n\n /**\n * Shutdown AzureMonitorLogExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorLogExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { AggregationTemporality, InstrumentType, } from "@opentelemetry/sdk-metr
|
|
|
5
5
|
import { ExportResultCode, suppressTracing } from "@opentelemetry/core";
|
|
6
6
|
import { AzureMonitorBaseExporter } from "./base";
|
|
7
7
|
import { resourceMetricsToEnvelope } from "../utils/metricUtils";
|
|
8
|
+
import { HttpSender } from "../platform";
|
|
8
9
|
/**
|
|
9
10
|
* Azure Monitor OpenTelemetry Metric Exporter.
|
|
10
11
|
*/
|
|
@@ -19,6 +20,7 @@ export class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
19
20
|
* Flag to determine if Exporter is shutdown.
|
|
20
21
|
*/
|
|
21
22
|
this._isShutdown = false;
|
|
23
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
22
24
|
diag.debug("AzureMonitorMetricExporter was successfully setup");
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
@@ -33,10 +35,10 @@ export class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
35
37
|
diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);
|
|
36
|
-
let envelopes = resourceMetricsToEnvelope(metrics, this.
|
|
38
|
+
let envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey);
|
|
37
39
|
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
38
40
|
context.with(suppressTracing(context.active()), async () => {
|
|
39
|
-
resultCallback(await this.
|
|
41
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
@@ -45,14 +47,14 @@ export class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
45
47
|
async shutdown() {
|
|
46
48
|
this._isShutdown = true;
|
|
47
49
|
diag.info("AzureMonitorMetricExporter shutting down");
|
|
48
|
-
return this.
|
|
50
|
+
return this._sender.shutdown();
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Select aggregation temporality
|
|
52
54
|
*/
|
|
53
|
-
selectAggregationTemporality(
|
|
54
|
-
if (
|
|
55
|
-
|
|
55
|
+
selectAggregationTemporality(instrumentType) {
|
|
56
|
+
if (instrumentType == InstrumentType.UP_DOWN_COUNTER ||
|
|
57
|
+
instrumentType == InstrumentType.OBSERVABLE_UP_DOWN_COUNTER) {
|
|
56
58
|
return AggregationTemporality.CUMULATIVE;
|
|
57
59
|
}
|
|
58
60
|
return AggregationTemporality.DELTA;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,cAAc,GAGf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,cAAc,GAGf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,0BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAZjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAC3B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,cAAc,EACnB,OAAO,CACR,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAA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from \"@opentelemetry/api\";\nimport {\n AggregationTemporality,\n InstrumentType,\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { resourceMetricsToEnvelope } from \"../utils/metricUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Exporter.\n */\nexport class AzureMonitorMetricExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorMetricExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender(\n this.endpointUrl,\n this.instrumentationKey,\n this.trackStatsbeat,\n options\n );\n diag.debug(\"AzureMonitorMetricExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry resource metrics.\n * @param metrics - Resource metrics to export.\n * @param resultCallback - Result callback.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);\n\n let envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);\n // Supress tracing until OpenTelemetry Metrics SDK support it\n context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorMetricExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorMetricExporter shutting down\");\n return this._sender.shutdown();\n }\n\n /**\n * Select aggregation temporality\n */\n public selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {\n if (\n instrumentType == InstrumentType.UP_DOWN_COUNTER ||\n instrumentType == InstrumentType.OBSERVABLE_UP_DOWN_COUNTER\n ) {\n return AggregationTemporality.CUMULATIVE;\n }\n return AggregationTemporality.DELTA;\n }\n\n /**\n * Force flush\n */\n public async forceFlush() {\n return Promise.resolve();\n }\n}\n"]}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import { diag, } from "@opentelemetry/api";
|
|
4
4
|
import { ExportResultCode } from "@opentelemetry/core";
|
|
5
5
|
import { MeterProvider, PeriodicExportingMetricReader, } from "@opentelemetry/sdk-metrics";
|
|
6
|
-
import { AzureMonitorStatsbeatExporter } from "../../index";
|
|
7
6
|
import * as ai from "../../utils/constants/applicationinsights";
|
|
8
7
|
import { StatsbeatMetrics } from "./statsbeatMetrics";
|
|
9
8
|
import { StatsbeatCounter, STATSBEAT_LANGUAGE, StatsbeatFeatureType, } from "./types";
|
|
9
|
+
import { AzureMonitorStatsbeatExporter } from "./statsbeatExporter";
|
|
10
10
|
let instance = null;
|
|
11
11
|
/**
|
|
12
12
|
* Long Interval Statsbeat Metrics
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAA+B,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gB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QAAQ,EACtB,IAAI,EAAE,oBAAoB,CAAC,OAAO,GACnC,CAAC;YACF,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,oBAAO,UAAU,EAAG,CAAC;SAC7E;IACH,CAAC;IAEO,eAAe,CAAC,gBAAkC;QACxD,IAAI,UAAU,mCAAQ,IAAI,CAAC,iBAAiB,GAAK,IAAI,CAAC,iBAAiB,CAAE,CAAC;QAC1E,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,aAAa;QAClB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAEM,QAAQ;QACb,IAAI,CAAC,mCAAmC,CAAC,QAAQ,EAAE,CAAC;IACtD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions, AzureMonitorStatsbeatExporter } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private _AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private _statsCollectionLongInterval: number = 86400000; // 1 day\n private _isInitialized: boolean = false;\n\n // Custom dimensions\n private _cikey: string;\n private _runtimeVersion: string;\n private _language: string;\n private _version: string;\n private _attach: string = \"sdk\";\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 constructor(options: StatsbeatOptions) {\n super();\n this._connectionString = super._getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this._connectionString,\n };\n\n if (this._AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this._feature = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this._instrumentation = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`\n );\n }\n }\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\n this._commonProperties = {\n os: super._os,\n rp: super._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: super._resourceIdentifier,\n };\n\n this._isInitialized = true;\n this._initialize();\n }\n\n private async _initialize() {\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._featureCallback.bind(this),\n [this._featureStatsbeatGauge]\n );\n\n // Export Feature/Attach Statsbeat once upon app initialization\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 } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private _featureCallback(observableResult: BatchObservableResult) {\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 _attachCallback(observableResult: ObservableResult) {\n let attributes = { ...this._commonProperties, ...this._attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public isInitialized() {\n return this._isInitialized;\n }\n\n public shutdown() {\n 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;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAGlB,oBAAoB,GAErB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,IAAI,QAAQ,GAAwC,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,4BAA6B,SAAQ,gBAAgB;IA8BzD,YAAY,OAAyB;QACnC,KAAK,EAAE,CAAC;QA9BF,sCAAiC,GAAG,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC;QACjF,iCAA4B,GAAW,QAAQ,CAAC,CAAC,QAAQ;QACzD,mBAAc,GAAY,KAAK,CAAC;QAO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cAAc,CAAC;IAC7B,CAAC;IAEM,QAAQ;QACb,IAAI,CAAC,mCAAmC,CAAC,QAAQ,EAAE,CAAC;IACtD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private _AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private _statsCollectionLongInterval: number = 86400000; // 1 day\n private _isInitialized: boolean = false;\n\n // Custom dimensions\n private _cikey: string;\n private _runtimeVersion: string;\n private _language: string;\n private _version: string;\n private _attach: string = \"sdk\";\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 constructor(options: StatsbeatOptions) {\n super();\n this._connectionString = super._getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this._connectionString,\n };\n\n if (this._AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this._feature = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this._instrumentation = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`\n );\n }\n }\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\n this._commonProperties = {\n os: super._os,\n rp: super._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: super._resourceIdentifier,\n };\n\n this._isInitialized = true;\n this._initialize();\n }\n\n private async _initialize() {\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._featureCallback.bind(this),\n [this._featureStatsbeatGauge]\n );\n\n // Export Feature/Attach Statsbeat once upon app initialization\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 } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private _featureCallback(observableResult: BatchObservableResult) {\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 _attachCallback(observableResult: ObservableResult) {\n let attributes = { ...this._commonProperties, ...this._attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public isInitialized() {\n return this._isInitialized;\n }\n\n public shutdown() {\n 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"]}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { diag, } from "@opentelemetry/api";
|
|
4
4
|
import { MeterProvider, PeriodicExportingMetricReader, } from "@opentelemetry/sdk-metrics";
|
|
5
|
-
import { AzureMonitorStatsbeatExporter } from "../../index";
|
|
6
5
|
import * as ai from "../../utils/constants/applicationinsights";
|
|
7
6
|
import { StatsbeatMetrics } from "./statsbeatMetrics";
|
|
8
7
|
import { StatsbeatCounter, STATSBEAT_LANGUAGE, NetworkStatsbeat, } from "./types";
|
|
8
|
+
import { AzureMonitorStatsbeatExporter } from "./statsbeatExporter";
|
|
9
9
|
export class NetworkStatsbeatMetrics extends StatsbeatMetrics {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
super();
|