@azure/monitor-opentelemetry-exporter 1.0.0-beta.7 → 1.0.0-beta.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,GAExB,MAAM,0BAA0B,CAAC;AAElC,MAAM,oCAAoC,GAAG,KAAM,CAAC;AACpD,MAAM,+CAA+C,GAAG,EAAE,CAAC;AAkC3D;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAgC;IAClE,kBAAkB,EAAE,EAAE;IACtB,WAAW,EAAE,uBAAuB;IACpC,wBAAwB,EAAE,oCAAoC;IAC9D,mCAAmC,EAAE,+CAA+C;IACpF,UAAU,EAAE,0BAA0B;CACvC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { TokenCredential } from \"@azure/core-http\";\nimport {\n DEFAULT_BREEZE_API_VERSION,\n DEFAULT_BREEZE_ENDPOINT,\n ServiceApiVersion,\n} from \"./Declarations/Constants\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\nconst DEFAULT_MAX_CONSECUTIVE_FAILURES_BEFORE_WARNING = 10;\n\n/**\n * Provides configuration options for AzureMonitorTraceExporter.\n */\nexport interface AzureExporterConfig {\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 * Azure Active Directory Credential\n */\n aadTokenCredential?: TokenCredential;\n}\n\n/**\n * Internal Azure exporter configuration\n * @internal\n */\nexport interface AzureExporterInternalConfig {\n instrumentationKey: string;\n batchSendRetryIntervalMs: number;\n maxConsecutiveFailuresBeforeWarning: number;\n endpointUrl: string;\n apiVersion: ServiceApiVersion;\n aadTokenCredential?: TokenCredential;\n}\n\n/**\n * Internal default Azure exporter configuration\n * @internal\n */\nexport const DEFAULT_EXPORTER_CONFIG: AzureExporterInternalConfig = {\n instrumentationKey: \"\",\n endpointUrl: DEFAULT_BREEZE_ENDPOINT,\n batchSendRetryIntervalMs: DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS,\n maxConsecutiveFailuresBeforeWarning: DEFAULT_MAX_CONSECUTIVE_FAILURES_BEFORE_WARNING,\n apiVersion: DEFAULT_BREEZE_API_VERSION,\n};\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,GAExB,MAAM,0BAA0B,CAAC;AAElC,MAAM,oCAAoC,GAAG,KAAM,CAAC;AACpD,MAAM,+CAA+C,GAAG,EAAE,CAAC;AAkC3D;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAgC;IAClE,kBAAkB,EAAE,EAAE;IACtB,WAAW,EAAE,uBAAuB;IACpC,wBAAwB,EAAE,oCAAoC;IAC9D,mCAAmC,EAAE,+CAA+C;IACpF,UAAU,EAAE,0BAA0B;CACvC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { TokenCredential } from \"@azure/core-auth\";\nimport {\n DEFAULT_BREEZE_API_VERSION,\n DEFAULT_BREEZE_ENDPOINT,\n ServiceApiVersion,\n} from \"./Declarations/Constants\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\nconst DEFAULT_MAX_CONSECUTIVE_FAILURES_BEFORE_WARNING = 10;\n\n/**\n * Provides configuration options for AzureMonitorTraceExporter.\n */\nexport interface AzureExporterConfig {\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 * Azure Active Directory Credential\n */\n aadTokenCredential?: TokenCredential;\n}\n\n/**\n * Internal Azure exporter configuration\n * @internal\n */\nexport interface AzureExporterInternalConfig {\n instrumentationKey: string;\n batchSendRetryIntervalMs: number;\n maxConsecutiveFailuresBeforeWarning: number;\n endpointUrl: string;\n apiVersion: ServiceApiVersion;\n aadTokenCredential?: TokenCredential;\n}\n\n/**\n * Internal default Azure exporter configuration\n * @internal\n */\nexport const DEFAULT_EXPORTER_CONFIG: AzureExporterInternalConfig = {\n instrumentationKey: \"\",\n endpointUrl: DEFAULT_BREEZE_ENDPOINT,\n batchSendRetryIntervalMs: DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS,\n maxConsecutiveFailuresBeforeWarning: DEFAULT_MAX_CONSECUTIVE_FAILURES_BEFORE_WARNING,\n apiVersion: DEFAULT_BREEZE_API_VERSION,\n};\n"]}
@@ -0,0 +1,172 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { diag } from "@opentelemetry/api";
4
+ import { ExportResultCode } from "@opentelemetry/core";
5
+ import { ConnectionStringParser } from "../utils/connectionStringParser";
6
+ import { HttpSender, FileSystemPersist } from "../platform";
7
+ import { DEFAULT_EXPORTER_CONFIG, } from "../config";
8
+ import { isRetriable } from "../utils/breezeUtils";
9
+ import { ENV_CONNECTION_STRING } from "../Declarations/Constants";
10
+ /**
11
+ * Azure Monitor OpenTelemetry Trace Exporter.
12
+ */
13
+ export class AzureMonitorBaseExporter {
14
+ /**
15
+ * Initializes a new instance of the AzureMonitorBaseExporter class.
16
+ * @param AzureExporterConfig - Exporter configuration.
17
+ */
18
+ constructor(options = {}) {
19
+ var _a, _b, _c, _d;
20
+ this._numConsecutiveRedirects = 0;
21
+ const connectionString = options.connectionString || process.env[ENV_CONNECTION_STRING];
22
+ this._options = Object.assign({}, DEFAULT_EXPORTER_CONFIG);
23
+ this._options.apiVersion = (_a = options.apiVersion) !== null && _a !== void 0 ? _a : this._options.apiVersion;
24
+ this._options.aadTokenCredential = options.aadTokenCredential;
25
+ if (connectionString) {
26
+ const parsedConnectionString = ConnectionStringParser.parse(connectionString);
27
+ this._options.instrumentationKey =
28
+ (_b = parsedConnectionString.instrumentationkey) !== null && _b !== void 0 ? _b : this._options.instrumentationKey;
29
+ this._options.endpointUrl =
30
+ (_d = (_c = parsedConnectionString.ingestionendpoint) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : this._options.endpointUrl;
31
+ }
32
+ // Instrumentation key is required
33
+ if (!this._options.instrumentationKey) {
34
+ const message = "No instrumentation key or connection string was provided to the Azure Monitor Exporter";
35
+ diag.error(message);
36
+ throw new Error(message);
37
+ }
38
+ this._instrumentationKey = this._options.instrumentationKey;
39
+ this._sender = new HttpSender(this._options);
40
+ this._persister = new FileSystemPersist(this._options);
41
+ this._retryTimer = null;
42
+ diag.debug("AzureMonitorTraceExporter was successfully setup");
43
+ }
44
+ /**
45
+ * Persist envelopes to disk
46
+ */
47
+ async _persist(envelopes) {
48
+ try {
49
+ const success = await this._persister.push(envelopes);
50
+ return success
51
+ ? { code: ExportResultCode.SUCCESS }
52
+ : {
53
+ code: ExportResultCode.FAILED,
54
+ error: new Error("Failed to persist envelope in disk."),
55
+ };
56
+ }
57
+ catch (ex) {
58
+ return { code: ExportResultCode.FAILED, error: ex };
59
+ }
60
+ }
61
+ /**
62
+ * Shutdown exporter
63
+ */
64
+ async _shutdown() {
65
+ return this._sender.shutdown();
66
+ }
67
+ /**
68
+ * Export envelopes
69
+ */
70
+ async _exportEnvelopes(envelopes) {
71
+ diag.info(`Exporting ${envelopes.length} envelope(s)`);
72
+ try {
73
+ const { result, statusCode } = await this._sender.send(envelopes);
74
+ this._numConsecutiveRedirects = 0;
75
+ if (statusCode === 200) {
76
+ // Success -- @todo: start retry timer
77
+ if (!this._retryTimer) {
78
+ this._retryTimer = setTimeout(() => {
79
+ this._retryTimer = null;
80
+ this._sendFirstPersistedFile();
81
+ }, this._options.batchSendRetryIntervalMs);
82
+ this._retryTimer.unref();
83
+ }
84
+ return { code: ExportResultCode.SUCCESS };
85
+ }
86
+ else if (statusCode && isRetriable(statusCode)) {
87
+ // Failed -- persist failed data
88
+ if (result) {
89
+ diag.info(result);
90
+ const breezeResponse = JSON.parse(result);
91
+ const filteredEnvelopes = [];
92
+ if (breezeResponse.errors) {
93
+ breezeResponse.errors.forEach((error) => {
94
+ if (error.statusCode && isRetriable(error.statusCode)) {
95
+ filteredEnvelopes.push(envelopes[error.index]);
96
+ }
97
+ });
98
+ }
99
+ if (filteredEnvelopes.length > 0) {
100
+ // calls resultCallback(ExportResult) based on result of persister.push
101
+ return await this._persist(filteredEnvelopes);
102
+ }
103
+ // Failed -- not retriable
104
+ return {
105
+ code: ExportResultCode.FAILED,
106
+ };
107
+ }
108
+ else {
109
+ // calls resultCallback(ExportResult) based on result of persister.push
110
+ return await this._persist(envelopes);
111
+ }
112
+ }
113
+ else {
114
+ // Failed -- not retriable
115
+ return {
116
+ code: ExportResultCode.FAILED,
117
+ };
118
+ }
119
+ }
120
+ catch (error) {
121
+ const restError = error;
122
+ if (restError.statusCode &&
123
+ (restError.statusCode === 307 || // Temporary redirect
124
+ restError.statusCode === 308)) {
125
+ // Permanent redirect
126
+ this._numConsecutiveRedirects++;
127
+ // To prevent circular redirects
128
+ if (this._numConsecutiveRedirects < 10) {
129
+ if (restError.response && restError.response.headers) {
130
+ const location = restError.response.headers.get("location");
131
+ if (location) {
132
+ // Update sender URL
133
+ this._sender.handlePermanentRedirect(location);
134
+ // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically
135
+ return this._exportEnvelopes(envelopes);
136
+ }
137
+ }
138
+ }
139
+ else {
140
+ return { code: ExportResultCode.FAILED, error: new Error("Circular redirect") };
141
+ }
142
+ }
143
+ else if (restError.statusCode && isRetriable(restError.statusCode)) {
144
+ return await this._persist(envelopes);
145
+ }
146
+ if (this._isNetworkError(restError)) {
147
+ diag.error("Retrying due to transient client side error. Error message:", restError.message);
148
+ return await this._persist(envelopes);
149
+ }
150
+ diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
151
+ return { code: ExportResultCode.FAILED, error: restError };
152
+ }
153
+ }
154
+ async _sendFirstPersistedFile() {
155
+ try {
156
+ const envelopes = (await this._persister.shift());
157
+ if (envelopes) {
158
+ await this._sender.send(envelopes);
159
+ }
160
+ }
161
+ catch (err) {
162
+ diag.warn(`Failed to fetch persisted file`, err);
163
+ }
164
+ }
165
+ _isNetworkError(error) {
166
+ if (error && error.code && error.code === "REQUEST_SEND_ERROR") {
167
+ return true;
168
+ }
169
+ return false;
170
+ }
171
+ }
172
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
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,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,uBAAuB,GAGxB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE;;GAEG;AACH,MAAM,OAAgB,wBAAwB;IAc5C;;;OAGG;IACH,YAAY,UAA+B,EAAE;;QAC3C,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;QAClC,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,O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,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 {\n DEFAULT_EXPORTER_CONFIG,\n AzureExporterConfig,\n AzureExporterInternalConfig,\n} from \"../config\";\nimport { PersistentStorage, Sender } from \"../types\";\nimport { isRetriable, BreezeResponse } from \"../utils/breezeUtils\";\nimport { ENV_CONNECTION_STRING } from \"../Declarations/Constants\";\nimport { TelemetryItem as Envelope } from \"../generated\";\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 readonly _instrumentationKey: string;\n private readonly _persister: PersistentStorage;\n private readonly _sender: Sender;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n /**\n * Exporter internal configuration\n */\n private readonly _options: AzureExporterInternalConfig;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureExporterConfig = {}) {\n this._numConsecutiveRedirects = 0;\n const connectionString = options.connectionString || process.env[ENV_CONNECTION_STRING];\n this._options = {\n ...DEFAULT_EXPORTER_CONFIG,\n };\n this._options.apiVersion = options.apiVersion ?? this._options.apiVersion;\n this._options.aadTokenCredential = options.aadTokenCredential;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this._options.instrumentationKey =\n parsedConnectionString.instrumentationkey ?? this._options.instrumentationKey;\n this._options.endpointUrl =\n parsedConnectionString.ingestionendpoint?.trim() ?? this._options.endpointUrl;\n }\n // Instrumentation key is required\n if (!this._options.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\n this._instrumentationKey = this._options.instrumentationKey;\n this._sender = new HttpSender(this._options);\n this._persister = new FileSystemPersist(this._options);\n this._retryTimer = null;\n diag.debug(\"AzureMonitorTraceExporter 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 try {\n const { result, statusCode } = await this._sender.send(envelopes);\n this._numConsecutiveRedirects = 0;\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._options.batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\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 // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\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 return { code: ExportResultCode.FAILED, error: new Error(\"Circular redirect\") };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\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\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 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"]}
@@ -0,0 +1,50 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { diag } from "@opentelemetry/api";
4
+ import { AggregationTemporality, } from "@opentelemetry/sdk-metrics-base";
5
+ import { AzureMonitorBaseExporter } from "./base";
6
+ import { resourceMetricsToEnvelope } from "../utils/metricUtils";
7
+ /**
8
+ * Azure Monitor OpenTelemetry Metric Exporter.
9
+ */
10
+ export class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
11
+ /**
12
+ * Initializes a new instance of the AzureMonitorMetricExporter class.
13
+ * @param AzureExporterConfig - Exporter configuration.
14
+ */
15
+ constructor(options = {}) {
16
+ super(options);
17
+ diag.debug("AzureMonitorMetricExporter was successfully setup");
18
+ }
19
+ /**
20
+ * Export OpenTelemetry resource metrics.
21
+ * @param metrics - Resource metrics to export.
22
+ * @param resultCallback - Result callback.
23
+ */
24
+ async export(metrics, resultCallback) {
25
+ diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);
26
+ let envelopes = resourceMetricsToEnvelope(metrics, this._instrumentationKey);
27
+ resultCallback(await this._exportEnvelopes(envelopes));
28
+ }
29
+ /**
30
+ * Shutdown AzureMonitorMetricExporter.
31
+ */
32
+ async shutdown() {
33
+ diag.info("Azure Monitor Trace Exporter shutting down");
34
+ return this._shutdown();
35
+ }
36
+ /**
37
+ * Select aggregation temporality
38
+ */
39
+ selectAggregationTemporality() {
40
+ return AggregationTemporality.CUMULATIVE;
41
+ }
42
+ /**
43
+ * Force flush
44
+ */
45
+ async forceFlush() {
46
+ // TODO: https://github.com/open-telemetry/opentelemetry-js/issues/3060
47
+ throw new Error("Method not implemented.");
48
+ }
49
+ }
50
+ //# sourceMappingURL=metric.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,sBAAsB,GAGvB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;GAEG;AACH,MAAM,OAAO,0BACX,SAAQ,wBAAwB;IAGhC;;;OAGG;IACH,YAAY,UAA+B,EAAE;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CACV,OAAwB,EACxB,cAA8C;QAE9C,IAAI,CAAC,IAAI,CAAC,aAAa,OAAO,CAAC,YAAY,CAAC,MAAM,yCAAyC,CAAC,CAAC;QAE7F,IAAI,SAAS,GAAe,yBAAyB,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACzF,cAAc,CAAC,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACI,4BAA4B;QACjC,OAAO,sBAAsB,CAAC,UAAU,CAAC;IAC3C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,uEAAuE;QACvE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { diag } from \"@opentelemetry/api\";\nimport {\n AggregationTemporality,\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics-base\";\nimport { ExportResult } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { AzureExporterConfig } from \"../config\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { resourceMetricsToEnvelope } from \"../utils/metricUtils\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Exporter.\n */\nexport class AzureMonitorMetricExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Initializes a new instance of the AzureMonitorMetricExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureExporterConfig = {}) {\n super(options);\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 diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);\n\n let envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this._instrumentationKey);\n resultCallback(await this._exportEnvelopes(envelopes));\n }\n\n /**\n * Shutdown AzureMonitorMetricExporter.\n */\n public async shutdown(): Promise<void> {\n diag.info(\"Azure Monitor Trace Exporter shutting down\");\n return this._shutdown();\n }\n\n /**\n * Select aggregation temporality\n */\n public selectAggregationTemporality() {\n return AggregationTemporality.CUMULATIVE;\n }\n\n /**\n * Force flush\n */\n public async forceFlush() {\n // TODO: https://github.com/open-telemetry/opentelemetry-js/issues/3060\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
@@ -1,142 +1,20 @@
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
- import { ConnectionStringParser } from "../utils/connectionStringParser";
6
- import { HttpSender, FileSystemPersist } from "../platform";
7
- import { DEFAULT_EXPORTER_CONFIG, } from "../config";
8
- import { isRetriable } from "../utils/breezeUtils";
9
- import { ENV_CONNECTION_STRING } from "../Declarations/Constants";
10
- import { readableSpanToEnvelope } from "../utils/spanUtils";
4
+ import { AzureMonitorBaseExporter } from "./base";
5
+ import { readableSpanToEnvelope, spanEventsToEnvelopes } from "../utils/spanUtils";
11
6
  /**
12
7
  * Azure Monitor OpenTelemetry Trace Exporter.
13
8
  */
14
- export class AzureMonitorTraceExporter {
9
+ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
15
10
  /**
16
11
  * Initializes a new instance of the AzureMonitorTraceExporter class.
17
12
  * @param AzureExporterConfig - Exporter configuration.
18
13
  */
19
14
  constructor(options = {}) {
20
- var _a, _b, _c, _d;
21
- this._numConsecutiveRedirects = 0;
22
- const connectionString = options.connectionString || process.env[ENV_CONNECTION_STRING];
23
- this._options = Object.assign({}, DEFAULT_EXPORTER_CONFIG);
24
- this._options.apiVersion = (_a = options.apiVersion) !== null && _a !== void 0 ? _a : this._options.apiVersion;
25
- this._options.aadTokenCredential = options.aadTokenCredential;
26
- if (connectionString) {
27
- const parsedConnectionString = ConnectionStringParser.parse(connectionString);
28
- this._options.instrumentationKey =
29
- (_b = parsedConnectionString.instrumentationkey) !== null && _b !== void 0 ? _b : this._options.instrumentationKey;
30
- this._options.endpointUrl =
31
- (_d = (_c = parsedConnectionString.ingestionendpoint) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : this._options.endpointUrl;
32
- }
33
- // Instrumentation key is required
34
- if (!this._options.instrumentationKey) {
35
- const message = "No instrumentation key or connection string was provided to the Azure Monitor Exporter";
36
- diag.error(message);
37
- throw new Error(message);
38
- }
39
- this._sender = new HttpSender(this._options);
40
- this._persister = new FileSystemPersist(this._options);
41
- this._retryTimer = null;
15
+ super(options);
42
16
  diag.debug("AzureMonitorTraceExporter was successfully setup");
43
17
  }
44
- async _persist(envelopes) {
45
- try {
46
- const success = await this._persister.push(envelopes);
47
- return success
48
- ? { code: ExportResultCode.SUCCESS }
49
- : {
50
- code: ExportResultCode.FAILED,
51
- error: new Error("Failed to persist envelope in disk."),
52
- };
53
- }
54
- catch (ex) {
55
- return { code: ExportResultCode.FAILED, error: ex };
56
- }
57
- }
58
- async exportEnvelopes(envelopes) {
59
- diag.info(`Exporting ${envelopes.length} envelope(s)`);
60
- try {
61
- const { result, statusCode } = await this._sender.send(envelopes);
62
- this._numConsecutiveRedirects = 0;
63
- if (statusCode === 200) {
64
- // Success -- @todo: start retry timer
65
- if (!this._retryTimer) {
66
- this._retryTimer = setTimeout(() => {
67
- this._retryTimer = null;
68
- this._sendFirstPersistedFile();
69
- }, this._options.batchSendRetryIntervalMs);
70
- this._retryTimer.unref();
71
- }
72
- return { code: ExportResultCode.SUCCESS };
73
- }
74
- else if (statusCode && isRetriable(statusCode)) {
75
- // Failed -- persist failed data
76
- if (result) {
77
- diag.info(result);
78
- const breezeResponse = JSON.parse(result);
79
- const filteredEnvelopes = [];
80
- breezeResponse.errors.forEach((error) => {
81
- if (error.statusCode && isRetriable(error.statusCode)) {
82
- filteredEnvelopes.push(envelopes[error.index]);
83
- }
84
- });
85
- if (filteredEnvelopes.length > 0) {
86
- // calls resultCallback(ExportResult) based on result of persister.push
87
- return await this._persist(filteredEnvelopes);
88
- }
89
- // Failed -- not retriable
90
- return {
91
- code: ExportResultCode.FAILED,
92
- };
93
- }
94
- else {
95
- // calls resultCallback(ExportResult) based on result of persister.push
96
- return await this._persist(envelopes);
97
- }
98
- }
99
- else {
100
- // Failed -- not retriable
101
- return {
102
- code: ExportResultCode.FAILED,
103
- };
104
- }
105
- }
106
- catch (error) {
107
- const restError = error;
108
- if (restError.statusCode &&
109
- (restError.statusCode === 307 || // Temporary redirect
110
- restError.statusCode === 308)) {
111
- // Permanent redirect
112
- this._numConsecutiveRedirects++;
113
- // To prevent circular redirects
114
- if (this._numConsecutiveRedirects < 10) {
115
- if (restError.response && restError.response.headers) {
116
- const location = restError.response.headers.get("location");
117
- if (location) {
118
- // Update sender URL
119
- this._sender.handlePermanentRedirect(location);
120
- // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically
121
- return this.exportEnvelopes(envelopes);
122
- }
123
- }
124
- }
125
- else {
126
- return { code: ExportResultCode.FAILED, error: new Error("Circular redirect") };
127
- }
128
- }
129
- else if (restError.statusCode && isRetriable(restError.statusCode)) {
130
- return await this._persist(envelopes);
131
- }
132
- if (this._isNetworkError(restError)) {
133
- diag.error("Retrying due to transient client side error. Error message:", restError.message);
134
- return await this._persist(envelopes);
135
- }
136
- diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
137
- return { code: ExportResultCode.FAILED, error: restError };
138
- }
139
- }
140
18
  /**
141
19
  * Export OpenTelemetry spans.
142
20
  * @param spans - Spans to export.
@@ -144,32 +22,22 @@ export class AzureMonitorTraceExporter {
144
22
  */
145
23
  async export(spans, resultCallback) {
146
24
  diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);
147
- const envelopes = spans.map((span) => readableSpanToEnvelope(span, this._options.instrumentationKey));
148
- resultCallback(await this.exportEnvelopes(envelopes));
25
+ let envelopes = [];
26
+ spans.forEach((span) => {
27
+ envelopes.push(readableSpanToEnvelope(span, this._instrumentationKey));
28
+ let spanEventEnvelopes = spanEventsToEnvelopes(span, this._instrumentationKey);
29
+ if (spanEventEnvelopes.length > 0) {
30
+ envelopes.push(...spanEventEnvelopes);
31
+ }
32
+ });
33
+ resultCallback(await this._exportEnvelopes(envelopes));
149
34
  }
150
35
  /**
151
36
  * Shutdown AzureMonitorTraceExporter.
152
37
  */
153
38
  async shutdown() {
154
39
  diag.info("Azure Monitor Trace Exporter shutting down");
155
- return this._sender.shutdown();
156
- }
157
- async _sendFirstPersistedFile() {
158
- try {
159
- const envelopes = (await this._persister.shift());
160
- if (envelopes) {
161
- await this._sender.send(envelopes);
162
- }
163
- }
164
- catch (err) {
165
- diag.warn(`Failed to fetch persisted file`, err);
166
- }
167
- }
168
- _isNetworkError(error) {
169
- if (error && error.code && error.code === "REQUEST_SEND_ERROR") {
170
- return true;
171
- }
172
- return false;
40
+ return this._shutdown();
173
41
  }
174
42
  }
175
43
  //# sourceMappingURL=trace.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,uBAAuB,GAGxB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;GAEG;AACH,MAAM,OAAO,yBAAyB;IAOpC;;;OAGG;IACH,YAAY,UAA+B,EAAE;;QAC3C,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;QAClC,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACxF,IAAI,CAAC,QAAQ,qBACR,uBAAuB,CAC3B,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAE9D,IAAI,gBAAgB,EAAE;YACpB,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAC9E,IAAI,CAAC,QAAQ,CAAC,k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AC,OAAO,GAAG,EAAE;YACZ,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 { ReadableSpan, SpanExporter } from \"@opentelemetry/sdk-trace-base\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { HttpSender, FileSystemPersist } from \"../platform\";\nimport {\n DEFAULT_EXPORTER_CONFIG,\n AzureExporterConfig,\n AzureExporterInternalConfig,\n} from \"../config\";\nimport { PersistentStorage, Sender } from \"../types\";\nimport { isRetriable, BreezeResponse } from \"../utils/breezeUtils\";\nimport { ENV_CONNECTION_STRING } from \"../Declarations/Constants\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { readableSpanToEnvelope } from \"../utils/spanUtils\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport class AzureMonitorTraceExporter implements SpanExporter {\n private readonly _persister: PersistentStorage;\n private readonly _sender: Sender;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n private readonly _options: AzureExporterInternalConfig;\n\n /**\n * Initializes a new instance of the AzureMonitorTraceExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureExporterConfig = {}) {\n this._numConsecutiveRedirects = 0;\n const connectionString = options.connectionString || process.env[ENV_CONNECTION_STRING];\n this._options = {\n ...DEFAULT_EXPORTER_CONFIG,\n };\n this._options.apiVersion = options.apiVersion ?? this._options.apiVersion;\n this._options.aadTokenCredential = options.aadTokenCredential;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this._options.instrumentationKey =\n parsedConnectionString.instrumentationkey ?? this._options.instrumentationKey;\n this._options.endpointUrl =\n parsedConnectionString.ingestionendpoint?.trim() ?? this._options.endpointUrl;\n }\n // Instrumentation key is required\n if (!this._options.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\n this._sender = new HttpSender(this._options);\n this._persister = new FileSystemPersist(this._options);\n this._retryTimer = null;\n diag.debug(\"AzureMonitorTraceExporter was successfully setup\");\n }\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) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n private async exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n try {\n const { result, statusCode } = await this._sender.send(envelopes);\n this._numConsecutiveRedirects = 0;\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._options.batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n if (filteredEnvelopes.length > 0) {\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error) {\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 return { code: ExportResultCode.FAILED, error: new Error(\"Circular redirect\") };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\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\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 /**\n * Export OpenTelemetry spans.\n * @param spans - Spans to export.\n * @param resultCallback - Result callback.\n */\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);\n const envelopes = spans.map((span) =>\n readableSpanToEnvelope(span, this._options.instrumentationKey)\n );\n resultCallback(await this.exportEnvelopes(envelopes));\n }\n\n /**\n * Shutdown AzureMonitorTraceExporter.\n */\n async shutdown(): Promise<void> {\n diag.info(\"Azure Monitor Trace Exporter shutting down\");\n return this._sender.shutdown();\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) {\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":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEnF;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,wBAAwB;IACrE;;;OAGG;IACH,YAAY,UAA+B,EAAE;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CACV,KAAqB,EACrB,cAA8C;QAE9C,IAAI,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,MAAM,sCAAsC,CAAC,CAAC;QAE3E,IAAI,SAAS,GAAe,EAAE,CAAC;QAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;YACvE,IAAI,kBAAkB,GAAG,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;YAC/E,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACjC,SAAS,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAC;aACvC;QACH,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult } from \"@opentelemetry/core\";\nimport { ReadableSpan, SpanExporter } from \"@opentelemetry/sdk-trace-base\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { AzureExporterConfig } from \"../config\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { readableSpanToEnvelope, spanEventsToEnvelopes } from \"../utils/spanUtils\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {\n /**\n * Initializes a new instance of the AzureMonitorTraceExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureExporterConfig = {}) {\n super(options);\n diag.debug(\"AzureMonitorTraceExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry spans.\n * @param spans - Spans to export.\n * @param resultCallback - Result callback.\n */\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);\n\n let envelopes: Envelope[] = [];\n spans.forEach((span) => {\n envelopes.push(readableSpanToEnvelope(span, this._instrumentationKey));\n let spanEventEnvelopes = spanEventsToEnvelopes(span, this._instrumentationKey);\n if (spanEventEnvelopes.length > 0) {\n envelopes.push(...spanEventEnvelopes);\n }\n });\n resultCallback(await this._exportEnvelopes(envelopes));\n }\n\n /**\n * Shutdown AzureMonitorTraceExporter.\n */\n async shutdown(): Promise<void> {\n diag.info(\"Azure Monitor Trace Exporter shutting down\");\n return this._shutdown();\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
+ export { AzureMonitorBaseExporter } from "./export/base";
3
4
  export { AzureMonitorTraceExporter } from "./export/trace";
5
+ export { AzureMonitorMetricExporter } from "./export/metric";
4
6
  export { ServiceApiVersion } from "./Declarations/Constants";
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { AzureMonitorTraceExporter } from \"./export/trace\";\nexport { AzureExporterConfig } from \"./config\";\nexport { ServiceApiVersion } from \"./Declarations/Constants\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { AzureMonitorBaseExporter } from \"./export/base\";\nexport { AzureMonitorTraceExporter } from \"./export/trace\";\nexport { AzureMonitorMetricExporter } from \"./export/metric\";\nexport { AzureExporterConfig } from \"./config\";\nexport { ServiceApiVersion } from \"./Declarations/Constants\";\nexport { MonitorBase, MonitorDomain, TelemetryItem } from \"./generated/models\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"httpSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/httpSender.ts"],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UAAU,EAAE;oBACtB,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;iBAC/C;YACH,CAAC;YACD,MAAM,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,SAAS,kCACxC,OAAO,KACV,UAAU,IACV,CAAC;YAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,mCAAI,EAAE,EAAE,CAAC;SAC7E;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,CAAC;SACT;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACxC,CAAC;IAED,uBAAuB,CAAC,QAA4B;QAClD,IAAI,QAAQ,EAAE;YACZ,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACrC,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;gBACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;aACzD;SACF;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport url from \"url\";\nimport { diag } from \"@opentelemetry/api\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { bearerTokenAuthenticationPolicy, redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport { Sender, SenderResult } from \"../../types\";\nimport {\n TelemetryItem as Envelope,\n ApplicationInsightsClient,\n ApplicationInsightsClientOptionalParams,\n TrackOptionalParams,\n} from \"../../generated\";\nimport { AzureExporterInternalConfig } from \"../../config\";\n\nconst applicationInsightsResource = \"https://monitor.azure.com//.default\";\n\n/**\n * Exporter HTTP sender class\n * @internal\n */\nexport class HttpSender implements Sender {\n private readonly _appInsightsClient: ApplicationInsightsClient;\n private _appInsightsClientOptions: ApplicationInsightsClientOptionalParams;\n\n constructor(private _exporterOptions: AzureExporterInternalConfig) {\n // Build endpoint using provided configuration or default values\n this._appInsightsClientOptions = {\n host: this._exporterOptions.endpointUrl,\n };\n this._appInsightsClient = new ApplicationInsightsClient({\n ...this._appInsightsClientOptions,\n });\n // Handle redirects in HTTP Sender\n this._appInsightsClient.pipeline.removePolicy({ name: redirectPolicyName });\n\n if (this._exporterOptions.aadTokenCredential) {\n let scopes: string[] = [applicationInsightsResource];\n this._appInsightsClient.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential: this._exporterOptions.aadTokenCredential,\n scopes: scopes,\n })\n );\n }\n }\n\n /**\n * Send Azure envelopes\n * @internal\n */\n async send(envelopes: Envelope[]): Promise<SenderResult> {\n let options: TrackOptionalParams = {};\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n await this._appInsightsClient.track(envelopes, {\n ...options,\n onResponse,\n });\n\n return { statusCode: response?.status, result: response?.bodyAsText ?? \"\" };\n } catch (e) {\n throw e;\n }\n }\n\n /**\n * Shutdown sender\n * @internal\n */\n async shutdown(): Promise<void> {\n diag.info(\"HttpSender shutting down\");\n }\n\n handlePermanentRedirect(location: string | undefined) {\n if (location) {\n const locUrl = new url.URL(location);\n if (locUrl && locUrl.host) {\n this._appInsightsClient.host = \"https://\" + locUrl.host;\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"httpSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/httpSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,+BAA+B,EAAE,kBAAkB,E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IACV,CAAC;YAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,mCAAI,EAAE,EAAE,CAAC;SAC7E;QAAC,OAAO,CAAM,EAAE;YACf,MAAM,CAAC,CAAC;SACT;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACxC,CAAC;IAED,uBAAuB,CAAC,QAA4B;QAClD,IAAI,QAAQ,EAAE;YACZ,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACrC,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;gBACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;aACzD;SACF;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport url from \"url\";\nimport { diag } from \"@opentelemetry/api\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { bearerTokenAuthenticationPolicy, redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport { Sender, SenderResult } from \"../../types\";\nimport {\n TelemetryItem as Envelope,\n ApplicationInsightsClient,\n ApplicationInsightsClientOptionalParams,\n TrackOptionalParams,\n} from \"../../generated\";\nimport { AzureExporterInternalConfig } from \"../../config\";\n\nconst applicationInsightsResource = \"https://monitor.azure.com//.default\";\n\n/**\n * Exporter HTTP sender class\n * @internal\n */\nexport class HttpSender implements Sender {\n private readonly _appInsightsClient: ApplicationInsightsClient;\n private _appInsightsClientOptions: ApplicationInsightsClientOptionalParams;\n\n constructor(private _exporterOptions: AzureExporterInternalConfig) {\n // Build endpoint using provided configuration or default values\n this._appInsightsClientOptions = {\n host: this._exporterOptions.endpointUrl,\n };\n this._appInsightsClient = new ApplicationInsightsClient({\n ...this._appInsightsClientOptions,\n });\n // Handle redirects in HTTP Sender\n this._appInsightsClient.pipeline.removePolicy({ name: redirectPolicyName });\n\n if (this._exporterOptions.aadTokenCredential) {\n let scopes: string[] = [applicationInsightsResource];\n this._appInsightsClient.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential: this._exporterOptions.aadTokenCredential,\n scopes: scopes,\n })\n );\n }\n }\n\n /**\n * Send Azure envelopes\n * @internal\n */\n async send(envelopes: Envelope[]): Promise<SenderResult> {\n let options: TrackOptionalParams = {};\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n await this._appInsightsClient.track(envelopes, {\n ...options,\n onResponse,\n });\n\n return { statusCode: response?.status, result: response?.bodyAsText ?? \"\" };\n } catch (e: any) {\n throw e;\n }\n }\n\n /**\n * Shutdown sender\n * @internal\n */\n async shutdown(): Promise<void> {\n diag.info(\"HttpSender shutting down\");\n }\n\n handlePermanentRedirect(location: string | undefined) {\n if (location) {\n const locUrl = new url.URL(location);\n if (locUrl && locUrl.host) {\n this._appInsightsClient.host = \"https://\" + locUrl.host;\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fileAccessControl.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileAccessControl.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,aAAa,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,OAAO,iBAAiB;IAS5B,gDAAgD;IACzC,MAAM,CAAC,mBAAmB;QAC/B,IACE,CAAC,iBAAiB,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AM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;SAC9F;IACH,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,SAAiB,EAAE,QAAgB;QACjE,OAAO;YACL,SAAS;YACT,QAAQ;YACR,yBAAyB;YACzB,QAAQ;YACR,GAAG,QAAQ,YAAY;YACvB,gBAAgB;SACjB,CAAC,CAAC,mCAAmC;IACxC,CAAC;;AAhLc,6BAAW,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,8BAA8B,CAAC;AACvE,iCAAe,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,yDAAyD,CAAC;AACtG,mCAAiB,GAA8B,EAAE,CAAC;AAClD,8BAAY,GAAkB,IAAI,CAAC;AACnC,4CAA0B,GAAG,KAAK,CAAC;AACpC,6CAA2B,GAAG,KAAK,CAAC;AACpC,4BAAU,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as os from \"os\";\nimport * as child_process from \"child_process\";\nimport { diag } from \"@opentelemetry/api\";\n\nexport class FileAccessControl {\n private static ICACLS_PATH = `${process.env.systemdrive}/windows/system32/icacls.exe`;\n private static POWERSHELL_PATH = `${process.env.systemdrive}/windows/system32/windowspowershell/v1.0/powershell.exe`;\n private static ACLED_DIRECTORIES: { [id: string]: boolean } = {};\n private static ACL_IDENTITY: string | null = null;\n private static OS_FILE_PROTECTION_CHECKED = false;\n public static OS_PROVIDES_FILE_PROTECTION = false;\n public static USE_ICACLS = os.type() === \"Windows_NT\";\n\n // Check if file access control could be enabled\n public static checkFileProtection() {\n if (\n !FileAccessControl.OS_PROVIDES_FILE_PROTECTION &&\n !FileAccessControl.OS_FILE_PROTECTION_CHECKED\n ) {\n FileAccessControl.OS_FILE_PROTECTION_CHECKED = true;\n // Node's chmod levels do not appropriately restrict file access on Windows\n // Use the built-in command line tool ICACLS on Windows to properly restrict\n // access to the temporary directory used for disk retry mode.\n if (FileAccessControl.USE_ICACLS) {\n // This should be async - but it's currently safer to have this synchronous\n // This guarantees we can immediately fail setDiskRetryMode if we need to\n try {\n FileAccessControl.OS_PROVIDES_FILE_PROTECTION = fs.existsSync(\n FileAccessControl.ICACLS_PATH\n );\n } catch (e) {\n // Ignore error\n }\n if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION) {\n diag.warn(\n \"Could not find ICACLS in expected location! This is necessary to use disk retry mode on Windows.\"\n );\n }\n } else {\n // chmod works everywhere else\n FileAccessControl.OS_PROVIDES_FILE_PROTECTION = true;\n }\n }\n }\n\n public static async applyACLRules(directory: string): Promise<void> {\n if (FileAccessControl.USE_ICACLS) {\n if (FileAccessControl.ACLED_DIRECTORIES[directory] === undefined) {\n // Avoid multiple calls race condition by setting ACLED_DIRECTORIES to false for this directory immediately\n // If batches are being failed faster than the processes spawned below return, some data won't be stored to disk\n // This is better than the alternative of potentially infinitely spawned processes\n FileAccessControl.ACLED_DIRECTORIES[directory] = false;\n try {\n // Restrict this directory to only current user and administrator access\n let identity = await this._getACLIdentity();\n await this._runICACLS(this._getACLArguments(directory, identity));\n FileAccessControl.ACLED_DIRECTORIES[directory] = true;\n } catch (ex) {\n FileAccessControl.ACLED_DIRECTORIES[directory] = false; // false is used to cache failed (vs undefined which is \"not yet tried\")\n throw ex;\n }\n } else {\n if (!FileAccessControl.ACLED_DIRECTORIES[directory]) {\n throw new Error(\"Setting ACL restrictions did not succeed (cached result)\");\n }\n }\n }\n }\n\n public static applyACLRulesSync(directory: string) {\n if (FileAccessControl.USE_ICACLS) {\n // For performance, only run ACL rules if we haven't already during this session\n if (FileAccessControl.ACLED_DIRECTORIES[directory] === undefined) {\n this._runICACLSSync(this._getACLArguments(directory, this._getACLIdentitySync()));\n FileAccessControl.ACLED_DIRECTORIES[directory] = true; // If we get here, it succeeded. _runIACLSSync will throw on failures\n return;\n } else if (!FileAccessControl.ACLED_DIRECTORIES[directory]) {\n // falsy but not undefined\n throw new Error(\"Setting ACL restrictions did not succeed (cached result)\");\n }\n }\n }\n\n private static _runICACLS(args: string[]): Promise<void> {\n return new Promise((resolve, reject) => {\n var aclProc = child_process.spawn(FileAccessControl.ICACLS_PATH, args, <any>{\n windowsHide: true,\n });\n aclProc.on(\"error\", (e: Error) => reject(e));\n aclProc.on(\"close\", (code: number) => {\n if (code === 0) {\n resolve();\n } else {\n reject(\n new Error(`Setting ACL restrictions did not succeed (ICACLS returned code ${code})`)\n );\n }\n });\n });\n }\n\n private static _runICACLSSync(args: string[]) {\n // Some very old versions of Node (< 0.11) don't have this\n if (child_process.spawnSync) {\n var aclProc = child_process.spawnSync(FileAccessControl.ICACLS_PATH, args, <any>{\n windowsHide: true,\n });\n if (aclProc.error) {\n throw aclProc.error;\n } else if (aclProc.status !== 0) {\n throw new Error(\n `Setting ACL restrictions did not succeed (ICACLS returned code ${aclProc.status})`\n );\n }\n } else {\n throw new Error(\"Could not synchronously call ICACLS under current version of Node.js\");\n }\n }\n\n private static _getACLIdentity(): Promise<string> {\n return new Promise((resolve, reject) => {\n if (FileAccessControl.ACL_IDENTITY) {\n resolve(FileAccessControl.ACL_IDENTITY);\n }\n var psProc = child_process.spawn(\n FileAccessControl.POWERSHELL_PATH,\n [\"-Command\", \"[System.Security.Principal.WindowsIdentity]::GetCurrent().Name\"],\n <any>{\n windowsHide: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"], // Needed to prevent hanging on Win 7\n }\n );\n let data = \"\";\n psProc.stdout.on(\"data\", (d: string) => (data += d));\n psProc.on(\"error\", (e: Error) => reject(e));\n psProc.on(\"close\", (code: number) => {\n FileAccessControl.ACL_IDENTITY = data && data.trim();\n if (code === 0) {\n resolve(FileAccessControl.ACL_IDENTITY);\n } else {\n reject(new Error(`Getting ACL identity did not succeed (PS returned code ${code})`));\n }\n });\n });\n }\n\n private static _getACLIdentitySync() {\n if (FileAccessControl.ACL_IDENTITY) {\n return FileAccessControl.ACL_IDENTITY;\n }\n // Some very old versions of Node (< 0.11) don't have this\n if (child_process.spawnSync) {\n var psProc = child_process.spawnSync(\n FileAccessControl.POWERSHELL_PATH,\n [\"-Command\", \"[System.Security.Principal.WindowsIdentity]::GetCurrent().Name\"],\n <any>{\n windowsHide: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"], // Needed to prevent hanging on Win 7\n }\n );\n if (psProc.error) {\n throw psProc.error;\n } else if (psProc.status !== 0) {\n throw new Error(`Getting ACL identity did not succeed (PS returned code ${psProc.status})`);\n }\n FileAccessControl.ACL_IDENTITY = psProc.stdout && psProc.stdout.toString().trim();\n return FileAccessControl.ACL_IDENTITY;\n } else {\n throw new Error(\"Could not synchronously get ACL identity under current version of Node.js\");\n }\n }\n\n private static _getACLArguments(directory: string, identity: string) {\n return [\n directory,\n \"/grant\",\n \"*S-1-5-32-544:(OI)(CI)F\", // Full permission for Administrators\n \"/grant\",\n `${identity}:(OI)(CI)F`, // Full permission for current user\n \"/inheritance:r\",\n ]; // Remove all inherited permissions\n }\n}\n"]}
1
+ {"version":3,"file":"fileAccessControl.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileAccessControl.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,aAAa,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,OAAO,iBAAiB;IAS5B,gDAAgD;IACzC,MAAM,CAAC,mBAAmB;QAC/B,IACE,CAAC,iBAAiB,CAAC,2BAA2B;YAC9C,CAAC,iBAAiB,CAAC,0BAA0B,EAC7C;YACA,iBAAiB,CAAC,0BAA0B,GAAG,IAAI,CAAC;YACpD,2EAA2E;YAC3E,4EAA4E;YAC5E,8DAA8D;YAC9D,IAAI,iBAAiB,CAAC,UAAU,EAAE;gBA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,YAAY;YACvB,gBAAgB;SACjB,CAAC,CAAC,mCAAmC;IACxC,CAAC;;AAhLc,6BAAW,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,8BAA8B,CAAC;AACvE,iCAAe,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,yDAAyD,CAAC;AACtG,mCAAiB,GAA8B,EAAE,CAAC;AAClD,8BAAY,GAAkB,IAAI,CAAC;AACnC,4CAA0B,GAAG,KAAK,CAAC;AACpC,6CAA2B,GAAG,KAAK,CAAC;AACpC,4BAAU,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as os from \"os\";\nimport * as child_process from \"child_process\";\nimport { diag } from \"@opentelemetry/api\";\n\nexport class FileAccessControl {\n private static ICACLS_PATH = `${process.env.systemdrive}/windows/system32/icacls.exe`;\n private static POWERSHELL_PATH = `${process.env.systemdrive}/windows/system32/windowspowershell/v1.0/powershell.exe`;\n private static ACLED_DIRECTORIES: { [id: string]: boolean } = {};\n private static ACL_IDENTITY: string | null = null;\n private static OS_FILE_PROTECTION_CHECKED = false;\n public static OS_PROVIDES_FILE_PROTECTION = false;\n public static USE_ICACLS = os.type() === \"Windows_NT\";\n\n // Check if file access control could be enabled\n public static checkFileProtection() {\n if (\n !FileAccessControl.OS_PROVIDES_FILE_PROTECTION &&\n !FileAccessControl.OS_FILE_PROTECTION_CHECKED\n ) {\n FileAccessControl.OS_FILE_PROTECTION_CHECKED = true;\n // Node's chmod levels do not appropriately restrict file access on Windows\n // Use the built-in command line tool ICACLS on Windows to properly restrict\n // access to the temporary directory used for disk retry mode.\n if (FileAccessControl.USE_ICACLS) {\n // This should be async - but it's currently safer to have this synchronous\n // This guarantees we can immediately fail setDiskRetryMode if we need to\n try {\n FileAccessControl.OS_PROVIDES_FILE_PROTECTION = fs.existsSync(\n FileAccessControl.ICACLS_PATH\n );\n } catch (e: any) {\n // Ignore error\n }\n if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION) {\n diag.warn(\n \"Could not find ICACLS in expected location! This is necessary to use disk retry mode on Windows.\"\n );\n }\n } else {\n // chmod works everywhere else\n FileAccessControl.OS_PROVIDES_FILE_PROTECTION = true;\n }\n }\n }\n\n public static async applyACLRules(directory: string): Promise<void> {\n if (FileAccessControl.USE_ICACLS) {\n if (FileAccessControl.ACLED_DIRECTORIES[directory] === undefined) {\n // Avoid multiple calls race condition by setting ACLED_DIRECTORIES to false for this directory immediately\n // If batches are being failed faster than the processes spawned below return, some data won't be stored to disk\n // This is better than the alternative of potentially infinitely spawned processes\n FileAccessControl.ACLED_DIRECTORIES[directory] = false;\n try {\n // Restrict this directory to only current user and administrator access\n let identity = await this._getACLIdentity();\n await this._runICACLS(this._getACLArguments(directory, identity));\n FileAccessControl.ACLED_DIRECTORIES[directory] = true;\n } catch (ex: any) {\n FileAccessControl.ACLED_DIRECTORIES[directory] = false; // false is used to cache failed (vs undefined which is \"not yet tried\")\n throw ex;\n }\n } else {\n if (!FileAccessControl.ACLED_DIRECTORIES[directory]) {\n throw new Error(\"Setting ACL restrictions did not succeed (cached result)\");\n }\n }\n }\n }\n\n public static applyACLRulesSync(directory: string) {\n if (FileAccessControl.USE_ICACLS) {\n // For performance, only run ACL rules if we haven't already during this session\n if (FileAccessControl.ACLED_DIRECTORIES[directory] === undefined) {\n this._runICACLSSync(this._getACLArguments(directory, this._getACLIdentitySync()));\n FileAccessControl.ACLED_DIRECTORIES[directory] = true; // If we get here, it succeeded. _runIACLSSync will throw on failures\n return;\n } else if (!FileAccessControl.ACLED_DIRECTORIES[directory]) {\n // falsy but not undefined\n throw new Error(\"Setting ACL restrictions did not succeed (cached result)\");\n }\n }\n }\n\n private static _runICACLS(args: string[]): Promise<void> {\n return new Promise((resolve, reject) => {\n var aclProc = child_process.spawn(FileAccessControl.ICACLS_PATH, args, <any>{\n windowsHide: true,\n });\n aclProc.on(\"error\", (e: Error) => reject(e));\n aclProc.on(\"close\", (code: number) => {\n if (code === 0) {\n resolve();\n } else {\n reject(\n new Error(`Setting ACL restrictions did not succeed (ICACLS returned code ${code})`)\n );\n }\n });\n });\n }\n\n private static _runICACLSSync(args: string[]) {\n // Some very old versions of Node (< 0.11) don't have this\n if (child_process.spawnSync) {\n var aclProc = child_process.spawnSync(FileAccessControl.ICACLS_PATH, args, <any>{\n windowsHide: true,\n });\n if (aclProc.error) {\n throw aclProc.error;\n } else if (aclProc.status !== 0) {\n throw new Error(\n `Setting ACL restrictions did not succeed (ICACLS returned code ${aclProc.status})`\n );\n }\n } else {\n throw new Error(\"Could not synchronously call ICACLS under current version of Node.js\");\n }\n }\n\n private static _getACLIdentity(): Promise<string> {\n return new Promise((resolve, reject) => {\n if (FileAccessControl.ACL_IDENTITY) {\n resolve(FileAccessControl.ACL_IDENTITY);\n }\n var psProc = child_process.spawn(\n FileAccessControl.POWERSHELL_PATH,\n [\"-Command\", \"[System.Security.Principal.WindowsIdentity]::GetCurrent().Name\"],\n <any>{\n windowsHide: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"], // Needed to prevent hanging on Win 7\n }\n );\n let data = \"\";\n psProc.stdout.on(\"data\", (d: string) => (data += d));\n psProc.on(\"error\", (e: Error) => reject(e));\n psProc.on(\"close\", (code: number) => {\n FileAccessControl.ACL_IDENTITY = data && data.trim();\n if (code === 0) {\n resolve(FileAccessControl.ACL_IDENTITY);\n } else {\n reject(new Error(`Getting ACL identity did not succeed (PS returned code ${code})`));\n }\n });\n });\n }\n\n private static _getACLIdentitySync() {\n if (FileAccessControl.ACL_IDENTITY) {\n return FileAccessControl.ACL_IDENTITY;\n }\n // Some very old versions of Node (< 0.11) don't have this\n if (child_process.spawnSync) {\n var psProc = child_process.spawnSync(\n FileAccessControl.POWERSHELL_PATH,\n [\"-Command\", \"[System.Security.Principal.WindowsIdentity]::GetCurrent().Name\"],\n <any>{\n windowsHide: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"], // Needed to prevent hanging on Win 7\n }\n );\n if (psProc.error) {\n throw psProc.error;\n } else if (psProc.status !== 0) {\n throw new Error(`Getting ACL identity did not succeed (PS returned code ${psProc.status})`);\n }\n FileAccessControl.ACL_IDENTITY = psProc.stdout && psProc.stdout.toString().trim();\n return FileAccessControl.ACL_IDENTITY;\n } else {\n throw new Error(\"Could not synchronously get ACL identity under current version of Node.js\");\n }\n }\n\n private static _getACLArguments(directory: string, identity: string) {\n return [\n directory,\n \"/grant\",\n \"*S-1-5-32-544:(OI)(CI)F\", // Full permission for Administrators\n \"/grant\",\n `${identity}:(OI)(CI)F`, // Full permission for current user\n \"/inheritance:r\",\n ]; // Remove all inherited permissions\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fileSystemHelpers.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileSystemHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,YAAY,GAAG,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,UAAU,GAAG,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACvC,MAAM,UAAU,GAAG,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,SAAiB,EAAmB,EAAE;IAClF,4BAA4B;IAC5B,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAC;IAE5C,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,uBAAuB;IACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;QAC9D,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE;YACtB,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC;SAC7B;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,SAAiB,EAAiB,EAAE;IACzE,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SACzD;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YAChC,IAAI;gBACF,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC;aAC7B;YAAC,OAAO,QAAQ,EAAE;gBACjB,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;oBAC1C,2CAA2C;oBAC3C,MAAM,QAAQ,CAAC;iBAChB;aACF;SACF;KACF;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { promisify } from \"util\";\n\nconst readdirAsync = promisify(fs.readdir);\nconst statAsync = promisify(fs.stat);\nconst lstatAsync = promisify(fs.lstat);\nconst mkdirAsync = promisify(fs.mkdir);\n\n/**\n * Computes the size (in bytes) of all files in a directory at the root level. Asynchronously.\n * @internal\n */\nexport const getShallowDirectorySize = async (directory: string): Promise<number> => {\n // Get the directory listing\n const files = await readdirAsync(directory);\n\n let totalSize = 0;\n\n // Query all file sizes\n for (const file of files) {\n const fileStats = await statAsync(path.join(directory, file));\n if (fileStats.isFile()) {\n totalSize += fileStats.size;\n }\n }\n\n return totalSize;\n};\n\n/**\n * Validate directory exists.\n * @internal\n */\nexport const confirmDirExists = async (directory: string): Promise<void> => {\n try {\n const stats = await lstatAsync(directory);\n if (!stats.isDirectory()) {\n throw new Error(\"Path existed but was not a directory\");\n }\n } catch (err) {\n if (err && err.code === \"ENOENT\") {\n try {\n await mkdirAsync(directory);\n } catch (mkdirErr) {\n if (mkdirErr && mkdirErr.code !== \"EEXIST\") {\n // Handle race condition by ignoring EEXIST\n throw mkdirErr;\n }\n }\n }\n }\n};\n"]}
1
+ {"version":3,"file":"fileSystemHelpers.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileSystemHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,YAAY,GAAG,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,UAAU,GAAG,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACvC,MAAM,UAAU,GAAG,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,SAAiB,EAAmB,EAAE;IAClF,4BAA4B;IAC5B,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAC;IAE5C,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,uBAAuB;IACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;QAC9D,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE;YACtB,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC;SAC7B;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,SAAiB,EAAiB,EAAE;IACzE,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SACzD;KACF;IAAC,OAAO,GAAQ,EAAE;QACjB,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YAChC,IAAI;gBACF,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC;aAC7B;YAAC,OAAO,QAAa,EAAE;gBACtB,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;oBAC1C,2CAA2C;oBAC3C,MAAM,QAAQ,CAAC;iBAChB;aACF;SACF;KACF;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { promisify } from \"util\";\n\nconst readdirAsync = promisify(fs.readdir);\nconst statAsync = promisify(fs.stat);\nconst lstatAsync = promisify(fs.lstat);\nconst mkdirAsync = promisify(fs.mkdir);\n\n/**\n * Computes the size (in bytes) of all files in a directory at the root level. Asynchronously.\n * @internal\n */\nexport const getShallowDirectorySize = async (directory: string): Promise<number> => {\n // Get the directory listing\n const files = await readdirAsync(directory);\n\n let totalSize = 0;\n\n // Query all file sizes\n for (const file of files) {\n const fileStats = await statAsync(path.join(directory, file));\n if (fileStats.isFile()) {\n totalSize += fileStats.size;\n }\n }\n\n return totalSize;\n};\n\n/**\n * Validate directory exists.\n * @internal\n */\nexport const confirmDirExists = async (directory: string): Promise<void> => {\n try {\n const stats = await lstatAsync(directory);\n if (!stats.isDirectory()) {\n throw new Error(\"Path existed but was not a directory\");\n }\n } catch (err: any) {\n if (err && err.code === \"ENOENT\") {\n try {\n await mkdirAsync(directory);\n } catch (mkdirErr: any) {\n if (mkdirErr && mkdirErr.code !== \"EEXIST\") {\n // Handle race condition by ignoring EEXIST\n throw mkdirErr;\n }\n }\n }\n }\n};\n"]}