@azure/monitor-opentelemetry-exporter 1.0.0-beta.17 → 1.0.0-beta.18
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 +35 -11
- package/dist/index.js +20 -5
- package/dist-esm/src/export/statsbeat/statsbeatMetrics.js +13 -1
- package/dist-esm/src/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/types.js +3 -2
- package/dist-esm/src/export/statsbeat/types.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/platform/nodejs/baseSender.js.map +1 -1
- package/dist-esm/src/platform/nodejs/context/context.js +1 -2
- package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +1 -2
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +1 -2
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist-esm/src/utils/connectionStringParser.js +1 -2
- package/dist-esm/src/utils/connectionStringParser.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/package.json +17 -17
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP
|
|
|
23
23
|
|
|
24
24
|
### Distributed Tracing
|
|
25
25
|
|
|
26
|
-
Add the exporter to your existing OpenTelemetry
|
|
26
|
+
Add the exporter to your existing OpenTelemetry Tracer Provider (`NodeTracerProvider` / `BasicTracerProvider`)
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
29
|
const { AzureMonitorTraceExporter } = require("@azure/monitor-opentelemetry-exporter");
|
|
@@ -32,12 +32,13 @@ const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
|
|
|
32
32
|
const { Resource } = require("@opentelemetry/resources");
|
|
33
33
|
const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const tracerProvider = new NodeTracerProvider({
|
|
36
36
|
resource: new Resource({
|
|
37
37
|
[SemanticResourceAttributes.SERVICE_NAME]: "basic-service",
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
// Register Tracer Provider as global
|
|
41
|
+
tracerProvider.register();
|
|
41
42
|
|
|
42
43
|
// Create an exporter instance
|
|
43
44
|
const exporter = new AzureMonitorTraceExporter({
|
|
@@ -45,8 +46,8 @@ const exporter = new AzureMonitorTraceExporter({
|
|
|
45
46
|
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>"
|
|
46
47
|
});
|
|
47
48
|
|
|
48
|
-
// Add the exporter to the
|
|
49
|
-
|
|
49
|
+
// Add the exporter to the Provider
|
|
50
|
+
tracerProvider.addSpanProcessor(
|
|
50
51
|
new BatchSpanProcessor(exporter, {
|
|
51
52
|
bufferTimeout: 15000,
|
|
52
53
|
bufferSize: 1000
|
|
@@ -56,16 +57,14 @@ provider.addSpanProcessor(
|
|
|
56
57
|
|
|
57
58
|
### Metrics
|
|
58
59
|
|
|
59
|
-
Add the exporter to your existing OpenTelemetry
|
|
60
|
+
Add the exporter to your existing OpenTelemetry Meter Provider (`MeterProvider`)
|
|
60
61
|
|
|
61
62
|
```js
|
|
63
|
+
const { metrics } = require("@opentelemetry/api");
|
|
62
64
|
const { MeterProvider, PeriodicExportingMetricReader } = require("@opentelemetry/sdk-metrics");
|
|
63
65
|
const { AzureMonitorMetricExporter } = require("@azure/monitor-opentelemetry-exporter");
|
|
64
|
-
const { Resource } = require("@opentelemetry/resources");
|
|
65
|
-
const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
|
|
66
66
|
|
|
67
67
|
// Add the exporter into the MetricReader and register it with the MeterProvider
|
|
68
|
-
const provider = new MeterProvider();
|
|
69
68
|
const exporter = new AzureMonitorMetricExporter({
|
|
70
69
|
connectionString:
|
|
71
70
|
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
|
|
@@ -74,12 +73,37 @@ const metricReaderOptions = {
|
|
|
74
73
|
exporter: exporter,
|
|
75
74
|
};
|
|
76
75
|
const metricReader = new PeriodicExportingMetricReader(metricReaderOptions);
|
|
77
|
-
|
|
76
|
+
const meterProvider = new MeterProvider();
|
|
77
|
+
meterProvider.addMetricReader(metricReader);
|
|
78
|
+
|
|
79
|
+
// Register Meter Provider as global
|
|
80
|
+
metrics.setGlobalMeterProvider(meterProvider);
|
|
81
|
+
|
|
78
82
|
```
|
|
79
83
|
|
|
80
84
|
### Logs
|
|
81
85
|
|
|
82
|
-
|
|
86
|
+
Add the Log Exporter to your existing OpenTelemetry Logger Provider (`LoggerProvider`)
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
const { logs } = require("@opentelemetry/api-logs");
|
|
90
|
+
const { LoggerProvider, BatchLogRecordProcessor } = require("@opentelemetry/sdk-logs");
|
|
91
|
+
const { AzureMonitorLogExporter } = require("@azure/monitor-opentelemetry-exporter");
|
|
92
|
+
|
|
93
|
+
// Add the Log exporter into the logRecordProcessor and register it with the LoggerProvider
|
|
94
|
+
const exporter = new AzureMonitorLogExporter({
|
|
95
|
+
connectionString:
|
|
96
|
+
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
|
|
97
|
+
});
|
|
98
|
+
const logRecordProcessor = new BatchLogRecordProcessor(exporter);
|
|
99
|
+
const loggerProvider = new LoggerProvider();
|
|
100
|
+
loggerProvider.addLogRecordProcessor(logRecordProcessor);
|
|
101
|
+
|
|
102
|
+
// Register logger Provider as global
|
|
103
|
+
logs.setGlobalLoggerProvider(loggerProvider);
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
83
107
|
|
|
84
108
|
### Sampling
|
|
85
109
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
4
6
|
var api = require('@opentelemetry/api');
|
|
5
7
|
var core = require('@opentelemetry/core');
|
|
@@ -59,7 +61,7 @@ const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
59
61
|
* AzureMonitorTraceExporter version.
|
|
60
62
|
* @internal
|
|
61
63
|
*/
|
|
62
|
-
const packageVersion = "1.0.0-beta.
|
|
64
|
+
const packageVersion = "1.0.0-beta.18";
|
|
63
65
|
var DependencyTypes;
|
|
64
66
|
(function (DependencyTypes) {
|
|
65
67
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -1806,7 +1808,7 @@ class ApplicationInsightsClient extends coreClient__namespace.ServiceClient {
|
|
|
1806
1808
|
const defaults = {
|
|
1807
1809
|
requestContentType: "application/json; charset=utf-8"
|
|
1808
1810
|
};
|
|
1809
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
1811
|
+
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.18`;
|
|
1810
1812
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
1811
1813
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
1812
1814
|
: `${packageDetails}`;
|
|
@@ -1905,6 +1907,7 @@ const STATSBEAT_LANGUAGE = "node";
|
|
|
1905
1907
|
const MAX_STATSBEAT_FAILURES = 3;
|
|
1906
1908
|
const StatsbeatResourceProvider = {
|
|
1907
1909
|
appsvc: "appsvc",
|
|
1910
|
+
aks: "aks",
|
|
1908
1911
|
functions: "functions",
|
|
1909
1912
|
vm: "vm",
|
|
1910
1913
|
unknown: "unknown",
|
|
@@ -1941,8 +1944,8 @@ const EU_ENDPOINTS = [
|
|
|
1941
1944
|
];
|
|
1942
1945
|
var StatsbeatFeatureType;
|
|
1943
1946
|
(function (StatsbeatFeatureType) {
|
|
1944
|
-
StatsbeatFeatureType["FEATURE"] = "
|
|
1945
|
-
StatsbeatFeatureType["INSTRUMENTATION"] = "
|
|
1947
|
+
StatsbeatFeatureType[StatsbeatFeatureType["FEATURE"] = 0] = "FEATURE";
|
|
1948
|
+
StatsbeatFeatureType[StatsbeatFeatureType["INSTRUMENTATION"] = 1] = "INSTRUMENTATION";
|
|
1946
1949
|
})(StatsbeatFeatureType || (StatsbeatFeatureType = {}));
|
|
1947
1950
|
|
|
1948
1951
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -1958,13 +1961,25 @@ class StatsbeatMetrics {
|
|
|
1958
1961
|
async getResourceProvider() {
|
|
1959
1962
|
// Check resource provider
|
|
1960
1963
|
this.resourceProvider = StatsbeatResourceProvider.unknown;
|
|
1961
|
-
if (process.env.
|
|
1964
|
+
if (process.env.AKS_ARM_NAMESPACE_ID) {
|
|
1965
|
+
// AKS
|
|
1966
|
+
this.resourceProvider = StatsbeatResourceProvider.aks;
|
|
1967
|
+
this.resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;
|
|
1968
|
+
}
|
|
1969
|
+
else if (process.env.WEBSITE_SITE_NAME) {
|
|
1962
1970
|
// Web apps
|
|
1963
1971
|
this.resourceProvider = StatsbeatResourceProvider.appsvc;
|
|
1972
|
+
this.resourceIdentifier = process.env.WEBSITE_SITE_NAME;
|
|
1973
|
+
if (process.env.WEBSITE_HOME_STAMPNAME) {
|
|
1974
|
+
this.resourceIdentifier += "/" + process.env.WEBSITE_HOME_STAMPNAME;
|
|
1975
|
+
}
|
|
1964
1976
|
}
|
|
1965
1977
|
else if (process.env.FUNCTIONS_WORKER_RUNTIME) {
|
|
1966
1978
|
// Function apps
|
|
1967
1979
|
this.resourceProvider = StatsbeatResourceProvider.functions;
|
|
1980
|
+
if (process.env.WEBSITE_HOSTNAME) {
|
|
1981
|
+
this.resourceIdentifier = process.env.WEBSITE_HOSTNAME;
|
|
1982
|
+
}
|
|
1968
1983
|
}
|
|
1969
1984
|
else if (await this.getAzureComputeMetadata()) {
|
|
1970
1985
|
this.resourceProvider = StatsbeatResourceProvider.vm;
|
|
@@ -14,13 +14,25 @@ export class StatsbeatMetrics {
|
|
|
14
14
|
async getResourceProvider() {
|
|
15
15
|
// Check resource provider
|
|
16
16
|
this.resourceProvider = StatsbeatResourceProvider.unknown;
|
|
17
|
-
if (process.env.
|
|
17
|
+
if (process.env.AKS_ARM_NAMESPACE_ID) {
|
|
18
|
+
// AKS
|
|
19
|
+
this.resourceProvider = StatsbeatResourceProvider.aks;
|
|
20
|
+
this.resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;
|
|
21
|
+
}
|
|
22
|
+
else if (process.env.WEBSITE_SITE_NAME) {
|
|
18
23
|
// Web apps
|
|
19
24
|
this.resourceProvider = StatsbeatResourceProvider.appsvc;
|
|
25
|
+
this.resourceIdentifier = process.env.WEBSITE_SITE_NAME;
|
|
26
|
+
if (process.env.WEBSITE_HOME_STAMPNAME) {
|
|
27
|
+
this.resourceIdentifier += "/" + process.env.WEBSITE_HOME_STAMPNAME;
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
30
|
else if (process.env.FUNCTIONS_WORKER_RUNTIME) {
|
|
22
31
|
// Function apps
|
|
23
32
|
this.resourceProvider = StatsbeatResourceProvider.functions;
|
|
33
|
+
if (process.env.WEBSITE_HOSTNAME) {
|
|
34
|
+
this.resourceIdentifier = process.env.WEBSITE_HOSTNAME;
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
37
|
else if (await this.getAzureComputeMetadata()) {
|
|
26
38
|
this.resourceProvider = StatsbeatResourceProvider.vm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,EACxB,yBAAyB,GAE1B,MAAM,SAAS,CAAC;AAEjB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,MAAM,OAAO,gBAAgB;IAA7B;QACY,qBAAgB,GAAW,yBAAyB,CAAC,OAAO,CAAC;QAC7D,WAAM,GAAuB,EAAE,CAAC;QAChC,OAAE,GAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QACvB,uBAAkB,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"statsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,EACxB,yBAAyB,GAE1B,MAAM,SAAS,CAAC;AAEjB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,MAAM,OAAO,gBAAgB;IAA7B;QACY,qBAAgB,GAAW,yBAAyB,CAAC,OAAO,CAAC;QAC7D,WAAM,GAAuB,EAAE,CAAC;QAChC,OAAE,GAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QACvB,uBAAkB,GAAG,EAAE,CAAC;IAsFpC,CAAC;IApFW,KAAK,CAAC,mBAAmB;QACjC,0BAA0B;QAC1B,IAAI,CAAC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C,wBAAwB,EAAE,KAAK,CAAC,CAAC;qBAC7C;gBACH,CAAC,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;aACb;iBAAM;gBACL,OAAO,KAAK,CAAC;aACd;QACH,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACV,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IAES,mBAAmB,CAAC,WAAmB;QAC/C,MAAM,eAAe,GAAG,WAAW,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC7C,OAAO,oBAAoB,CAAC;aAC7B;SACF;QACD,OAAO,wBAAwB,CAAC;IAClC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n createDefaultHttpClient,\n createPipelineRequest,\n HttpMethods,\n} from \"@azure/core-rest-pipeline\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n AIMS_API_VERSION,\n AIMS_FORMAT,\n AIMS_URI,\n EU_CONNECTION_STRING,\n EU_ENDPOINTS,\n NON_EU_CONNECTION_STRING,\n StatsbeatResourceProvider,\n VirtualMachineInfo,\n} from \"./types\";\n\nconst os = require(\"os\");\n\nexport class StatsbeatMetrics {\n protected resourceProvider: string = StatsbeatResourceProvider.unknown;\n protected vmInfo: VirtualMachineInfo = {};\n protected os: string = os.type();\n protected resourceIdentifier = \"\";\n\n protected async getResourceProvider(): Promise<void> {\n // Check resource provider\n this.resourceProvider = StatsbeatResourceProvider.unknown;\n if (process.env.AKS_ARM_NAMESPACE_ID) {\n // AKS\n this.resourceProvider = StatsbeatResourceProvider.aks;\n this.resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;\n } else if (process.env.WEBSITE_SITE_NAME) {\n // Web apps\n this.resourceProvider = StatsbeatResourceProvider.appsvc;\n this.resourceIdentifier = process.env.WEBSITE_SITE_NAME;\n if (process.env.WEBSITE_HOME_STAMPNAME) {\n this.resourceIdentifier += \"/\" + process.env.WEBSITE_HOME_STAMPNAME;\n }\n } else if (process.env.FUNCTIONS_WORKER_RUNTIME) {\n // Function apps\n this.resourceProvider = StatsbeatResourceProvider.functions;\n if (process.env.WEBSITE_HOSTNAME) {\n this.resourceIdentifier = process.env.WEBSITE_HOSTNAME;\n }\n } else if (await this.getAzureComputeMetadata()) {\n this.resourceProvider = StatsbeatResourceProvider.vm;\n this.resourceIdentifier = this.vmInfo.id + \"/\" + this.vmInfo.subscriptionId;\n // Overrride OS as VM info have higher precedence\n if (this.vmInfo.osType) {\n this.os = this.vmInfo.osType;\n }\n } else {\n this.resourceProvider = StatsbeatResourceProvider.unknown;\n }\n }\n\n public async getAzureComputeMetadata(): Promise<boolean> {\n const httpClient = createDefaultHttpClient();\n const method: HttpMethods = \"GET\";\n\n const options = {\n url: `${AIMS_URI}?${AIMS_API_VERSION}&${AIMS_FORMAT}`,\n timeout: 5000, // 5 seconds\n method: method,\n allowInsecureConnection: true,\n };\n const request = createPipelineRequest(options);\n\n await httpClient\n .sendRequest(request)\n .then((res: any) => {\n if (res.status === 200) {\n // Success; VM\n this.vmInfo.isVM = true;\n let virtualMachineData = \"\";\n res.on(\"data\", (data: any) => {\n virtualMachineData += data;\n });\n res.on(\"end\", () => {\n try {\n const data = JSON.parse(virtualMachineData);\n this.vmInfo.id = data[\"vmId\"] || \"\";\n this.vmInfo.subscriptionId = data[\"subscriptionId\"] || \"\";\n this.vmInfo.osType = data[\"osType\"] || \"\";\n } catch (error) {\n diag.debug(\"Failed to parse JSON: \", error);\n }\n });\n return true;\n } else {\n return false;\n }\n })\n .catch(() => {\n return false;\n });\n return false;\n }\n\n protected getConnectionString(endpointUrl: string): string {\n const currentEndpoint = endpointUrl;\n for (let i = 0; i < EU_ENDPOINTS.length; i++) {\n if (currentEndpoint.includes(EU_ENDPOINTS[i])) {\n return EU_CONNECTION_STRING;\n }\n }\n return NON_EU_CONNECTION_STRING;\n }\n}\n"]}
|
|
@@ -21,6 +21,7 @@ export const STATSBEAT_LANGUAGE = "node";
|
|
|
21
21
|
export const MAX_STATSBEAT_FAILURES = 3;
|
|
22
22
|
export const StatsbeatResourceProvider = {
|
|
23
23
|
appsvc: "appsvc",
|
|
24
|
+
aks: "aks",
|
|
24
25
|
functions: "functions",
|
|
25
26
|
vm: "vm",
|
|
26
27
|
unknown: "unknown",
|
|
@@ -57,7 +58,7 @@ export const EU_ENDPOINTS = [
|
|
|
57
58
|
];
|
|
58
59
|
export var StatsbeatFeatureType;
|
|
59
60
|
(function (StatsbeatFeatureType) {
|
|
60
|
-
StatsbeatFeatureType["FEATURE"] = "
|
|
61
|
-
StatsbeatFeatureType["INSTRUMENTATION"] = "
|
|
61
|
+
StatsbeatFeatureType[StatsbeatFeatureType["FEATURE"] = 0] = "FEATURE";
|
|
62
|
+
StatsbeatFeatureType[StatsbeatFeatureType["INSTRUMENTATION"] = 1] = "INSTRUMENTATION";
|
|
62
63
|
})(StatsbeatFeatureType || (StatsbeatFeatureType = {}));
|
|
63
64
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,OAAO,gBAAgB;IA6B3B,YAAY,QAAgB,EAAE,IAAY;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,0BAA0B,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,EAAE,C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Y,gBAAgB;IAC1B,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,+CAA2B,CAAA;IAC3B,qDAAiC,CAAA;IACjC,uDAAmC,CAAA;IACnC,yDAAqC,CAAA;IACrC,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EATW,gBAAgB,KAAhB,gBAAgB,QAS3B;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,kDAAkD,CAAC;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,wBAAwB,GACnC,6HAA6H,CAAC;AAChI,MAAM,CAAC,MAAM,oBAAoB,GAC/B,iIAAiI,CAAC;AACpI,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,YAAY;IACZ,aAAa;IACb,eAAe;IACf,aAAa;IACb,oBAAoB;IACpB,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,SAAS;IACT,QAAQ;CACT,CAAC;AAmCF,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qEAAW,CAAA;IACX,qFAAmB,CAAA;AACrB,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport class NetworkStatsbeat {\n public time: number | undefined;\n\n public lastTime: number;\n\n public endpoint: string;\n\n public host: string;\n\n public totalRequestCount: number;\n\n public lastRequestCount: number;\n\n public totalSuccesfulRequestCount: number;\n\n public totalFailedRequestCount: { statusCode: number; count: number }[];\n\n public retryCount: { statusCode: number; count: number }[];\n\n public exceptionCount: { exceptionType: string; count: number }[];\n\n public throttleCount: { statusCode: number; count: number }[];\n\n public intervalRequestExecutionTime: number;\n\n public lastIntervalRequestExecutionTime: number;\n\n public averageRequestExecutionTime: number;\n\n constructor(endpoint: string, host: string) {\n this.endpoint = endpoint;\n this.host = host;\n this.totalRequestCount = 0;\n this.totalSuccesfulRequestCount = 0;\n this.totalFailedRequestCount = [];\n this.retryCount = [];\n this.exceptionCount = [];\n this.throttleCount = [];\n this.intervalRequestExecutionTime = 0;\n this.lastIntervalRequestExecutionTime = 0;\n this.lastTime = +new Date();\n this.lastRequestCount = 0;\n this.averageRequestExecutionTime = 0;\n }\n}\n\nexport const STATSBEAT_LANGUAGE = \"node\";\n\nexport const MAX_STATSBEAT_FAILURES = 3;\n\nexport const StatsbeatResourceProvider = {\n appsvc: \"appsvc\",\n aks: \"aks\",\n functions: \"functions\",\n vm: \"vm\",\n unknown: \"unknown\",\n};\n\nexport enum StatsbeatCounter {\n SUCCESS_COUNT = \"Request_Success_Count\",\n FAILURE_COUNT = \"Request_Failure_Count\",\n RETRY_COUNT = \"Retry_Count\",\n THROTTLE_COUNT = \"Throttle_Count\",\n EXCEPTION_COUNT = \"Exception_Count\",\n AVERAGE_DURATION = \"Request_Duration\",\n ATTACH = \"Attach\",\n FEATURE = \"Feature\",\n}\n\nexport const AIMS_URI = \"http://169.254.169.254/metadata/instance/compute\";\nexport const AIMS_API_VERSION = \"api-version=2017-12-01\";\nexport const AIMS_FORMAT = \"format=json\";\nexport const NON_EU_CONNECTION_STRING =\n \"InstrumentationKey=c4a29126-a7cb-47e5-b348-11414998b11e;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com\";\nexport const EU_CONNECTION_STRING =\n \"InstrumentationKey=7dc56bab-3c0c-4e9f-9ebb-d1acadee8d0f;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com\";\nexport const EU_ENDPOINTS = [\n \"westeurope\",\n \"northeurope\",\n \"francecentral\",\n \"francesouth\",\n \"germanywestcentral\",\n \"norwayeast\",\n \"norwaywest\",\n \"swedencentral\",\n \"switzerlandnorth\",\n \"switzerlandwest\",\n \"uksouth\",\n \"ukwest\",\n];\n\nexport interface CommonStatsbeatProperties {\n os: string;\n rp: string;\n cikey: string;\n runtimeVersion: string;\n language: string;\n version: string;\n attach: string;\n}\n\nexport interface AttachStatsbeatProperties {\n rpId: string;\n}\n\nexport interface NetworkStatsbeatProperties {\n endpoint: string;\n host: string;\n}\n\nexport interface StatsbeatOptions {\n instrumentationKey: string;\n endpointUrl: string;\n networkCollectionInterval?: number;\n longCollectionInterval?: number;\n}\n\nexport interface VirtualMachineInfo {\n isVM?: boolean;\n id?: string;\n subscriptionId?: string;\n osType?: string;\n}\n\nexport enum StatsbeatFeatureType {\n FEATURE = 0,\n INSTRUMENTATION = 1,\n}\n"]}
|
|
@@ -23,7 +23,7 @@ export class ApplicationInsightsClient extends coreClient.ServiceClient {
|
|
|
23
23
|
const defaults = {
|
|
24
24
|
requestContentType: "application/json; charset=utf-8"
|
|
25
25
|
};
|
|
26
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
26
|
+
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.18`;
|
|
27
27
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
28
28
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
29
29
|
: `${packageDetails}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAQ5C,MAAM,OAAO,yBAA0B,SAAQ,UAAU,CAAC,aAAa;IAGrE;;;OAGG;IACH,YAAY,OAAiD;;QAC3D,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd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yright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
1
|
+
{"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAQ5C,MAAM,OAAO,yBAA0B,SAAQ,UAAU,CAAC,aAAa;IAGrE;;;OAGG;IACH,YAAY,OAAiD;;QAC3D,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAA4C;YACxD,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,uDAAuD,CAAC;QAC/E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAA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OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,kBAAkB,CAAC,CAAC;IAC1E,CAAC;CACF;AACD,2BAA2B;AAC3B,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;AAE3E,MAAM,kBAAkB,GAA6B;IACnD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE;QACT,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;SAClC;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;SAClC;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;KACF;IACD,WAAW,EAAE,UAAU,CAAC,IAAI;IAC5B,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.18`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint ?? options.baseUri ?? \"{Host}/v2.1\"\n };\n super(optionsWithDefaults);\n\n if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {\n const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();\n const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(\n (pipelinePolicy) =>\n pipelinePolicy.name ===\n coreRestPipeline.bearerTokenAuthenticationPolicyName\n );\n if (!bearerTokenAuthenticationPolicyFound) {\n this.pipeline.removePolicy({\n name: coreRestPipeline.bearerTokenAuthenticationPolicyName\n });\n this.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n scopes: `${optionsWithDefaults.baseUri}/.default`,\n challengeCallbacks: {\n authorizeRequestOnChallenge:\n coreClient.authorizeRequestOnClaimChallenge\n }\n })\n );\n }\n }\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n\n /**\n * This operation sends a sequence of telemetry events that will be monitored by Azure Monitor.\n * @param body The list of telemetry events to track.\n * @param options The options parameters.\n */\n track(\n body: TelemetryItem[],\n options?: TrackOptionalParams\n ): Promise<TrackOperationResponse> {\n return this.sendOperationRequest({ body, options }, trackOperationSpec);\n }\n}\n// Operation Specifications\nconst serializer = coreClient.createSerializer(Mappers, /* isXml */ false);\n\nconst trackOperationSpec: coreClient.OperationSpec = {\n path: \"/track\",\n httpMethod: \"POST\",\n responses: {\n 200: {\n bodyMapper: Mappers.TrackResponse\n },\n 206: {\n bodyMapper: Mappers.TrackResponse\n },\n 400: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 402: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 429: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 500: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 503: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n }\n },\n requestBody: Parameters.body,\n urlParameters: [Parameters.host],\n headerParameters: [Parameters.contentType, Parameters.accept],\n mediaType: \"json\",\n serializer\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/baseSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,qDAAqD,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtE,MAAM,oCAAoC,GAAG,KAAM,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAgB,UA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AI,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.\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage, SenderResult } from \"../../types\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { FileSystemPersist } from \"./persist\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { NetworkStatsbeatMetrics } from \"../../export/statsbeat/networkStatsbeatMetrics\";\nimport { getInstance } from \"../../export/statsbeat/longIntervalStatsbeatMetrics\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { MAX_STATSBEAT_FAILURES } from \"../../export/statsbeat/types\";\nimport { BreezeResponse, isRetriable } from \"../../utils/breezeUtils\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n\n/**\n * Base sender class\n * @internal\n */\nexport abstract class BaseSender {\n private readonly persister: PersistentStorage;\n private numConsecutiveRedirects: number;\n private retryTimer: NodeJS.Timer | null;\n private networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private longIntervalStatsbeatMetrics;\n private statsbeatFailureCount: number = 0;\n private batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n\n constructor(options: {\n endpointUrl: string;\n instrumentationKey: string;\n trackStatsbeat: boolean;\n exporterOptions: AzureMonitorExporterOptions;\n aadAudience?: string;\n }) {\n this.numConsecutiveRedirects = 0;\n this.persister = new FileSystemPersist(options.instrumentationKey, options.exporterOptions);\n if (options.trackStatsbeat) {\n // Initialize statsbeatMetrics\n this.networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: options.instrumentationKey,\n endpointUrl: options.endpointUrl,\n });\n this.longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: options.instrumentationKey,\n endpointUrl: options.endpointUrl,\n });\n }\n this.retryTimer = null;\n }\n\n abstract send(payload: unknown[]): Promise<SenderResult>;\n abstract shutdown(): Promise<void>;\n abstract handlePermanentRedirect(location: string | undefined): void;\n\n /**\n * Export envelopes\n */\n public 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.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.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 const 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 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 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 /**\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 // Disable collection of statsbeat metrics after max failures\n private incrementStatsbeatFailure() {\n this.statsbeatFailureCount++;\n if (this.statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\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.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":"baseSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/baseSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,qDAAqD,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtE,MAAM,oCAAoC,GAAG,KAAM,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAgB,UAAU;IAS9B,YAAY,OAMX;QATO,0BAAqB,GAAW,CAAC,CAAC;QAClC,6BAAwB,GAAW,oCAAoC,CAAC;QAS9E,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,eAAe,CAA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AAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE;gBACpC,CAAC,CAAC;oBACE,IAAI,EAAE,gBAAgB,CAAC,MAAM;oBAC7B,KAAK,EAAE,IAAI,KAAK,CAAC,qCAAqC,CAAC;iBACxD,CAAC;SACP;QAAC,OAAO,EAAO,EAAE;YAChB,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;SACrD;IACH,CAAC;IAED,6DAA6D;IACrD,yBAAyB;;QAC/B,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,qBAAqB,GAAG,sBAAsB,EAAE;YACvD,MAAA,IAAI,CAAC,uBAAuB,0CAAE,QAAQ,EAAE,CAAC;YACzC,MAAA,IAAI,CAAC,4BAA4B,0CAAE,QAAQ,EAAE,CAAC;YAC9C,IAAI,CAAC,uBAAuB,GAAG,SAAS,CAAC;YACzC,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC;SAChC;IACH,CAAC;IAEO,KAAK,CAAC,sBAAsB;QAClC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAsB,CAAC;YACtE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC5B;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,cAAc,CAAC,KAAgB;QACrC,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.\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage, SenderResult } from \"../../types\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { FileSystemPersist } from \"./persist\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { NetworkStatsbeatMetrics } from \"../../export/statsbeat/networkStatsbeatMetrics\";\nimport { getInstance } from \"../../export/statsbeat/longIntervalStatsbeatMetrics\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { MAX_STATSBEAT_FAILURES } from \"../../export/statsbeat/types\";\nimport { BreezeResponse, isRetriable } from \"../../utils/breezeUtils\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n\n/**\n * Base sender class\n * @internal\n */\nexport abstract class BaseSender {\n private readonly persister: PersistentStorage;\n private numConsecutiveRedirects: number;\n private retryTimer: NodeJS.Timeout | null;\n private networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private longIntervalStatsbeatMetrics;\n private statsbeatFailureCount: number = 0;\n private batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n\n constructor(options: {\n endpointUrl: string;\n instrumentationKey: string;\n trackStatsbeat: boolean;\n exporterOptions: AzureMonitorExporterOptions;\n aadAudience?: string;\n }) {\n this.numConsecutiveRedirects = 0;\n this.persister = new FileSystemPersist(options.instrumentationKey, options.exporterOptions);\n if (options.trackStatsbeat) {\n // Initialize statsbeatMetrics\n this.networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: options.instrumentationKey,\n endpointUrl: options.endpointUrl,\n });\n this.longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: options.instrumentationKey,\n endpointUrl: options.endpointUrl,\n });\n }\n this.retryTimer = null;\n }\n\n abstract send(payload: unknown[]): Promise<SenderResult>;\n abstract shutdown(): Promise<void>;\n abstract handlePermanentRedirect(location: string | undefined): void;\n\n /**\n * Export envelopes\n */\n public 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.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.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 const 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 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 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 /**\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 // Disable collection of statsbeat metrics after max failures\n private incrementStatsbeatFailure() {\n this.statsbeatFailureCount++;\n if (this.statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\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.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"]}
|
|
@@ -10,7 +10,7 @@ let instance = null;
|
|
|
10
10
|
* Azure Telemetry context.
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
class Context {
|
|
13
|
+
export class Context {
|
|
14
14
|
constructor() {
|
|
15
15
|
this.tags = {};
|
|
16
16
|
this._loadDeviceContext();
|
|
@@ -37,7 +37,6 @@ class Context {
|
|
|
37
37
|
Context.sdkVersion = null;
|
|
38
38
|
Context.opentelemetryVersion = null;
|
|
39
39
|
Context.nodeVersion = "";
|
|
40
|
-
export { Context };
|
|
41
40
|
/**
|
|
42
41
|
* Singleton Context instance
|
|
43
42
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/context/context.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAGnE,IAAI,QAAQ,GAAmB,IAAI,CAAC;AAEpC;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/context/context.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,QAAQ,EAA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G,MAAM,OAAO,OAAO,CAAC,WAAW,QAAQ,OAAO,CAAC,oBAAoB,IAAI,OAAO,EAAE,CAAC;QAChH,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,GAAG,kBAAkB,CAAC;IAC3E,CAAC;;AA9Ba,kBAAU,GAAkB,IAAI,CAAC;AAEjC,4BAAoB,GAAkB,IAAI,CAAC;AAE3C,mBAAW,GAAW,EAAE,CAAC;AA6BzC;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;KAC1B;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as os from \"os\";\nimport { SDK_INFO } from \"@opentelemetry/core\";\nimport { SemanticResourceAttributes } from \"@opentelemetry/semantic-conventions\";\n\nimport { KnownContextTagKeys } from \"../../../generated\";\nimport * as ai from \"../../../utils/constants/applicationinsights\";\nimport { Tags } from \"../../../types\";\n\nlet instance: Context | null = null;\n\n/**\n * Azure Telemetry context.\n * @internal\n */\nexport class Context {\n public tags: Tags;\n\n public static sdkVersion: string | null = null;\n\n public static opentelemetryVersion: string | null = null;\n\n public static nodeVersion: string = \"\";\n\n constructor() {\n this.tags = {};\n this._loadDeviceContext();\n this._loadInternalContext();\n }\n\n private _loadDeviceContext(): void {\n this.tags[KnownContextTagKeys.AiDeviceOsVersion] = os && `${os.type()} ${os.release()}`;\n }\n\n private _loadInternalContext(): void {\n const { node } = process.versions;\n [Context.nodeVersion] = node.split(\".\");\n Context.opentelemetryVersion = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_VERSION];\n Context.sdkVersion = ai.packageVersion;\n\n const prefix = process.env[\"AZURE_MONITOR_AGENT_PREFIX\"]\n ? process.env[\"AZURE_MONITOR_AGENT_PREFIX\"]\n : \"\";\n const version = process.env[\"AZURE_MONITOR_DISTRO_VERSION\"]\n ? `dst${process.env[\"AZURE_MONITOR_DISTRO_VERSION\"]}`\n : `ext${Context.sdkVersion}`;\n const internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;\n this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;\n }\n}\n\n/**\n * Singleton Context instance\n * @internal\n */\nexport function getInstance(): Context {\n if (!instance) {\n instance = new Context();\n }\n return instance;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import * as fs from "fs";
|
|
|
4
4
|
import * as os from "os";
|
|
5
5
|
import * as child_process from "child_process";
|
|
6
6
|
import { diag } from "@opentelemetry/api";
|
|
7
|
-
class FileAccessControl {
|
|
7
|
+
export class FileAccessControl {
|
|
8
8
|
// Check if file access control could be enabled
|
|
9
9
|
static checkFileProtection() {
|
|
10
10
|
if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION &&
|
|
@@ -168,5 +168,4 @@ FileAccessControl.ACL_IDENTITY = null;
|
|
|
168
168
|
FileAccessControl.OS_FILE_PROTECTION_CHECKED = false;
|
|
169
169
|
FileAccessControl.OS_PROVIDES_FILE_PROTECTION = false;
|
|
170
170
|
FileAccessControl.USE_ICACLS = os.type() === "Windows_NT";
|
|
171
|
-
export { FileAccessControl };
|
|
172
171
|
//# sourceMappingURL=fileAccessControl.js.map
|
|
@@ -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,MAAa,iBAAiB;IAS5B,gDAAgD;IACzC,MAAM,CAAC,mBAAmB;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CAAC;SACvC;aAAM;YACL,MAAM,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;SAP3C,iBAAiB","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 const 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 const 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 const 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 const 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 const 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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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: 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 const 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 const 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 const 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 const 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 const 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"]}
|
|
@@ -16,7 +16,7 @@ const writeFileAsync = promisify(fs.writeFile);
|
|
|
16
16
|
* File system persist class.
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
class FileSystemPersist {
|
|
19
|
+
export class FileSystemPersist {
|
|
20
20
|
constructor(instrumentationKey, _options) {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
this._options = _options;
|
|
@@ -176,5 +176,4 @@ class FileSystemPersist {
|
|
|
176
176
|
}
|
|
177
177
|
FileSystemPersist.TEMPDIR_PREFIX = "ot-azure-exporter-";
|
|
178
178
|
FileSystemPersist.FILENAME_SUFFIX = ".ai.json";
|
|
179
|
-
export { FileSystemPersist };
|
|
180
179
|
//# sourceMappingURL=fileSystemPersist.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileSystemPersist.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileSystemPersist.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MA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iBACb;aACF;YACD,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,KAAU,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,yDAAyD,EAAE,KAAK,CAAC,CAAC;YAC5E,OAAO,KAAK,CAAC;SACd;IACH,CAAC;;AAnLM,gCAAc,GAAG,oBAAoB,AAAvB,CAAwB;AACtC,iCAAe,GAAG,UAAU,AAAb,CAAc;SAFzB,iBAAiB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as os from \"os\";\nimport * as path from \"path\";\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage } from \"../../../types\";\nimport { FileAccessControl } from \"./fileAccessControl\";\nimport { confirmDirExists, getShallowDirectorySize } from \"./fileSystemHelpers\";\nimport { promisify } from \"util\";\nimport { AzureMonitorExporterOptions } from \"../../../config\";\n\nconst statAsync = promisify(fs.stat);\nconst readdirAsync = promisify(fs.readdir);\nconst readFileAsync = promisify(fs.readFile);\nconst unlinkAsync = promisify(fs.unlink);\nconst writeFileAsync = promisify(fs.writeFile);\n\n/**\n * File system persist class.\n * @internal\n */\nexport class FileSystemPersist implements PersistentStorage {\n static TEMPDIR_PREFIX = \"ot-azure-exporter-\";\n static FILENAME_SUFFIX = \".ai.json\";\n\n fileRetemptionPeriod = 2 * 24 * 60 * 60 * 1000; // 2 days\n cleanupTimeOut = 60 * 60 * 1000; // 1 hour\n maxBytesOnDisk: number = 50_000_000; // ~50MB\n\n private _enabled: boolean;\n private _tempDirectory: string = \"\";\n private _fileCleanupTimer: NodeJS.Timer | null = null;\n private _instrumentationKey: string;\n\n constructor(instrumentationKey: string, private _options?: AzureMonitorExporterOptions) {\n this._instrumentationKey = instrumentationKey;\n if (this._options?.disableOfflineStorage) {\n this._enabled = false;\n return;\n }\n this._enabled = true;\n FileAccessControl.checkFileProtection();\n\n if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION) {\n this._enabled = false;\n diag.error(\n \"Sufficient file protection capabilities were not detected. Files will not be persisted\"\n );\n }\n\n if (!this._instrumentationKey) {\n this._enabled = false;\n diag.error(\n `No instrumentation key was provided to FileSystemPersister. Files will not be persisted`\n );\n }\n if (this._enabled) {\n this._tempDirectory = path.join(\n this._options?.storageDirectory || os.tmpdir(),\n \"Microsoft\",\n \"AzureMonitor\",\n FileSystemPersist.TEMPDIR_PREFIX + this._instrumentationKey\n );\n\n // Starts file cleanup task\n if (!this._fileCleanupTimer) {\n this._fileCleanupTimer = setTimeout(() => {\n this._fileCleanupTask();\n }, this.cleanupTimeOut);\n this._fileCleanupTimer.unref();\n }\n }\n }\n\n push(value: unknown[]): Promise<boolean> {\n if (this._enabled) {\n diag.debug(\"Pushing value to persistent storage\", value.toString());\n return this._storeToDisk(JSON.stringify(value));\n }\n return new Promise((resolve) => {\n resolve(false);\n });\n }\n\n async shift(): Promise<unknown> {\n if (this._enabled) {\n diag.debug(\"Searching for filesystem persisted files\");\n try {\n const buffer = await this._getFirstFileOnDisk();\n if (buffer) {\n return JSON.parse(buffer.toString(\"utf8\"));\n }\n } catch (e: any) {\n diag.debug(\"Failed to read persisted file\", e);\n }\n return null;\n }\n return new Promise((resolve) => {\n resolve(null);\n });\n }\n\n /**\n * Check for temp telemetry files\n * reads the first file if exist, deletes it and tries to send its load\n */\n private async _getFirstFileOnDisk(): Promise<Buffer | null> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX)\n );\n if (files.length === 0) {\n return null;\n } else {\n const firstFile = files[0];\n const filePath = path.join(this._tempDirectory, firstFile);\n const payload = await readFileAsync(filePath);\n // delete the file first to prevent double sending\n await unlinkAsync(filePath);\n return payload;\n }\n }\n return null;\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n // File does not exist -- return null instead of throwing\n return null;\n } else {\n throw e;\n }\n }\n }\n\n private async _storeToDisk(payload: string): Promise<boolean> {\n try {\n await confirmDirExists(this._tempDirectory);\n } catch (error: any) {\n diag.warn(`Error while checking/creating directory: `, error && error.message);\n return false;\n }\n\n try {\n const size = await getShallowDirectorySize(this._tempDirectory);\n if (size > this.maxBytesOnDisk) {\n diag.warn(\n `Not saving data due to max size limit being met. Directory size in bytes is: ${size}`\n );\n return false;\n }\n } catch (error: any) {\n diag.warn(`Error while checking size of persistence directory: `, error && error.message);\n return false;\n }\n\n const fileName = `${new Date().getTime()}${FileSystemPersist.FILENAME_SUFFIX}`;\n const fileFullPath = path.join(this._tempDirectory, fileName);\n\n // Mode 600 is w/r for creator and no read access for others\n diag.info(`saving data to disk at: ${fileFullPath}`);\n try {\n await writeFileAsync(fileFullPath, payload, { mode: 0o600 });\n } catch (writeError: any) {\n diag.warn(`Error writing file to persistent file storage`, writeError);\n return false;\n }\n return true;\n }\n\n private async _fileCleanupTask(): Promise<boolean> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX)\n );\n if (files.length === 0) {\n return false;\n } else {\n files.forEach(async (file) => {\n // Check expiration\n const fileCreationDate: Date = new Date(\n parseInt(file.split(FileSystemPersist.FILENAME_SUFFIX)[0])\n );\n const expired = new Date(+new Date() - this.fileRetemptionPeriod) > fileCreationDate;\n if (expired) {\n const filePath = path.join(this._tempDirectory, file);\n await unlinkAsync(filePath);\n }\n });\n return true;\n }\n }\n return false;\n } catch (error: any) {\n diag.info(`Failed cleanup of persistent file storage expired files`, error);\n return false;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fileSystemPersist.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileSystemPersist.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO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CAAC;yBAC7B;oBACH,CAAC,CAAC,CAAC;oBACH,OAAO,IAAI,CAAC;iBACb;aACF;YACD,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,KAAU,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,yDAAyD,EAAE,KAAK,CAAC,CAAC;YAC5E,OAAO,KAAK,CAAC;SACd;IACH,CAAC;;AAnLM,gCAAc,GAAG,oBAAoB,AAAvB,CAAwB;AACtC,iCAAe,GAAG,UAAU,AAAb,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 path from \"path\";\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage } from \"../../../types\";\nimport { FileAccessControl } from \"./fileAccessControl\";\nimport { confirmDirExists, getShallowDirectorySize } from \"./fileSystemHelpers\";\nimport { promisify } from \"util\";\nimport { AzureMonitorExporterOptions } from \"../../../config\";\n\nconst statAsync = promisify(fs.stat);\nconst readdirAsync = promisify(fs.readdir);\nconst readFileAsync = promisify(fs.readFile);\nconst unlinkAsync = promisify(fs.unlink);\nconst writeFileAsync = promisify(fs.writeFile);\n\n/**\n * File system persist class.\n * @internal\n */\nexport class FileSystemPersist implements PersistentStorage {\n static TEMPDIR_PREFIX = \"ot-azure-exporter-\";\n static FILENAME_SUFFIX = \".ai.json\";\n\n fileRetemptionPeriod = 2 * 24 * 60 * 60 * 1000; // 2 days\n cleanupTimeOut = 60 * 60 * 1000; // 1 hour\n maxBytesOnDisk: number = 50_000_000; // ~50MB\n\n private _enabled: boolean;\n private _tempDirectory: string = \"\";\n private _fileCleanupTimer: NodeJS.Timeout | null = null;\n private _instrumentationKey: string;\n\n constructor(instrumentationKey: string, private _options?: AzureMonitorExporterOptions) {\n this._instrumentationKey = instrumentationKey;\n if (this._options?.disableOfflineStorage) {\n this._enabled = false;\n return;\n }\n this._enabled = true;\n FileAccessControl.checkFileProtection();\n\n if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION) {\n this._enabled = false;\n diag.error(\n \"Sufficient file protection capabilities were not detected. Files will not be persisted\"\n );\n }\n\n if (!this._instrumentationKey) {\n this._enabled = false;\n diag.error(\n `No instrumentation key was provided to FileSystemPersister. Files will not be persisted`\n );\n }\n if (this._enabled) {\n this._tempDirectory = path.join(\n this._options?.storageDirectory || os.tmpdir(),\n \"Microsoft\",\n \"AzureMonitor\",\n FileSystemPersist.TEMPDIR_PREFIX + this._instrumentationKey\n );\n\n // Starts file cleanup task\n if (!this._fileCleanupTimer) {\n this._fileCleanupTimer = setTimeout(() => {\n this._fileCleanupTask();\n }, this.cleanupTimeOut);\n this._fileCleanupTimer.unref();\n }\n }\n }\n\n push(value: unknown[]): Promise<boolean> {\n if (this._enabled) {\n diag.debug(\"Pushing value to persistent storage\", value.toString());\n return this._storeToDisk(JSON.stringify(value));\n }\n return new Promise((resolve) => {\n resolve(false);\n });\n }\n\n async shift(): Promise<unknown> {\n if (this._enabled) {\n diag.debug(\"Searching for filesystem persisted files\");\n try {\n const buffer = await this._getFirstFileOnDisk();\n if (buffer) {\n return JSON.parse(buffer.toString(\"utf8\"));\n }\n } catch (e: any) {\n diag.debug(\"Failed to read persisted file\", e);\n }\n return null;\n }\n return new Promise((resolve) => {\n resolve(null);\n });\n }\n\n /**\n * Check for temp telemetry files\n * reads the first file if exist, deletes it and tries to send its load\n */\n private async _getFirstFileOnDisk(): Promise<Buffer | null> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX)\n );\n if (files.length === 0) {\n return null;\n } else {\n const firstFile = files[0];\n const filePath = path.join(this._tempDirectory, firstFile);\n const payload = await readFileAsync(filePath);\n // delete the file first to prevent double sending\n await unlinkAsync(filePath);\n return payload;\n }\n }\n return null;\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n // File does not exist -- return null instead of throwing\n return null;\n } else {\n throw e;\n }\n }\n }\n\n private async _storeToDisk(payload: string): Promise<boolean> {\n try {\n await confirmDirExists(this._tempDirectory);\n } catch (error: any) {\n diag.warn(`Error while checking/creating directory: `, error && error.message);\n return false;\n }\n\n try {\n const size = await getShallowDirectorySize(this._tempDirectory);\n if (size > this.maxBytesOnDisk) {\n diag.warn(\n `Not saving data due to max size limit being met. Directory size in bytes is: ${size}`\n );\n return false;\n }\n } catch (error: any) {\n diag.warn(`Error while checking size of persistence directory: `, error && error.message);\n return false;\n }\n\n const fileName = `${new Date().getTime()}${FileSystemPersist.FILENAME_SUFFIX}`;\n const fileFullPath = path.join(this._tempDirectory, fileName);\n\n // Mode 600 is w/r for creator and no read access for others\n diag.info(`saving data to disk at: ${fileFullPath}`);\n try {\n await writeFileAsync(fileFullPath, payload, { mode: 0o600 });\n } catch (writeError: any) {\n diag.warn(`Error writing file to persistent file storage`, writeError);\n return false;\n }\n return true;\n }\n\n private async _fileCleanupTask(): Promise<boolean> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX)\n );\n if (files.length === 0) {\n return false;\n } else {\n files.forEach(async (file) => {\n // Check expiration\n const fileCreationDate: Date = new Date(\n parseInt(file.split(FileSystemPersist.FILENAME_SUFFIX)[0])\n );\n const expired = new Date(+new Date() - this.fileRetemptionPeriod) > fileCreationDate;\n if (expired) {\n const filePath = path.join(this._tempDirectory, file);\n await unlinkAsync(filePath);\n }\n });\n return true;\n }\n }\n return false;\n } catch (error: any) {\n diag.info(`Failed cleanup of persistent file storage expired files`, error);\n return false;\n }\n }\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import * as Constants from "../Declarations/Constants";
|
|
|
6
6
|
* ConnectionString parser.
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
class ConnectionStringParser {
|
|
9
|
+
export class ConnectionStringParser {
|
|
10
10
|
static parse(connectionString) {
|
|
11
11
|
if (!connectionString) {
|
|
12
12
|
return {};
|
|
@@ -75,5 +75,4 @@ class ConnectionStringParser {
|
|
|
75
75
|
}
|
|
76
76
|
ConnectionStringParser.FIELDS_SEPARATOR = ";";
|
|
77
77
|
ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR = "=";
|
|
78
|
-
export { ConnectionStringParser };
|
|
79
78
|
//# sourceMappingURL=connectionStringParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IAK1B,MAAM,CAAC,KAAK,CAAC,gBAAyB;QAC3C,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO,EAAE,CAAC;SACX;QAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,KAAK,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;QAChF,IAAI,OAAO,GAAG,IAAI,CAAC;QAEnB,MAAM,MAAM,GAAqB,OAAO,CAAC,MAAM,CAAC,CAAC,MAAwB,EAAE,EAAU,EAAE,EAAE;YACvF,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,CAAC;YAE3E,IAA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I,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;;AArFuB,uCAAgB,GAAG,GAAG,CAAC;AAEvB,gDAAyB,GAAG,GAAG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ConnectionString, ConnectionStringKey } from \"../Declarations/Contracts\";\n\nimport * as Constants from \"../Declarations/Constants\";\n\n/**\n * ConnectionString parser.\n * @internal\n */\nexport class ConnectionStringParser {\n private static readonly FIELDS_SEPARATOR = \";\";\n\n private static readonly FIELD_KEY_VALUE_SEPARATOR = \"=\";\n\n public static parse(connectionString?: string): ConnectionString {\n if (!connectionString) {\n return {};\n }\n\n const kvPairs = connectionString.split(ConnectionStringParser.FIELDS_SEPARATOR);\n let isValid = true;\n\n const result: ConnectionString = kvPairs.reduce((fields: ConnectionString, kv: string) => {\n const kvParts = kv.split(ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR);\n\n if (kvParts.length === 2) {\n // only save fields with valid formats\n const key = kvParts[0].toLowerCase() as ConnectionStringKey;\n const value = kvParts[1];\n return { ...fields, [key]: value };\n }\n diag.error(\n `Connection string key-value pair is invalid: ${kv}`,\n `Entire connection string will be discarded`,\n connectionString\n );\n isValid = false;\n return fields;\n }, {});\n\n if (isValid && Object.keys(result).length > 0) {\n // this is a valid connection string, so parse the results\n\n if (result.endpointsuffix) {\n // use endpoint suffix where overrides are not provided\n const locationPrefix = result.location ? `${result.location}.` : \"\";\n result.ingestionendpoint =\n result.ingestionendpoint || `https://${locationPrefix}dc.${result.endpointsuffix}`;\n result.liveendpoint =\n result.liveendpoint || `https://${locationPrefix}live.${result.endpointsuffix}`;\n }\n\n result.ingestionendpoint = result.ingestionendpoint\n ? ConnectionStringParser.sanitizeUrl(result.ingestionendpoint)\n : Constants.DEFAULT_BREEZE_ENDPOINT;\n result.liveendpoint = result.liveendpoint\n ? ConnectionStringParser.sanitizeUrl(result.liveendpoint)\n : Constants.DEFAULT_LIVEMETRICS_ENDPOINT;\n if (result.authorization && result.authorization.toLowerCase() !== \"ikey\") {\n diag.warn(\n `Connection String contains an unsupported 'Authorization' value: ${result.authorization!}. Defaulting to 'Authorization=ikey'. Instrumentation Key ${result.instrumentationkey!}`\n );\n }\n } else {\n diag.error(\n \"An invalid connection string was passed in. There may be telemetry loss\",\n connectionString\n );\n }\n\n return result;\n }\n\n public static sanitizeUrl(url: string) {\n let newUrl = url.trim();\n if (newUrl.indexOf(\"https://\") < 0) {\n // Try to update http to https\n newUrl = newUrl.replace(\"http://\", \"https://\");\n }\n // Remove final slash if present\n if (newUrl[newUrl.length - 1] === \"/\") {\n newUrl = newUrl.slice(0, -1);\n }\n return newUrl;\n }\n\n public static validateInstrumentationKey(iKey: string): boolean {\n if (iKey.startsWith(\"InstrumentationKey=\")) {\n const startIndex = iKey.indexOf(\"InstrumentationKey=\") + \"InstrumentationKey=\".length;\n const endIndex = iKey.indexOf(\";\", startIndex);\n iKey = iKey.substring(startIndex, endIndex);\n }\n const UUID_Regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$\";\n const regexp = new RegExp(UUID_Regex);\n return regexp.test(iKey);\n }\n}\n"]}
|
|
@@ -19,7 +19,7 @@ export const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
19
19
|
* AzureMonitorTraceExporter version.
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
export const packageVersion = "1.0.0-beta.
|
|
22
|
+
export const packageVersion = "1.0.0-beta.18";
|
|
23
23
|
export var DependencyTypes;
|
|
24
24
|
(function (DependencyTypes) {
|
|
25
25
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;AACf,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAE1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,uCAAuC,CAAC;AACtF,MAAM,CAAC,MAAM,gCAAgC,GAAG,yCAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,+BAA+B,GAAG,wCAAwC,CAAC;AACxF,MAAM,CAAC,MAAM,mCAAmC,GAAG,4CAA4C,CAAC;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,kCAAkC,GAAG,aAAa,CAAC;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,eAAe,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,uCAAuC,GAAG,kBAAkB,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * AI MS Links.\n * @internal\n */\nexport const MS_LINKS = \"_MS.links\";\n/**\n * AI enqueued time attribute.\n * @internal\n */\nexport const ENQUEUED_TIME = \"enqueuedTime\";\n/**\n * AI time since enqueued attribute.\n * @internal\n */\nexport const TIME_SINCE_ENQUEUED = \"timeSinceEnqueued\";\n/**\n * AzureMonitorTraceExporter version.\n * @internal\n */\nexport const packageVersion = \"1.0.0-beta.
|
|
1
|
+
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;AACf,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAE1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,uCAAuC,CAAC;AACtF,MAAM,CAAC,MAAM,gCAAgC,GAAG,yCAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,+BAA+B,GAAG,wCAAwC,CAAC;AACxF,MAAM,CAAC,MAAM,mCAAmC,GAAG,4CAA4C,CAAC;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,kCAAkC,GAAG,aAAa,CAAC;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,eAAe,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,uCAAuC,GAAG,kBAAkB,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * AI MS Links.\n * @internal\n */\nexport const MS_LINKS = \"_MS.links\";\n/**\n * AI enqueued time attribute.\n * @internal\n */\nexport const ENQUEUED_TIME = \"enqueuedTime\";\n/**\n * AI time since enqueued attribute.\n * @internal\n */\nexport const TIME_SINCE_ENQUEUED = \"timeSinceEnqueued\";\n/**\n * AzureMonitorTraceExporter version.\n * @internal\n */\nexport const packageVersion = \"1.0.0-beta.18\";\n\nexport enum DependencyTypes {\n InProc = \"InProc\",\n QueueMessage = \"Queue Message\",\n Sql = \"SQL\",\n Http = \"Http\",\n Grpc = \"GRPC\",\n}\n\nexport const AzureMonitorSampleRate = \"_MS.sampleRate\";\nexport const ApplicationInsightsBaseType = \"_MS.baseType\";\n\nexport const ApplicationInsightsMessageName = \"Microsoft.ApplicationInsights.Message\";\nexport const ApplicationInsightsExceptionName = \"Microsoft.ApplicationInsights.Exception\";\nexport const ApplicationInsightsPageViewName = \"Microsoft.ApplicationInsights.PageView\";\nexport const ApplicationInsightsAvailabilityName = \"Microsoft.ApplicationInsights.Availability\";\nexport const ApplicationInsightsEventName = \"Microsoft.ApplicationInsights.Event\";\n\nexport const ApplicationInsightsMessageBaseType = \"MessageData\";\nexport const ApplicationInsightsExceptionBaseType = \"ExceptionData\";\nexport const ApplicationInsightsPageViewBaseType = \"PageViewData\";\nexport const ApplicationInsightsAvailabilityBaseType = \"AvailabilityData\";\nexport const ApplicationInsightsEventBaseType = \"EventData\";\n"]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@azure/monitor-opentelemetry-exporter",
|
|
3
3
|
"author": "Microsoft Corporation",
|
|
4
4
|
"sdk-type": "client",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.18",
|
|
6
6
|
"description": "Application Insights exporter for the OpenTelemetry JavaScript (Node.js) SDK",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist-esm/src/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"pack": "npm pack 2>&1"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"dist-esm/src/",
|
|
@@ -85,37 +85,37 @@
|
|
|
85
85
|
"@azure/dev-tool": "^1.0.0",
|
|
86
86
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
87
87
|
"@microsoft/api-extractor": "^7.31.1",
|
|
88
|
-
"@opentelemetry/instrumentation": "^0.
|
|
89
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
90
|
-
"@opentelemetry/sdk-trace-node": "^1.
|
|
88
|
+
"@opentelemetry/instrumentation": "^0.45.0",
|
|
89
|
+
"@opentelemetry/instrumentation-http": "^0.45.0",
|
|
90
|
+
"@opentelemetry/sdk-trace-node": "^1.18.0",
|
|
91
91
|
"@types/mocha": "^10.0.0",
|
|
92
|
-
"@types/node": "^
|
|
92
|
+
"@types/node": "^18.0.0",
|
|
93
93
|
"dotenv": "^16.0.0",
|
|
94
94
|
"eslint": "^8.0.0",
|
|
95
95
|
"eslint-plugin-node": "^11.1.0",
|
|
96
96
|
"esm": "^3.2.18",
|
|
97
97
|
"mocha": "^10.0.0",
|
|
98
98
|
"nock": "^12.0.3",
|
|
99
|
-
"
|
|
99
|
+
"c8": "^8.0.0",
|
|
100
100
|
"prettier": "^2.5.1",
|
|
101
101
|
"rimraf": "^3.0.0",
|
|
102
|
-
"sinon": "^
|
|
102
|
+
"sinon": "^17.0.0",
|
|
103
103
|
"ts-node": "^10.0.0",
|
|
104
|
-
"typescript": "~5.
|
|
104
|
+
"typescript": "~5.2.0",
|
|
105
105
|
"cross-env": "^7.0.2"
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
108
|
"@azure/core-client": "^1.0.0",
|
|
109
109
|
"@azure/core-auth": "^1.3.0",
|
|
110
110
|
"@azure/core-rest-pipeline": "^1.1.0",
|
|
111
|
-
"@opentelemetry/api": "^1.
|
|
112
|
-
"@opentelemetry/api-logs": "^0.
|
|
113
|
-
"@opentelemetry/core": "^1.
|
|
114
|
-
"@opentelemetry/resources": "^1.
|
|
115
|
-
"@opentelemetry/sdk-metrics": "^1.
|
|
116
|
-
"@opentelemetry/sdk-trace-base": "^1.
|
|
117
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
118
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
111
|
+
"@opentelemetry/api": "^1.7.0",
|
|
112
|
+
"@opentelemetry/api-logs": "^0.45.0",
|
|
113
|
+
"@opentelemetry/core": "^1.18.0",
|
|
114
|
+
"@opentelemetry/resources": "^1.18.0",
|
|
115
|
+
"@opentelemetry/sdk-metrics": "^1.18.0",
|
|
116
|
+
"@opentelemetry/sdk-trace-base": "^1.18.0",
|
|
117
|
+
"@opentelemetry/semantic-conventions": "^1.18.0",
|
|
118
|
+
"@opentelemetry/sdk-logs": "^0.45.0",
|
|
119
119
|
"tslib": "^2.2.0"
|
|
120
120
|
},
|
|
121
121
|
"sideEffects": false,
|