@azure/monitor-opentelemetry 1.19.0 → 1.20.0
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 +7 -3
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +4 -13
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/logs/handler.d.ts.map +1 -1
- package/dist/commonjs/logs/handler.js +4 -3
- package/dist/commonjs/logs/handler.js.map +1 -1
- package/dist/commonjs/metrics/performanceCounters.d.ts +3 -0
- package/dist/commonjs/metrics/performanceCounters.d.ts.map +1 -1
- package/dist/commonjs/metrics/performanceCounters.js +26 -26
- package/dist/commonjs/metrics/performanceCounters.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.js +8 -7
- package/dist/commonjs/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/commonjs/package.json +6 -1
- package/dist/commonjs/shared/config.d.ts +7 -0
- package/dist/commonjs/shared/config.d.ts.map +1 -1
- package/dist/commonjs/shared/config.js +27 -6
- package/dist/commonjs/shared/config.js.map +1 -1
- package/dist/commonjs/traces/handler.d.ts.map +1 -1
- package/dist/commonjs/traces/handler.js +1 -7
- package/dist/commonjs/traces/handler.js.map +1 -1
- package/dist/commonjs/traces/sampler.js +1 -1
- package/dist/commonjs/traces/sampler.js.map +1 -1
- package/dist/commonjs/types.d.ts +11 -2
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +1 -1
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/utils/common.d.ts +24 -0
- package/dist/commonjs/utils/common.d.ts.map +1 -1
- package/dist/commonjs/utils/common.js +47 -0
- package/dist/commonjs/utils/common.js.map +1 -1
- package/dist/commonjs/utils/statsbeat.d.ts.map +1 -1
- package/dist/commonjs/utils/statsbeat.js +3 -1
- package/dist/commonjs/utils/statsbeat.js.map +1 -1
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logs/handler.d.ts.map +1 -1
- package/dist/esm/logs/handler.js +4 -3
- package/dist/esm/logs/handler.js.map +1 -1
- package/dist/esm/metrics/performanceCounters.d.ts +3 -0
- package/dist/esm/metrics/performanceCounters.d.ts.map +1 -1
- package/dist/esm/metrics/performanceCounters.js +26 -26
- package/dist/esm/metrics/performanceCounters.js.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.js +8 -7
- package/dist/esm/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/esm/package.json +6 -1
- package/dist/esm/shared/config.d.ts +7 -0
- package/dist/esm/shared/config.d.ts.map +1 -1
- package/dist/esm/shared/config.js +28 -7
- package/dist/esm/shared/config.js.map +1 -1
- package/dist/esm/traces/handler.d.ts.map +1 -1
- package/dist/esm/traces/handler.js +1 -7
- package/dist/esm/traces/handler.js.map +1 -1
- package/dist/esm/traces/sampler.js +1 -1
- package/dist/esm/traces/sampler.js.map +1 -1
- package/dist/esm/types.d.ts +11 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/common.d.ts +24 -0
- package/dist/esm/utils/common.d.ts.map +1 -1
- package/dist/esm/utils/common.js +45 -0
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/statsbeat.d.ts.map +1 -1
- package/dist/esm/utils/statsbeat.js +4 -2
- package/dist/esm/utils/statsbeat.js.map +1 -1
- package/package.json +28 -28
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ useAzureMonitor(options);
|
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
- Connection String can be set via `APPLICATIONINSIGHTS_CONNECTION_STRING`.
|
|
43
|
+
- Batch span processing can be configured with the standard OpenTelemetry environment variables `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`, `OTEL_BSP_SCHEDULE_DELAY`, and `OTEL_BSP_EXPORT_TIMEOUT`.
|
|
43
44
|
- Sampler can be set via the OpenTelemetry env vars `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG` (takes precedence over the `samplingRatio` option). Supported sampler values: `microsoft.rate_limited`, `microsoft.fixed_percentage`, `always_on`, `always_off`, `trace_id_ratio`, `parentbased_always_on`, `parentbased_always_off`, `parentbased_trace_id_ratio`. For `microsoft.rate_limited`, the arg is spans per second; for `trace_id_ratio`/parentbased, the arg is a probability in [0,1]. When the arg is omitted, defaults apply (rate limit disabled; probability defaults to 1). See the upstream OpenTelemetry environment variable spec for full context: https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/.
|
|
44
45
|
- To use the **fixed percentage sampler** (instead of the default rate-limited sampler), you can either:
|
|
45
46
|
- Set the environment variable `OTEL_TRACES_SAMPLER=microsoft.fixed_percentage` with an optional `OTEL_TRACES_SAMPLER_ARG` for the sampling probability (e.g., `0.5` for 50%).
|
|
@@ -86,6 +87,7 @@ For CommonJS applications, no additional flags are needed - the loader is automa
|
|
|
86
87
|
```ts snippet:ReadmeSampleConfiguration
|
|
87
88
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
88
89
|
import { AzureMonitorOpenTelemetryOptions, useAzureMonitor } from "@azure/monitor-opentelemetry";
|
|
90
|
+
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
89
91
|
|
|
90
92
|
const resource = resourceFromAttributes({ testAttribute: "testValue" });
|
|
91
93
|
const options: AzureMonitorOpenTelemetryOptions = {
|
|
@@ -111,8 +113,10 @@ const options: AzureMonitorOpenTelemetryOptions = {
|
|
|
111
113
|
// Instrumentations generating logs
|
|
112
114
|
bunyan: { enabled: true },
|
|
113
115
|
winston: { enabled: true },
|
|
114
|
-
// Console log collection is opt-in (disabled by default)
|
|
115
|
-
|
|
116
|
+
// Console log collection is opt-in (disabled by default).
|
|
117
|
+
// `logSeverity` takes precedence over the
|
|
118
|
+
// APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL environment variable.
|
|
119
|
+
console: { enabled: false, logSeverity: SeverityNumber.WARN },
|
|
116
120
|
},
|
|
117
121
|
enableLiveMetrics: true,
|
|
118
122
|
enableStandardMetrics: true,
|
|
@@ -278,7 +282,7 @@ The following OpenTelemetry Instrumentation libraries are included as part of Az
|
|
|
278
282
|
|
|
279
283
|
- [Console](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-console) (disabled by default; enable with `instrumentationOptions: { console: { enabled: true } }`)
|
|
280
284
|
|
|
281
|
-
Once enabled, the set of `console` methods collected is filtered by the `APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL` environment variable (`NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `VERBOSE`, `ALL`; see [Self-diagnostics](#self-diagnostics)). For example, `WARN` collects only `console.warn` and `console.error`, while `NONE` disables collection of `console` (and all other) logs entirely.
|
|
285
|
+
Once enabled, the set of `console` methods collected is filtered by the `logSeverity` value on the `console` instrumentation options, falling back to the `APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL` environment variable (`NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `VERBOSE`, `ALL`; see [Self-diagnostics](#self-diagnostics)) when `logSeverity` is not set. For example, `WARN` collects only `console.warn` and `console.error`, while `NONE` disables collection of `console` (and all other) logs entirely.
|
|
282
286
|
|
|
283
287
|
Other OpenTelemetry Instrumentations are available [here](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages) and could be added using TracerProvider in AzureMonitorOpenTelemetryClient.
|
|
284
288
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserSdkLoaderHelper.d.ts","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoaderHelper.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,oBAAY,qBAAqB;IAC/B,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,EAAE,OAAO;CACV;AAGD,eAAO,MAAM,mBAAmB,UAS/B,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAO,OAGpC,CAAC;AAEF,eAAO,MAAM,SAAS,gCAAuB,CAAC;AAC9C,eAAO,MAAM,WAAW,kCAAyB,CAAC;AAClD,eAAO,MAAM,YAAY,mCAA0B,CAAC;AACpD,eAAO,MAAM,YAAY,mCAA0B,CAAC;AAGpD,eAAO,MAAM,sBAAsB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAMnE,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAOlE,CAAC;AAGF,eAAO,MAAM,wBAAwB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAMrE,CAAC;AAGF,eAAO,MAAM,uBAAuB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAOpE,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,GAAG,IAStE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,IAShE,CAAC;AAEF,eAAO,MAAM,0BAA0B,G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IAShE,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,gBAAgB,MAAM,KACrB,qBAAqB,GAAG,IAe1B,CAAC;AAIF,eAAO,MAAM,6BAA6B,GACxC,UAAU,IAAI,CAAC,cAAc,KAC5B,qBAAqB,EAAE,GAAG,IAW5B,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,OAAO,MAAM,EACb,MAAM,MAAM,EACZ,SAAS,MAAM,KACd,MAAM,GAAG,IAMX,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,UAAU,IAAI,CAAC,cAAc,KAAG,OAWvE,CAAC"}
|
|
@@ -130,10 +130,9 @@ exports.getContentEncodingFromHeaders = getContentEncodingFromHeaders;
|
|
|
130
130
|
const insertBrowserSdkLoaderByIndex = (index, html, snippet) => {
|
|
131
131
|
if (index < 0)
|
|
132
132
|
return null;
|
|
133
|
-
let newHtml = null;
|
|
134
133
|
const subStart = html.substring(0, index);
|
|
135
134
|
const subEnd = html.substring(index);
|
|
136
|
-
newHtml = subStart + '<script type="text/javascript">' + snippet + "</script>" + subEnd;
|
|
135
|
+
const newHtml = subStart + '<script type="text/javascript">' + snippet + "</script>" + subEnd;
|
|
137
136
|
return newHtml;
|
|
138
137
|
};
|
|
139
138
|
exports.insertBrowserSdkLoaderByIndex = insertBrowserSdkLoaderByIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserSdkLoaderHelper.js","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoaderHelper.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,sEAAsE;AAEtE,mDAA6B;AAC7B,yCAAsC;AAGtC,iDAAiD;AACjD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,4CAAmB,CAAA;IACnB,kCAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AAED,mCAAmC;AACtB,QAAA,mBAAmB,GAAG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CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,QAAQ,GAAG,iCAAiC,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,CAAC;IAC9F,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,6BAA6B,iCAUxC;AAEK,MAAM,uBAAuB,GAAG,CAAC,QAA6B,EAAW,EAAE;IAChF,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACvD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\nimport * as zlib from \"zlib\";\nimport { promisify } from \"node:util\";\nimport type http from \"node:http\";\n\n// currently support the following encoding types\nexport enum contentEncodingMethod {\n GZIP = \"gzip\",\n DEFLATE = \"deflate\",\n BR = \"br\",\n}\n\n// current supported encoding types\nexport const bufferEncodingTypes = [\n \"utf8\",\n \"utf16le\",\n \"latin1\",\n \"base64\",\n \"hex\",\n \"ascii\",\n \"binary\",\n \"ucs2\",\n];\n\n// for node version under 10, Brotli compression is not supported.\nexport const isBrotliSupported = (): boolean => {\n const majVer = process.versions.node.split(\".\")[0];\n return parseInt(majVer) >= 10;\n};\n\nexport const gzipAsync = promisify(zlib.gzip);\nexport const gunzipAsync = promisify(zlib.gunzip);\nexport const deflateAsync = promisify(zlib.deflate);\nexport const inflateAsync = promisify(zlib.inflate);\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompress === \"function\") {\n return promisify(zlibObject.brotliCompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliCompressSync;\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompress === \"function\") {\n return promisify(zlibObject.brotliDecompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliDecompressSync;\n }\n return null;\n};\n\nexport const isBufferType = (buffer: Buffer, type?: string): boolean | null => {\n const encodingType = type ? type : \"utf8\";\n let result = false;\n if (Buffer.isEncoding(encodingType)) {\n const newBuffer = Buffer.from(buffer.toString(encodingType), encodingType);\n result = newBuffer.toJSON().data.toString() === buffer.toJSON().data.toString();\n }\n\n return result;\n};\n\nexport const findBufferEncodingType = (buffer: Buffer): string | null => {\n let bufferType = null;\n for (const type of bufferEncodingTypes) {\n if (Buffer.isEncoding(type) && isBufferType(buffer, type)) {\n bufferType = type;\n break;\n }\n }\n return bufferType;\n};\n\nexport const isSupportedContentEncoding = (\n encodingMethod: string,\n): contentEncodingMethod | null => {\n let encodingType = null;\n switch (encodingMethod) {\n case \"gzip\":\n encodingType = contentEncodingMethod.GZIP;\n break;\n case \"br\":\n encodingType = contentEncodingMethod.BR;\n break;\n case \"deflate\":\n encodingType = contentEncodingMethod.DEFLATE;\n break;\n default:\n }\n return encodingType;\n};\n\n// mutiple content-encoding is not supported\n// for mutiple content-encoding, this method will return any empty array\nexport const getContentEncodingFromHeaders = (\n response: http.ServerResponse,\n): contentEncodingMethod[] | null => {\n const headers: contentEncodingMethod[] = [];\n const contentEncodingHeaders = response.getHeader(\"Content-Encoding\");\n if (!contentEncodingHeaders) return null;\n if (typeof contentEncodingHeaders === \"string\") {\n const supportedContentEncoding = isSupportedContentEncoding(contentEncodingHeaders);\n if (supportedContentEncoding) {\n headers.push(supportedContentEncoding);\n }\n }\n return headers;\n};\n\nexport const insertBrowserSdkLoaderByIndex = (\n index: number,\n html: string,\n snippet: string,\n): string | null => {\n if (index < 0) return null;\n const subStart = html.substring(0, index);\n const subEnd = html.substring(index);\n const newHtml = subStart + '<script type=\"text/javascript\">' + snippet + \"</script>\" + subEnd;\n return newHtml;\n};\n\nexport const isContentTypeHeaderHtml = (response: http.ServerResponse): boolean => {\n let isHtml = false;\n const contentType = response.getHeader(\"Content-Type\");\n if (contentType) {\n if (typeof contentType === \"string\") {\n isHtml = contentType.indexOf(\"html\") >= 0;\n } else {\n isHtml = contentType.toString().indexOf(\"html\") >= 0;\n }\n }\n return isHtml;\n};\n"]}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
2
|
-
import type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, BrowserSdkLoaderOptions } from "./types.js";
|
|
3
|
-
export type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, BrowserSdkLoaderOptions };
|
|
2
|
+
import type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, ConsoleInstrumentationOptions, BrowserSdkLoaderOptions } from "./types.js";
|
|
3
|
+
export type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, ConsoleInstrumentationOptions, BrowserSdkLoaderOptions, };
|
|
4
4
|
/**
|
|
5
5
|
* Initialize Azure Monitor Distro
|
|
6
6
|
* @param options - Azure Monitor OpenTelemetry Options
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMlD,OAAO,KAAK,EAGV,gCAAgC,EAChC,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMlD,OAAO,KAAK,EAGV,gCAAgC,EAChC,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAiBpB,YAAY,EACV,gCAAgC,EAChC,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,GACxB,CAAC;AA4BF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gCAAgC,GAAG,IAAI,CAsGhF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAMpD;AAED;;;GAGG;AAEH,wBAAgB,eAAe,IAAI,OAAO,GAAG,SAAS,CAErD"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -22,12 +22,6 @@ const common_js_1 = require("./utils/common.js");
|
|
|
22
22
|
const logUtils_js_1 = require("./utils/logUtils.js");
|
|
23
23
|
const index_js_3 = require("./shared/logging/index.js");
|
|
24
24
|
const types_js_2 = require("./types.js");
|
|
25
|
-
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
26
|
-
/**
|
|
27
|
-
* Semantic attribute for cloud resource ID, defined by \@opentelemetry/resource-detector-azure
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
const CLOUD_RESOURCE_ID_ATTRIBUTE = "cloud.resource_id";
|
|
31
25
|
process.env["AZURE_MONITOR_DISTRO_VERSION"] = types_js_1.AZURE_MONITOR_OPENTELEMETRY_VERSION;
|
|
32
26
|
let sdk;
|
|
33
27
|
let browserSdkLoader;
|
|
@@ -70,18 +64,15 @@ function useAzureMonitor(options) {
|
|
|
70
64
|
winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,
|
|
71
65
|
console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,
|
|
72
66
|
};
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
const resourceAttributes = config.resource.attributes;
|
|
77
|
-
const aksResourceDetected = semantic_conventions_1.SEMRESATTRS_K8S_CLUSTER_NAME in resourceAttributes ||
|
|
78
|
-
CLOUD_RESOURCE_ID_ATTRIBUTE in resourceAttributes;
|
|
67
|
+
// Only report this feature when the AKS resource detector itself was able to populate the AKS
|
|
68
|
+
// cluster attributes, which requires the customer to have configured access to the
|
|
69
|
+
// aks-cluster-metadata ConfigMap (RBAC + env var or mounted file).
|
|
79
70
|
const statsbeatFeatures = {
|
|
80
71
|
browserSdkLoader: config.browserSdkLoaderOptions.enabled,
|
|
81
72
|
aadHandling: !!config.azureMonitorExporterOptions?.credential,
|
|
82
73
|
diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,
|
|
83
74
|
customerSdkStats: process.env[types_js_1.APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === "true",
|
|
84
|
-
aksResourceDetectorPopulation:
|
|
75
|
+
aksResourceDetectorPopulation: config.aksResourceDetectorPopulated,
|
|
85
76
|
};
|
|
86
77
|
(0, statsbeat_js_1.getInstance)().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);
|
|
87
78
|
if (config.browserSdkLoaderO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AG,CAAC;AACb,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport type { NodeSDKConfiguration } from \"@opentelemetry/sdk-node\";\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\nimport type { MetricReader, ViewOptions } from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"./shared/config.js\";\nimport { MetricHandler } from \"./metrics/index.js\";\nimport { TraceHandler } from \"./traces/handler.js\";\nimport { LogHandler } from \"./logs/index.js\";\nimport type {\n StatsbeatFeatures,\n StatsbeatInstrumentations,\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n BrowserSdkLoaderOptions,\n} from \"./types.js\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n APPLICATIONINSIGHTS_SDKSTATS_DISABLED,\n} from \"./types.js\";\nimport { BrowserSdkLoader } from \"./browserSdkLoader/browserSdkLoader.js\";\nimport { setSdkPrefix } from \"./metrics/quickpulse/utils.js\";\nimport type { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport type { LogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport { getInstance } from \"./utils/statsbeat.js\";\nimport { patchOpenTelemetryInstrumentationEnable } from \"./utils/opentelemetryInstrumentationPatcher.js\";\nimport { ensureAzureSdkTracingBridge } from \"./utils/azureSdkTracingBridge.js\";\nimport { isFunctionApp, parseResourceDetectorsFromEnvVar } from \"./utils/common.js\";\nimport { isLogCollectionDisabled } from \"./utils/logUtils.js\";\nimport { Logger } from \"./shared/logging/index.js\";\nimport { AZURE_MONITOR_AUTO_ATTACH } from \"./types.js\";\nimport { SEMRESATTRS_K8S_CLUSTER_NAME } from \"@opentelemetry/semantic-conventions\";\n\n/**\n * Semantic attribute for cloud resource ID, defined by \\@opentelemetry/resource-detector-azure\n * @internal\n */\nconst CLOUD_RESOURCE_ID_ATTRIBUTE = \"cloud.resource_id\";\n\nexport type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, BrowserSdkLoaderOptions };\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet sdk: NodeSDK;\nlet browserSdkLoader: BrowserSdkLoader | undefined;\n// Track the global console patch because NodeSDK does not disable instrumentations.\nlet consoleInstrumentation: Instrumentation | undefined;\n\n/**\n * Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.\n */\nfunction sendAttachWarning(): void {\n if (process.env[AZURE_MONITOR_AUTO_ATTACH] === \"true\" && !isFunctionApp()) {\n // TODO: When AKS attach is public, update this message with disablement instructions for AKS\n const message =\n \"Distro detected that automatic instrumentation may have occurred. Only use autoinstrumentation if you \" +\n \"are not using manual instrumentation of OpenTelemetry in your code, such as with \" +\n \"@azure/monitor-opentelemetry or @azure/monitor-opentelemetry-exporter. For App Service resources, disable \" +\n \"autoinstrumentation in the Application Insights experience on your App Service resource or by setting \" +\n \"the ApplicationInsightsAgent_EXTENSION_VERSION app setting to 'disabled'.\";\n // Surface in the log stream\n console.warn(message);\n // Also log via diagnostic logging\n Logger.getInstance().warn(message);\n }\n}\n\n/**\n * Initialize Azure Monitor Distro\n * @param options - Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions): void {\n const config = new InternalConfig(options);\n patchOpenTelemetryInstrumentationEnable();\n // Omit disabled log instrumentations from Statsbeat.\n const logInstrumentationsEnabled = !isLogCollectionDisabled();\n const statsbeatInstrumentations: StatsbeatInstrumentations = {\n // Instrumentations\n azureSdk: config.instrumentationOptions?.azureSdk?.enabled,\n mongoDb: config.instrumentationOptions?.mongoDb?.enabled,\n mySql: config.instrumentationOptions?.mySql?.enabled,\n postgreSql: config.instrumentationOptions?.postgreSql?.enabled,\n redis: config.instrumentationOptions?.redis?.enabled,\n bunyan: logInstrumentationsEnabled && config.instrumentationOptions?.bunyan?.enabled,\n winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,\n console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,\n };\n // Check if the AKS resource detector successfully populated specific resource attributes\n // (k8s.cluster.name or cloud.resource_id) beyond the basic cloud.platform/cloud.provider\n // Derive from config.resource.attributes which already includes the AKS detector results\n const resourceAttributes = config.resource.attributes;\n const aksResourceDetected =\n SEMRESATTRS_K8S_CLUSTER_NAME in resourceAttributes ||\n CLOUD_RESOURCE_ID_ATTRIBUTE in resourceAttributes;\n const statsbeatFeatures: StatsbeatFeatures = {\n browserSdkLoader: config.browserSdkLoaderOptions.enabled,\n aadHandling: !!config.azureMonitorExporterOptions?.credential,\n diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,\n customerSdkStats: process.env[APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === \"true\",\n aksResourceDetectorPopulation: aksResourceDetected,\n };\n getInstance().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);\n\n if (config.browserSdkLoaderOptions.enabled) {\n browserSdkLoader = new BrowserSdkLoader(config);\n }\n // Remove global providers in OpenTelemetry, these would be overridden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n // Restore any console patch from the previous initialization.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n\n // Clear the entire OpenTelemetry API global state to avoid version conflicts.\n // The disable() calls above remove individual providers but leave the `version` field\n // on the global object intact. If a different version of @opentelemetry/api was loaded\n // first (e.g. by a VS Code extension host or another extension), the stale version\n // causes registerGlobal() in sdk.start() to fail with \"All API registration versions\n // must match\", resulting in Noop providers. Deleting the global object forces\n // registerGlobal() to create a fresh one with the correct version.\n const globalOpentelemetryApiKey = Symbol.for(\"opentelemetry.js.api.1\");\n Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);\n\n // Create internal handlers\n const metricHandler = new MetricHandler(config);\n const traceHandler = new TraceHandler(config, metricHandler);\n const logHandler = new LogHandler(config, metricHandler);\n\n const instrumentations = traceHandler\n .getInstrumentations()\n .concat(logHandler.getInstrumentations());\n consoleInstrumentation = logHandler.getConsoleInstrumentation();\n\n const resourceDetectorsList = parseResourceDetectorsFromEnvVar();\n\n // Add extra SpanProcessors, and logRecordProcessors from user configuration\n const spanProcessors: SpanProcessor[] = options?.spanProcessors || [];\n const logRecordProcessors: LogRecordProcessor[] = options?.logRecordProcessors || [];\n const customViews: ViewOptions[] = options?.views || [];\n\n // Prepare metric readers - always include Azure Monitor\n const metricReaders: MetricReader[] = [\n metricHandler.getMetricReader(),\n ...(options?.metricReaders || []),\n ];\n\n const views: ViewOptions[] = metricHandler.getViews().concat(customViews);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n metricReaders: metricReaders,\n views,\n instrumentations: instrumentations,\n logRecordProcessors: [\n logHandler.getAzureLogRecordProcessor(),\n ...logRecordProcessors,\n logHandler.getBatchLogRecordProcessor(),\n ],\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessors: [\n traceHandler.getAzureMonitorSpanProcessor(),\n ...spanProcessors,\n traceHandler.getBatchSpanProcessor(),\n ],\n resourceDetectors: resourceDetectorsList,\n };\n sdk = new NodeSDK(sdkConfig);\n setSdkPrefix();\n sendAttachWarning();\n sdk.start();\n\n // Eagerly install the Azure SDK tracing bridge in case @azure/core-tracing\n // was loaded before useAzureMonitor() (the RITM hook misses it otherwise).\n ensureAzureSdkTracingBridge();\n}\n\n/**\n * Shutdown Azure Monitor Open Telemetry Distro\n * @see https://github.com/open-telemetry/opentelemetry-js/blob/0229434cb5a3179f63c021105f36270ae7897929/experimental/packages/opentelemetry-sdk-node/src/sdk.ts#L398\n */\nexport function shutdownAzureMonitor(): Promise<void> {\n browserSdkLoader?.dispose();\n // NodeSDK.shutdown() does not restore the global console.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n return sdk?.shutdown();\n}\n\n/**\n * Get the internal SDK instance for testing purposes\n * @internal\n */\n// eslint-disable-next-line no-underscore-dangle\nexport function _getSdkInstance(): NodeSDK | undefined {\n return sdk;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAyElC,0CAsGC;AAMD,oDAMC;AAOD,0CAEC;AAlMD,4CAAoD;AACpD,sDAA+C;AAG/C,sDAAkD;AAElD,kDAAoD;AACpD,iDAAmD;AACnD,oDAAmD;AACnD,8CAA6C;AAS7C,yCAGoB;AACpB,gFAA0E;AAC1E,4DAA6D;AAG7D,uDAAmD;AACnD,2GAAyG;AACzG,+EAA+E;AAC/E,iDAAoF;AACpF,qDAA8D;AAC9D,wDAAmD;AACnD,yCAAuD;AASvD,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,8CAAmC,CAAC;AAElF,IAAI,GAAY,CAAC;AACjB,IAAI,gBAA8C,CAAC;AACnD,oFAAoF;AACpF,IAAI,sBAAmD,CAAC;AAExD;;GAEG;AACH,SAAS,iBAAiB;IACxB,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAyB,CAAC,KAAK,MAAM,IAAI,CAAC,IAAA,yBAAa,GAAE,EAAE,CAAC;QAC1E,6FAA6F;QAC7F,MAAM,OAAO,GACX,wGAAwG;YACxG,mFAAmF;YACnF,4GAA4G;YAC5G,wGAAwG;YACxG,2EAA2E,CAAC;QAC9E,4BAA4B;QAC5B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,kCAAkC;QAClC,iBAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,OAA0C;IACxE,MAAM,MAAM,GAAG,IAAI,0BAAc,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAA,gFAAuC,GAAE,CAAC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C,OAAO,EAAE,aAAa,IAAI,EAAE,CAAC;KAClC,CAAC;IAEF,MAAM,KAAK,GAAkB,aAAa,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAE1E,+BAA+B;IAC/B,MAAM,SAAS,GAAkC;QAC/C,mBAAmB,EAAE,IAAI;QACzB,aAAa,EAAE,aAAa;QAC5B,KAAK;QACL,gBAAgB,EAAE,gBAAgB;QAClC,mBAAmB,EAAE;YACnB,UAAU,CAAC,0BAA0B,EAAE;YACvC,GAAG,mBAAmB;YACtB,UAAU,CAAC,0BAA0B,EAAE;SACxC;QACD,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,YAAY,CAAC,UAAU,EAAE;QAClC,cAAc,EAAE;YACd,YAAY,CAAC,4BAA4B,EAAE;YAC3C,GAAG,cAAc;YACjB,YAAY,CAAC,qBAAqB,EAAE;SACrC;QACD,iBAAiB,EAAE,qBAAqB;KACzC,CAAC;IACF,GAAG,GAAG,IAAI,kBAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,IAAA,uBAAY,GAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;IACpB,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,2EAA2E;IAC3E,2EAA2E;IAC3E,IAAA,sDAA2B,GAAE,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB;IAClC,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,sBAAsB,EAAE,OAAO,EAAE,CAAC;IAClC,sBAAsB,GAAG,SAAS,CAAC;IACnC,OAAO,GAAG,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,gDAAgD;AAChD,SAAgB,eAAe;IAC7B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport type { NodeSDKConfiguration } from \"@opentelemetry/sdk-node\";\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\nimport type { MetricReader, ViewOptions } from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"./shared/config.js\";\nimport { MetricHandler } from \"./metrics/index.js\";\nimport { TraceHandler } from \"./traces/handler.js\";\nimport { LogHandler } from \"./logs/index.js\";\nimport type {\n StatsbeatFeatures,\n StatsbeatInstrumentations,\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n ConsoleInstrumentationOptions,\n BrowserSdkLoaderOptions,\n} from \"./types.js\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n APPLICATIONINSIGHTS_SDKSTATS_DISABLED,\n} from \"./types.js\";\nimport { BrowserSdkLoader } from \"./browserSdkLoader/browserSdkLoader.js\";\nimport { setSdkPrefix } from \"./metrics/quickpulse/utils.js\";\nimport type { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport type { LogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport { getInstance } from \"./utils/statsbeat.js\";\nimport { patchOpenTelemetryInstrumentationEnable } from \"./utils/opentelemetryInstrumentationPatcher.js\";\nimport { ensureAzureSdkTracingBridge } from \"./utils/azureSdkTracingBridge.js\";\nimport { isFunctionApp, parseResourceDetectorsFromEnvVar } from \"./utils/common.js\";\nimport { isLogCollectionDisabled } from \"./utils/logUtils.js\";\nimport { Logger } from \"./shared/logging/index.js\";\nimport { AZURE_MONITOR_AUTO_ATTACH } from \"./types.js\";\n\nexport type {\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n ConsoleInstrumentationOptions,\n BrowserSdkLoaderOptions,\n};\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet sdk: NodeSDK;\nlet browserSdkLoader: BrowserSdkLoader | undefined;\n// Track the global console patch because NodeSDK does not disable instrumentations.\nlet consoleInstrumentation: Instrumentation | undefined;\n\n/**\n * Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.\n */\nfunction sendAttachWarning(): void {\n if (process.env[AZURE_MONITOR_AUTO_ATTACH] === \"true\" && !isFunctionApp()) {\n // TODO: When AKS attach is public, update this message with disablement instructions for AKS\n const message =\n \"Distro detected that automatic instrumentation may have occurred. Only use autoinstrumentation if you \" +\n \"are not using manual instrumentation of OpenTelemetry in your code, such as with \" +\n \"@azure/monitor-opentelemetry or @azure/monitor-opentelemetry-exporter. For App Service resources, disable \" +\n \"autoinstrumentation in the Application Insights experience on your App Service resource or by setting \" +\n \"the ApplicationInsightsAgent_EXTENSION_VERSION app setting to 'disabled'.\";\n // Surface in the log stream\n console.warn(message);\n // Also log via diagnostic logging\n Logger.getInstance().warn(message);\n }\n}\n\n/**\n * Initialize Azure Monitor Distro\n * @param options - Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions): void {\n const config = new InternalConfig(options);\n patchOpenTelemetryInstrumentationEnable();\n // Omit disabled log instrumentations from Statsbeat.\n const logInstrumentationsEnabled = !isLogCollectionDisabled();\n const statsbeatInstrumentations: StatsbeatInstrumentations = {\n // Instrumentations\n azureSdk: config.instrumentationOptions?.azureSdk?.enabled,\n mongoDb: config.instrumentationOptions?.mongoDb?.enabled,\n mySql: config.instrumentationOptions?.mySql?.enabled,\n postgreSql: config.instrumentationOptions?.postgreSql?.enabled,\n redis: config.instrumentationOptions?.redis?.enabled,\n bunyan: logInstrumentationsEnabled && config.instrumentationOptions?.bunyan?.enabled,\n winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,\n console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,\n };\n // Only report this feature when the AKS resource detector itself was able to populate the AKS\n // cluster attributes, which requires the customer to have configured access to the\n // aks-cluster-metadata ConfigMap (RBAC + env var or mounted file).\n const statsbeatFeatures: StatsbeatFeatures = {\n browserSdkLoader: config.browserSdkLoaderOptions.enabled,\n aadHandling: !!config.azureMonitorExporterOptions?.credential,\n diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,\n customerSdkStats: process.env[APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === \"true\",\n aksResourceDetectorPopulation: config.aksResourceDetectorPopulated,\n };\n getInstance().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);\n\n if (config.browserSdkLoaderOptions.enabled) {\n browserSdkLoader = new BrowserSdkLoader(config);\n }\n // Remove global providers in OpenTelemetry, these would be overridden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n // Restore any console patch from the previous initialization.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n\n // Clear the entire OpenTelemetry API global state to avoid version conflicts.\n // The disable() calls above remove individual providers but leave the `version` field\n // on the global object intact. If a different version of @opentelemetry/api was loaded\n // first (e.g. by a VS Code extension host or another extension), the stale version\n // causes registerGlobal() in sdk.start() to fail with \"All API registration versions\n // must match\", resulting in Noop providers. Deleting the global object forces\n // registerGlobal() to create a fresh one with the correct version.\n const globalOpentelemetryApiKey = Symbol.for(\"opentelemetry.js.api.1\");\n Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);\n\n // Create internal handlers\n const metricHandler = new MetricHandler(config);\n const traceHandler = new TraceHandler(config, metricHandler);\n const logHandler = new LogHandler(config, metricHandler);\n\n const instrumentations = traceHandler\n .getInstrumentations()\n .concat(logHandler.getInstrumentations());\n consoleInstrumentation = logHandler.getConsoleInstrumentation();\n\n const resourceDetectorsList = parseResourceDetectorsFromEnvVar();\n\n // Add extra SpanProcessors, and logRecordProcessors from user configuration\n const spanProcessors: SpanProcessor[] = options?.spanProcessors || [];\n const logRecordProcessors: LogRecordProcessor[] = options?.logRecordProcessors || [];\n const customViews: ViewOptions[] = options?.views || [];\n\n // Prepare metric readers - always include Azure Monitor\n const metricReaders: MetricReader[] = [\n metricHandler.getMetricReader(),\n ...(options?.metricReaders || []),\n ];\n\n const views: ViewOptions[] = metricHandler.getViews().concat(customViews);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n metricReaders: metricReaders,\n views,\n instrumentations: instrumentations,\n logRecordProcessors: [\n logHandler.getAzureLogRecordProcessor(),\n ...logRecordProcessors,\n logHandler.getBatchLogRecordProcessor(),\n ],\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessors: [\n traceHandler.getAzureMonitorSpanProcessor(),\n ...spanProcessors,\n traceHandler.getBatchSpanProcessor(),\n ],\n resourceDetectors: resourceDetectorsList,\n };\n sdk = new NodeSDK(sdkConfig);\n setSdkPrefix();\n sendAttachWarning();\n sdk.start();\n\n // Eagerly install the Azure SDK tracing bridge in case @azure/core-tracing\n // was loaded before useAzureMonitor() (the RITM hook misses it otherwise).\n ensureAzureSdkTracingBridge();\n}\n\n/**\n * Shutdown Azure Monitor Open Telemetry Distro\n * @see https://github.com/open-telemetry/opentelemetry-js/blob/0229434cb5a3179f63c021105f36270ae7897929/experimental/packages/opentelemetry-sdk-node/src/sdk.ts#L398\n */\nexport function shutdownAzureMonitor(): Promise<void> {\n browserSdkLoader?.dispose();\n // NodeSDK.shutdown() does not restore the global console.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n return sdk?.shutdown();\n}\n\n/**\n * Get the internal SDK instance for testing purposes\n * @internal\n */\n// eslint-disable-next-line no-underscore-dangle\nexport function _getSdkInstance(): NodeSDK | undefined {\n return sdk;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE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AiB,CAAoB;IAC7C,OAAO,CAAC,uBAAuB,CAA8B;IAE7D;;;;OAIG;gBACS,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa;IAYzD,0BAA0B,IAAI,uBAAuB;IAIrD,0BAA0B,IAAI,uBAAuB;IAIrD,mBAAmB,IAAI,eAAe,EAAE;IAI/C,6EAA6E;IACtE,yBAAyB,IAAI,eAAe,GAAG,SAAS;IAI/D;;OAEG;IACH,OAAO,CAAC,2BAA2B;CAoCpC"}
|
|
@@ -71,12 +71,13 @@ class LogHandler {
|
|
|
71
71
|
logSeverity,
|
|
72
72
|
}));
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
const consoleOptions = this._config.instrumentationOptions.console;
|
|
75
|
+
if (consoleOptions?.enabled) {
|
|
75
76
|
// Defer patching until registration so construction preserves the original methods.
|
|
76
77
|
const consoleInstrumentation = new instrumentation_console_1.ConsoleInstrumentation({
|
|
77
|
-
...
|
|
78
|
+
...consoleOptions,
|
|
78
79
|
enabled: false,
|
|
79
|
-
logSeverity,
|
|
80
|
+
logSeverity: consoleOptions.logSeverity ?? logSeverity,
|
|
80
81
|
});
|
|
81
82
|
this._consoleInstrumentation = consoleInstrumentation;
|
|
82
83
|
this._instrumentations.push(consoleInstrumentation);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,0FAAgF;AAEhF,kFAA8E;AAC9E,oFAAgF;AAChF,oFAAgF;AAIhF,mEAAkE;AAClE,6EAA4E;AAC5E,sDAAyF;AAEzF;;GAEG;AACH,MAAa,UAAU;IACb,cAAc,CAA0B;IACxC,wBAAwB,CAA0B;IAClD,6BAA6B,CAA+B;IAC5D,cAAc,CAAgB;IAC9B,OAAO,CAAiB;IACxB,iBAAiB,CAAoB;IACrC,uBAAuB,CAA8B;IAE7D;;;;OAIG;IACH,YAAY,MAA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BAAsB,GAAG,IAAI,gDAAsB,CAAC;gBACxD,GAAG,cAAc;gBACjB,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,WAAW;aACvD,CAAC,CAAC;YACH,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAlFD,gCAkFC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzureMonitorLogExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BunyanInstrumentation } from \"@opentelemetry/instrumentation-bunyan\";\nimport { ConsoleInstrumentation } from \"@opentelemetry/instrumentation-console\";\nimport { WinstonInstrumentation } from \"@opentelemetry/instrumentation-winston\";\nimport type { BatchLogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport type { InternalConfig } from \"../shared/config.js\";\nimport type { MetricHandler } from \"../metrics/handler.js\";\nimport { AzureLogRecordProcessor } from \"./logRecordProcessor.js\";\nimport { AzureBatchLogRecordProcessor } from \"./batchLogRecordProcessor.js\";\nimport { isLogCollectionDisabled, logLevelToSeverityNumber } from \"../utils/logUtils.js\";\n\n/**\n * Azure Monitor OpenTelemetry Log Handler\n */\nexport class LogHandler {\n private _azureExporter: AzureMonitorLogExporter;\n private _azureLogRecordProcessor: AzureLogRecordProcessor;\n private _azureBatchLogRecordProcessor: AzureBatchLogRecordProcessor;\n private _metricHandler: MetricHandler;\n private _config: InternalConfig;\n private _instrumentations: Instrumentation[];\n private _consoleInstrumentation: Instrumentation | undefined;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Distro configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);\n this._azureBatchLogRecordProcessor = new AzureBatchLogRecordProcessor(this._azureExporter, {\n enableTraceBasedSamplingForLogs: this._config.enableTraceBasedSamplingForLogs,\n });\n this._azureLogRecordProcessor = new AzureLogRecordProcessor(this._metricHandler);\n this._instrumentations = [];\n this._initializeInstrumentations();\n }\n\n public getAzureLogRecordProcessor(): AzureLogRecordProcessor {\n return this._azureLogRecordProcessor;\n }\n\n public getBatchLogRecordProcessor(): BatchLogRecordProcessor {\n return this._azureBatchLogRecordProcessor;\n }\n\n public getInstrumentations(): Instrumentation[] {\n return this._instrumentations;\n }\n\n /** Returns the console instrumentation for explicit lifecycle management. */\n public getConsoleInstrumentation(): Instrumentation | undefined {\n return this._consoleInstrumentation;\n }\n\n /**\n * Start auto collection of telemetry\n */\n private _initializeInstrumentations(): void {\n if (isLogCollectionDisabled()) {\n return;\n }\n\n const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;\n const logSeverity = logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined;\n\n if (this._config.instrumentationOptions.bunyan?.enabled) {\n this._instrumentations.push(\n new BunyanInstrumentation({\n ...this._config.instrumentationOptions.bunyan,\n logSeverity,\n }),\n );\n }\n if (this._config.instrumentationOptions.winston?.enabled) {\n this._instrumentations.push(\n new WinstonInstrumentation({\n ...this._config.instrumentationOptions.winston,\n logSeverity,\n }),\n );\n }\n const consoleOptions = this._config.instrumentationOptions.console;\n if (consoleOptions?.enabled) {\n // Defer patching until registration so construction preserves the original methods.\n const consoleInstrumentation = new ConsoleInstrumentation({\n ...consoleOptions,\n enabled: false,\n logSeverity: consoleOptions.logSeverity ?? logSeverity,\n });\n this._consoleInstrumentation = consoleInstrumentation;\n this._instrumentations.push(consoleInstrumentation);\n }\n }\n}\n"]}
|
|
@@ -34,6 +34,9 @@ export declare class PerformanceCounterMetrics {
|
|
|
34
34
|
private lastHrtime;
|
|
35
35
|
private lastCpus;
|
|
36
36
|
private lastCpusProcess;
|
|
37
|
+
private lastAppCpuUsageNormalized;
|
|
38
|
+
private lastHrtimeNormalized;
|
|
39
|
+
private lastCpusProcessNormalized;
|
|
37
40
|
private totalExceptionCount;
|
|
38
41
|
/**
|
|
39
42
|
* Creates performance counter instruments.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceCounters.d.ts","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAM5D,OAAO,EAAE,aAAa,EAAiC,MAAM,4BAA4B,CAAC;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,+BAA+B,CAAC;AAG9E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AAOpE;;GAEG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,wBAAwB,CAAY;IAC5C,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,uBAAuB,CAAkB;IACjD,OAAO,CAAC,+BAA+B,CAAqB;IAC5D,OAAO,CAAC,yBAAyB,CAAkB;IACnD,OAAO,CAAC,iCAAiC,CAAqB;IAC9D,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,0BAA0B,CAAqB;IACvD,OAAO,CAAC,0BAA0B,CAAkB;IACpD,OAAO,CAAC,kCAAkC,CAAqB;IAC/D,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,mBAAmB,CAAkB;IAC7C,OAAO,CAAC,2BAA2B,CAAqB;IACxD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CAAW;IAC7B,OAAO,CAAC,QAAQ,CAIZ;IACJ,OAAO,CAAC,eAAe,CAInB;IACJ,OAAO,CAAC,yBAAyB,CAAmC;IACpE,OAAO,CAAC,oBAAoB,CAAW;IACvC,OAAO,CAAC,yBAAyB,CAI7B;IACJ,OAAO,CAAC,mBAAmB,CAAa;IAExC;;;;OAIG;gBACS,MAAM,EAAE,gCAAgC,EAAE,OAAO,CAAC,EAAE;QAAE,kBAAkB,EAAE,MAAM,CAAA;KAAE;IAkG9F;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;OAEG;IACI,gBAAgB,IAAI,aAAa;IAIxC;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAkB3C;;;OAGG;IACI,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAO/C,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,mBAAmB;IAwC3B,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,wBAAwB;IA0ChC,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,gBAAgB;CAgBzB"}
|
|
@@ -38,7 +38,7 @@ class PerformanceCounterMetrics {
|
|
|
38
38
|
processTimeGaugeCallback;
|
|
39
39
|
exceptionCountGauge;
|
|
40
40
|
exceptionCountGaugeCallback;
|
|
41
|
-
lastExceptionRate
|
|
41
|
+
lastExceptionRate;
|
|
42
42
|
totalCount = 0;
|
|
43
43
|
intervalExecutionTime = 0;
|
|
44
44
|
lastRequestRate;
|
|
@@ -46,6 +46,9 @@ class PerformanceCounterMetrics {
|
|
|
46
46
|
lastHrtime;
|
|
47
47
|
lastCpus;
|
|
48
48
|
lastCpusProcess;
|
|
49
|
+
lastAppCpuUsageNormalized;
|
|
50
|
+
lastHrtimeNormalized;
|
|
51
|
+
lastCpusProcessNormalized;
|
|
49
52
|
totalExceptionCount = 0;
|
|
50
53
|
/**
|
|
51
54
|
* Creates performance counter instruments.
|
|
@@ -58,11 +61,15 @@ class PerformanceCounterMetrics {
|
|
|
58
61
|
this.lastCpusProcess = node_os_1.default.cpus();
|
|
59
62
|
this.lastAppCpuUsage = node_process_1.default.cpuUsage();
|
|
60
63
|
this.lastHrtime = node_process_1.default.hrtime();
|
|
64
|
+
this.lastCpusProcessNormalized = node_os_1.default.cpus();
|
|
65
|
+
this.lastAppCpuUsageNormalized = node_process_1.default.cpuUsage();
|
|
66
|
+
this.lastHrtimeNormalized = node_process_1.default.hrtime();
|
|
61
67
|
this.lastRequestRate = {
|
|
62
68
|
count: this.totalCount,
|
|
63
69
|
time: +new Date(),
|
|
64
70
|
executionInterval: this.intervalExecutionTime,
|
|
65
71
|
};
|
|
72
|
+
this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };
|
|
66
73
|
this.azureExporter = new monitor_opentelemetry_exporter_1.AzureMonitorMetricExporter(this.internalConfig.azureMonitorExporterOptions);
|
|
67
74
|
const metricReaderOptions = {
|
|
68
75
|
exporter: this.azureExporter,
|
|
@@ -74,7 +81,6 @@ class PerformanceCounterMetrics {
|
|
|
74
81
|
};
|
|
75
82
|
this.meterProvider = new sdk_metrics_1.MeterProvider(meterProviderConfig);
|
|
76
83
|
this.meter = this.meterProvider.getMeter("AzureMonitorPerformanceCountersMeter");
|
|
77
|
-
this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };
|
|
78
84
|
// Create Instruments
|
|
79
85
|
this.requestDurationHistogram = this.meter.createHistogram(types_js_1.PerformanceCounterMetricNames.REQUEST_DURATION, { valueType: api_1.ValueType.DOUBLE });
|
|
80
86
|
this.requestRateGauge = this.meter.createObservableGauge(types_js_1.PerformanceCounterMetricNames.REQUEST_RATE, {
|
|
@@ -248,33 +254,31 @@ class PerformanceCounterMetrics {
|
|
|
248
254
|
const cpus = node_os_1.default.cpus();
|
|
249
255
|
if (cpus &&
|
|
250
256
|
cpus.length &&
|
|
251
|
-
this.
|
|
252
|
-
cpus.length === this.
|
|
257
|
+
this.lastCpusProcessNormalized &&
|
|
258
|
+
cpus.length === this.lastCpusProcessNormalized.length) {
|
|
253
259
|
// Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)
|
|
254
260
|
let appCpuPercent = undefined;
|
|
255
261
|
const appCpuUsage = node_process_1.default.cpuUsage();
|
|
256
262
|
const hrtime = node_process_1.default.hrtime();
|
|
257
263
|
const totalApp = appCpuUsage.user -
|
|
258
|
-
this.
|
|
259
|
-
(appCpuUsage.system - this.
|
|
260
|
-
if (typeof this.
|
|
261
|
-
|
|
264
|
+
this.lastAppCpuUsageNormalized.user +
|
|
265
|
+
(appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;
|
|
266
|
+
if (typeof this.lastHrtimeNormalized !== "undefined" &&
|
|
267
|
+
this.lastHrtimeNormalized.length === 2) {
|
|
268
|
+
const elapsedTime = (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +
|
|
269
|
+
(hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds
|
|
262
270
|
appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);
|
|
263
271
|
}
|
|
264
272
|
// Set previous
|
|
265
|
-
this.
|
|
266
|
-
this.
|
|
267
|
-
const cpuTotals = this.getTotalCombinedCpu(cpus, this.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
274
|
-
}
|
|
273
|
+
this.lastAppCpuUsageNormalized = appCpuUsage;
|
|
274
|
+
this.lastHrtimeNormalized = hrtime;
|
|
275
|
+
const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);
|
|
276
|
+
const value = appCpuPercent !== undefined
|
|
277
|
+
? appCpuPercent
|
|
278
|
+
: (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
275
279
|
observableResult.observe(value);
|
|
276
280
|
}
|
|
277
|
-
this.
|
|
281
|
+
this.lastCpusProcessNormalized = cpus;
|
|
278
282
|
}
|
|
279
283
|
getProcessTime(observableResult) {
|
|
280
284
|
// this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary
|
|
@@ -300,13 +304,9 @@ class PerformanceCounterMetrics {
|
|
|
300
304
|
this.lastAppCpuUsage = appCpuUsage;
|
|
301
305
|
this.lastHrtime = hrtime;
|
|
302
306
|
const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
309
|
-
}
|
|
307
|
+
const value = appCpuPercent !== undefined
|
|
308
|
+
? appCpuPercent
|
|
309
|
+
: (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
310
310
|
observableResult.observe(value);
|
|
311
311
|
}
|
|
312
312
|
this.lastCpusProcess = cpus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,8DAAyB;AAQzB,4CAAyD;AAEzD,0FAAmF;AAKnF,4DAA0F;AAE1F,yCAA2D;AAC3D,8CAA2D;AAE3D,oDAAoE;AAEpE,2DAAqD;AACrD,yCAAiD;AACjD,wEAAmC;AAEnC;;GAEG;AACH,MAAa,yBAAyB;IAC5B,cAAc,CAAmC;IACjD,kBAAkB,GAAG,KAAK,CAAC,CAAC,aAAa;IACzC,aAAa,CAAgB;IAC7B,aAAa,CAA6B;IAC1C,KAAK,CAAQ;IACb,wBAAwB,CAAY;IACpC,gBAAgB,CAAkB;IAClC,wBAAwB,CA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AAuD,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,gBAAkC;QACzD,MAAM,WAAW,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC,CAAC;QAClF,MAAM,SAAS,GAAG,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;QAC5D,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,cAAc,GAAG,SAAS,GAAG,IAAI,CAAC;YACxC,MAAM,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;YACjD,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF;AAzXD,8DAyXC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number } = { count: 0, time: 0 };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
|
|
1
|
+
{"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,8DAAyB;AAQzB,4CAAyD;AAEzD,0FAAmF;AAKnF,4DAA0F;AAE1F,yCAA2D;AAC3D,8CAA2D;AAE3D,oDAAoE;AAEpE,2DAAqD;AACrD,yCAAiD;AACjD,wEAAmC;AAEnC;;GAEG;AACH,MAAa,yBAAyB;IAC5B,cAAc,CAAmC;IACjD,kBAAkB,GAAG,KAAK,CAAC,CAAC,aAAa;IACzC,aAAa,CAAgB;IAC7B,aAAa,CAA6B;IAC1C,KAAK,CAAQ;IACb,wBAAwB,CAAY;IACpC,gBAAgB,CAAkB;IAClC,wBAAwB,CAAqB;IAC7C,uBAAuB,CAAkB;IACzC,+BAA+B,CAAqB;IACpD,yBAAyB,CAAkB;IAC3C,iCAAiC,CAAqB;IACtD,kBAAkB,CAAkB;IACpC,0BAA0B,CAAqB;IAC/C,0BAA0B,CAAkB;IAC5C,kCAAkC,CAAqB;IACvD,gBAAgB,CAAkB;IAClC,wBAAwB,CAAqB;IAC7C,mBAAmB,CAAkB;IACrC,2BAA2B,CAAqB;IAChD,iBAAiB,CAAkC;IACnD,UAAU,GAAW,CAAC,CAAC;IACvB,qBAAqB,GAAG,CAAC,CAAC;IAC1B,eAAe,CAA6D;IAC5E,eAAe,CAAmC;IAClD,UAAU,CAAW;IACrB,QAAQ,CAIZ;IACI,eAAe,CAInB;IACI,yBAAyB,CAAmC;IAC5D,oBAAoB,CAAW;IAC/B,yBAAyB,CAI7B;IACI,mBAAmB,GAAW,CAAC,CAAC;IAExC;;;;OAIG;IACH,YAAY,MAAwC,EAAE,O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CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF;AAlYD,8DAkYC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastAppCpuUsageNormalized: { user: number; system: number };\n private lastHrtimeNormalized: number[];\n private lastCpusProcessNormalized: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n this.lastCpusProcessNormalized = os.cpus();\n this.lastAppCpuUsageNormalized = process.cpuUsage();\n this.lastHrtimeNormalized = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcessNormalized &&\n cpus.length === this.lastCpusProcessNormalized.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsageNormalized.user +\n (appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;\n\n if (\n typeof this.lastHrtimeNormalized !== \"undefined\" &&\n this.lastHrtimeNormalized.length === 2\n ) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +\n (hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsageNormalized = appCpuUsage;\n this.lastHrtimeNormalized = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);\n const value =\n appCpuPercent !== undefined\n ? appCpuPercent\n : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n observableResult.observe(value);\n }\n this.lastCpusProcessNormalized = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n const value =\n appCpuPercent !== undefined\n ? appCpuPercent\n : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAK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
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
const currentHost = (() => {
|
|
126
|
+
try {
|
|
127
|
+
return new url_1.default.URL(this.endpointUrl).host;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
})();
|
|
132
133
|
if (!(0, redirectUtils_js_1.isSameRegisteredDomain)(currentHost, locUrl.host)) {
|
|
133
134
|
api_1.diag.error(`Refusing cross-origin Live Metrics redirect to https://${locUrl.host}: target is neither the configured endpoint host nor under a known Azure Monitor ingestion domain.`);
|
|
134
135
|
return;
|