@azure/monitor-opentelemetry 1.18.1 → 1.19.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 +8 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +20 -3
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/logs/batchLogRecordProcessor.js +1 -1
- package/dist/commonjs/logs/batchLogRecordProcessor.js.map +1 -1
- package/dist/commonjs/logs/handler.d.ts +3 -0
- package/dist/commonjs/logs/handler.d.ts.map +1 -1
- package/dist/commonjs/logs/handler.js +22 -2
- package/dist/commonjs/logs/handler.js.map +1 -1
- package/dist/commonjs/metrics/handler.d.ts.map +1 -1
- package/dist/commonjs/metrics/handler.js +2 -3
- package/dist/commonjs/metrics/handler.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/credentialUtils.d.ts +16 -0
- package/dist/commonjs/metrics/quickpulse/credentialUtils.d.ts.map +1 -0
- package/dist/commonjs/metrics/quickpulse/credentialUtils.js +48 -0
- package/dist/commonjs/metrics/quickpulse/credentialUtils.js.map +1 -0
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts +10 -0
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.js +37 -8
- package/dist/commonjs/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/filtering/filter.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/filtering/filter.js +2 -5
- package/dist/commonjs/metrics/quickpulse/filtering/filter.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/liveMetrics.d.ts +4 -2
- package/dist/commonjs/metrics/quickpulse/liveMetrics.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/liveMetrics.js +75 -18
- package/dist/commonjs/metrics/quickpulse/liveMetrics.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/redirectUtils.d.ts +28 -0
- package/dist/commonjs/metrics/quickpulse/redirectUtils.d.ts.map +1 -0
- package/dist/commonjs/metrics/quickpulse/redirectUtils.js +80 -0
- package/dist/commonjs/metrics/quickpulse/redirectUtils.js.map +1 -0
- package/dist/commonjs/metrics/quickpulse/utils.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/utils.js.map +1 -1
- package/dist/commonjs/metrics/standardMetrics.js.map +1 -1
- package/dist/commonjs/shared/config.d.ts.map +1 -1
- package/dist/commonjs/shared/config.js +1 -0
- package/dist/commonjs/shared/config.js.map +1 -1
- package/dist/commonjs/shared/logging/diagFileConsoleLogger.d.ts +1 -0
- package/dist/commonjs/shared/logging/diagFileConsoleLogger.d.ts.map +1 -1
- package/dist/commonjs/shared/logging/diagFileConsoleLogger.js +13 -12
- package/dist/commonjs/shared/logging/diagFileConsoleLogger.js.map +1 -1
- package/dist/commonjs/traces/handler.d.ts +12 -0
- package/dist/commonjs/traces/handler.d.ts.map +1 -1
- package/dist/commonjs/traces/handler.js +30 -1
- package/dist/commonjs/traces/handler.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/types.d.ts +11 -1
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +47 -3
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/utils/azureSdkTracingBridge.d.ts +18 -0
- package/dist/commonjs/utils/azureSdkTracingBridge.d.ts.map +1 -0
- package/dist/commonjs/utils/azureSdkTracingBridge.js +35 -0
- package/dist/commonjs/utils/azureSdkTracingBridge.js.map +1 -0
- package/dist/commonjs/utils/common.d.ts +10 -0
- package/dist/commonjs/utils/common.d.ts.map +1 -1
- package/dist/commonjs/utils/common.js +16 -0
- package/dist/commonjs/utils/common.js.map +1 -1
- package/dist/commonjs/utils/logUtils.d.ts +5 -0
- package/dist/commonjs/utils/logUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/logUtils.js +8 -0
- package/dist/commonjs/utils/logUtils.js.map +1 -1
- package/dist/commonjs/utils/opentelemetryInstrumentationPatcher.d.ts.map +1 -1
- package/dist/commonjs/utils/opentelemetryInstrumentationPatcher.js +3 -2
- package/dist/commonjs/utils/opentelemetryInstrumentationPatcher.js.map +1 -1
- package/dist/commonjs/utils/statsbeat.d.ts.map +1 -1
- package/dist/commonjs/utils/statsbeat.js +35 -30
- package/dist/commonjs/utils/statsbeat.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +20 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logs/batchLogRecordProcessor.js +1 -1
- package/dist/esm/logs/batchLogRecordProcessor.js.map +1 -1
- package/dist/esm/logs/handler.d.ts +3 -0
- package/dist/esm/logs/handler.d.ts.map +1 -1
- package/dist/esm/logs/handler.js +23 -3
- package/dist/esm/logs/handler.js.map +1 -1
- package/dist/esm/metrics/handler.d.ts.map +1 -1
- package/dist/esm/metrics/handler.js +2 -3
- package/dist/esm/metrics/handler.js.map +1 -1
- package/dist/esm/metrics/quickpulse/credentialUtils.d.ts +16 -0
- package/dist/esm/metrics/quickpulse/credentialUtils.d.ts.map +1 -0
- package/dist/esm/metrics/quickpulse/credentialUtils.js +45 -0
- package/dist/esm/metrics/quickpulse/credentialUtils.js.map +1 -0
- package/dist/esm/metrics/quickpulse/export/sender.d.ts +10 -0
- package/dist/esm/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.js +37 -8
- package/dist/esm/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/esm/metrics/quickpulse/filtering/filter.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/filtering/filter.js +2 -5
- package/dist/esm/metrics/quickpulse/filtering/filter.js.map +1 -1
- package/dist/esm/metrics/quickpulse/liveMetrics.d.ts +4 -2
- package/dist/esm/metrics/quickpulse/liveMetrics.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/liveMetrics.js +75 -18
- package/dist/esm/metrics/quickpulse/liveMetrics.js.map +1 -1
- package/dist/esm/metrics/quickpulse/redirectUtils.d.ts +28 -0
- package/dist/esm/metrics/quickpulse/redirectUtils.d.ts.map +1 -0
- package/dist/esm/metrics/quickpulse/redirectUtils.js +76 -0
- package/dist/esm/metrics/quickpulse/redirectUtils.js.map +1 -0
- package/dist/esm/metrics/quickpulse/utils.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/utils.js.map +1 -1
- package/dist/esm/metrics/standardMetrics.js.map +1 -1
- package/dist/esm/shared/config.d.ts.map +1 -1
- package/dist/esm/shared/config.js +1 -0
- package/dist/esm/shared/config.js.map +1 -1
- package/dist/esm/shared/logging/diagFileConsoleLogger.d.ts +1 -0
- package/dist/esm/shared/logging/diagFileConsoleLogger.d.ts.map +1 -1
- package/dist/esm/shared/logging/diagFileConsoleLogger.js +13 -12
- package/dist/esm/shared/logging/diagFileConsoleLogger.js.map +1 -1
- package/dist/esm/traces/handler.d.ts +12 -0
- package/dist/esm/traces/handler.d.ts.map +1 -1
- package/dist/esm/traces/handler.js +29 -1
- package/dist/esm/traces/handler.js.map +1 -1
- package/dist/esm/types.d.ts +11 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +46 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/azureSdkTracingBridge.d.ts +18 -0
- package/dist/esm/utils/azureSdkTracingBridge.d.ts.map +1 -0
- package/dist/esm/utils/azureSdkTracingBridge.js +34 -0
- package/dist/esm/utils/azureSdkTracingBridge.js.map +1 -0
- package/dist/esm/utils/common.d.ts +10 -0
- package/dist/esm/utils/common.d.ts.map +1 -1
- package/dist/esm/utils/common.js +14 -0
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/logUtils.d.ts +5 -0
- package/dist/esm/utils/logUtils.d.ts.map +1 -1
- package/dist/esm/utils/logUtils.js +7 -0
- package/dist/esm/utils/logUtils.js.map +1 -1
- package/dist/esm/utils/opentelemetryInstrumentationPatcher.d.ts.map +1 -1
- package/dist/esm/utils/opentelemetryInstrumentationPatcher.js +3 -2
- package/dist/esm/utils/opentelemetryInstrumentationPatcher.js.map +1 -1
- package/dist/esm/utils/statsbeat.d.ts.map +1 -1
- package/dist/esm/utils/statsbeat.js +36 -31
- package/dist/esm/utils/statsbeat.js.map +1 -1
- package/package.json +41 -30
package/README.md
CHANGED
|
@@ -111,6 +111,8 @@ const options: AzureMonitorOpenTelemetryOptions = {
|
|
|
111
111
|
// Instrumentations generating logs
|
|
112
112
|
bunyan: { enabled: true },
|
|
113
113
|
winston: { enabled: true },
|
|
114
|
+
// Console log collection is opt-in (disabled by default)
|
|
115
|
+
console: { enabled: false },
|
|
114
116
|
},
|
|
115
117
|
enableLiveMetrics: true,
|
|
116
118
|
enableStandardMetrics: true,
|
|
@@ -161,7 +163,8 @@ useAzureMonitor(options);
|
|
|
161
163
|
redis: { enabled: true },
|
|
162
164
|
redis4: { enabled: true },
|
|
163
165
|
bunyan: { enabled: false },
|
|
164
|
-
winston: { enabled: false }
|
|
166
|
+
winston: { enabled: false },
|
|
167
|
+
console: { enabled: false }
|
|
165
168
|
}
|
|
166
169
|
</code></pre>
|
|
167
170
|
</td>
|
|
@@ -273,6 +276,10 @@ The following OpenTelemetry Instrumentation libraries are included as part of Az
|
|
|
273
276
|
|
|
274
277
|
- [Winston](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-winston)
|
|
275
278
|
|
|
279
|
+
- [Console](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-console) (disabled by default; enable with `instrumentationOptions: { console: { enabled: true } }`)
|
|
280
|
+
|
|
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.
|
|
282
|
+
|
|
276
283
|
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.
|
|
277
284
|
|
|
278
285
|
```ts snippet:ReadmeSampleCustomInstrumentation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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;AAwBpB,YAAY,EAAE,gCAAgC,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,CAAC;AA4BlG;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gCAAgC,GAAG,IAAI,CA0GhF;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
|
@@ -17,7 +17,9 @@ const browserSdkLoader_js_1 = require("./browserSdkLoader/browserSdkLoader.js");
|
|
|
17
17
|
const utils_js_1 = require("./metrics/quickpulse/utils.js");
|
|
18
18
|
const statsbeat_js_1 = require("./utils/statsbeat.js");
|
|
19
19
|
const opentelemetryInstrumentationPatcher_js_1 = require("./utils/opentelemetryInstrumentationPatcher.js");
|
|
20
|
+
const azureSdkTracingBridge_js_1 = require("./utils/azureSdkTracingBridge.js");
|
|
20
21
|
const common_js_1 = require("./utils/common.js");
|
|
22
|
+
const logUtils_js_1 = require("./utils/logUtils.js");
|
|
21
23
|
const index_js_3 = require("./shared/logging/index.js");
|
|
22
24
|
const types_js_2 = require("./types.js");
|
|
23
25
|
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
@@ -29,6 +31,8 @@ const CLOUD_RESOURCE_ID_ATTRIBUTE = "cloud.resource_id";
|
|
|
29
31
|
process.env["AZURE_MONITOR_DISTRO_VERSION"] = types_js_1.AZURE_MONITOR_OPENTELEMETRY_VERSION;
|
|
30
32
|
let sdk;
|
|
31
33
|
let browserSdkLoader;
|
|
34
|
+
// Track the global console patch because NodeSDK does not disable instrumentations.
|
|
35
|
+
let consoleInstrumentation;
|
|
32
36
|
/**
|
|
33
37
|
* Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.
|
|
34
38
|
*/
|
|
@@ -53,6 +57,8 @@ function sendAttachWarning() {
|
|
|
53
57
|
function useAzureMonitor(options) {
|
|
54
58
|
const config = new config_js_1.InternalConfig(options);
|
|
55
59
|
(0, opentelemetryInstrumentationPatcher_js_1.patchOpenTelemetryInstrumentationEnable)();
|
|
60
|
+
// Omit disabled log instrumentations from Statsbeat.
|
|
61
|
+
const logInstrumentationsEnabled = !(0, logUtils_js_1.isLogCollectionDisabled)();
|
|
56
62
|
const statsbeatInstrumentations = {
|
|
57
63
|
// Instrumentations
|
|
58
64
|
azureSdk: config.instrumentationOptions?.azureSdk?.enabled,
|
|
@@ -60,8 +66,9 @@ function useAzureMonitor(options) {
|
|
|
60
66
|
mySql: config.instrumentationOptions?.mySql?.enabled,
|
|
61
67
|
postgreSql: config.instrumentationOptions?.postgreSql?.enabled,
|
|
62
68
|
redis: config.instrumentationOptions?.redis?.enabled,
|
|
63
|
-
bunyan: config.instrumentationOptions?.bunyan?.enabled,
|
|
64
|
-
winston: config.instrumentationOptions?.winston?.enabled,
|
|
69
|
+
bunyan: logInstrumentationsEnabled && config.instrumentationOptions?.bunyan?.enabled,
|
|
70
|
+
winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,
|
|
71
|
+
console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,
|
|
65
72
|
};
|
|
66
73
|
// Check if the AKS resource detector successfully populated specific resource attributes
|
|
67
74
|
// (k8s.cluster.name or cloud.resource_id) beyond the basic cloud.platform/cloud.provider
|
|
@@ -84,6 +91,9 @@ function useAzureMonitor(options) {
|
|
|
84
91
|
api_1.metrics.disable();
|
|
85
92
|
api_1.trace.disable();
|
|
86
93
|
api_logs_1.logs.disable();
|
|
94
|
+
// Restore any console patch from the previous initialization.
|
|
95
|
+
consoleInstrumentation?.disable();
|
|
96
|
+
consoleInstrumentation = undefined;
|
|
87
97
|
// Clear the entire OpenTelemetry API global state to avoid version conflicts.
|
|
88
98
|
// The disable() calls above remove individual providers but leave the `version` field
|
|
89
99
|
// on the global object intact. If a different version of @opentelemetry/api was loaded
|
|
@@ -92,7 +102,7 @@ function useAzureMonitor(options) {
|
|
|
92
102
|
// must match", resulting in Noop providers. Deleting the global object forces
|
|
93
103
|
// registerGlobal() to create a fresh one with the correct version.
|
|
94
104
|
const globalOpentelemetryApiKey = Symbol.for("opentelemetry.js.api.1");
|
|
95
|
-
|
|
105
|
+
Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);
|
|
96
106
|
// Create internal handlers
|
|
97
107
|
const metricHandler = new index_js_1.MetricHandler(config);
|
|
98
108
|
const traceHandler = new handler_js_1.TraceHandler(config, metricHandler);
|
|
@@ -100,6 +110,7 @@ function useAzureMonitor(options) {
|
|
|
100
110
|
const instrumentations = traceHandler
|
|
101
111
|
.getInstrumentations()
|
|
102
112
|
.concat(logHandler.getInstrumentations());
|
|
113
|
+
consoleInstrumentation = logHandler.getConsoleInstrumentation();
|
|
103
114
|
const resourceDetectorsList = (0, common_js_1.parseResourceDetectorsFromEnvVar)();
|
|
104
115
|
// Add extra SpanProcessors, and logRecordProcessors from user configuration
|
|
105
116
|
const spanProcessors = options?.spanProcessors || [];
|
|
@@ -135,6 +146,9 @@ function useAzureMonitor(options) {
|
|
|
135
146
|
(0, utils_js_1.setSdkPrefix)();
|
|
136
147
|
sendAttachWarning();
|
|
137
148
|
sdk.start();
|
|
149
|
+
// Eagerly install the Azure SDK tracing bridge in case @azure/core-tracing
|
|
150
|
+
// was loaded before useAzureMonitor() (the RITM hook misses it otherwise).
|
|
151
|
+
(0, azureSdkTracingBridge_js_1.ensureAzureSdkTracingBridge)();
|
|
138
152
|
}
|
|
139
153
|
/**
|
|
140
154
|
* Shutdown Azure Monitor Open Telemetry Distro
|
|
@@ -142,6 +156,9 @@ function useAzureMonitor(options) {
|
|
|
142
156
|
*/
|
|
143
157
|
function shutdownAzureMonitor() {
|
|
144
158
|
browserSdkLoader?.dispose();
|
|
159
|
+
// NodeSDK.shutdown() does not restore the global console.
|
|
160
|
+
consoleInstrumentation?.disable();
|
|
161
|
+
consoleInstrumentation = undefined;
|
|
145
162
|
return sdk?.shutdown();
|
|
146
163
|
}
|
|
147
164
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAqElC,0CA+FC;AAMD,oDAGC;AAOD,0CAEC;AApLD,4CAAoD;AACpD,sDAA+C;AAE/C,sDAAkD;AAElD,kDAAoD;AACpD,iDAAmD;AACnD,oDAAmD;AACnD,8CAA6C;AAQ7C,yCAGoB;AACpB,gFAA0E;AAC1E,4DAA6D;AAG7D,uDAAmD;AACnD,2GAAyG;AACzG,iDAAoF;AACpF,wDAAmD;AACnD,yCAAuD;AACvD,8EAAmF;AAEnF;;;GAGG;AACH,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAIxD,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,8CAAmC,CAAC;AAElF,IAAI,GAAY,CAAC;AACjB,IAAI,gBAA8C,CAAC;AAEnD;;GAEG;AACH,SAAS,iBAAiB;IACxB,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAyB,CAAC,KAAK,MAAM,IAAI,CAAC,IAAA,yBAAa,GAAE,EAAE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corporation.\n// Licensed under the MIT License.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\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 { isFunctionApp, parseResourceDetectorsFromEnvVar } from \"./utils/common.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\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 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: config.instrumentationOptions?.bunyan?.enabled,\n winston: config.instrumentationOptions?.winston?.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\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 delete (globalThis as Record<symbol, unknown>)[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\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\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 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;;AA0ElC,0CA0GC;AAMD,oDAMC;AAOD,0CAEC;AAvMD,4CAAoD;AACpD,sDAA+C;AAG/C,sDAAkD;AAElD,kDAAoD;AACpD,iDAAmD;AACnD,oDAAmD;AACnD,8CAA6C;AAQ7C,yCAGoB;AACpB,gFAA0E;AAC1E,4DAA6D;AAG7D,uDAAmD;AACnD,2GAAyG;AACzG,+EAA+E;AAC/E,iDAAoF;AACpF,qDAA8D;AAC9D,wDAAmD;AACnD,yCAAuD;AACvD,8EAAmF;AAEnF;;;GAGG;AACH,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAIxD,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC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B,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 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"]}
|
|
@@ -12,7 +12,7 @@ const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
|
12
12
|
class AzureBatchLogRecordProcessor extends sdk_logs_1.BatchLogRecordProcessor {
|
|
13
13
|
_options;
|
|
14
14
|
constructor(exporter, options) {
|
|
15
|
-
super(exporter);
|
|
15
|
+
super({ exporter });
|
|
16
16
|
this._options = options;
|
|
17
17
|
}
|
|
18
18
|
onEmit(logRecord) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchLogRecordProcessor.js","sourceRoot":"","sources":["../../../src/logs/batchLogRecordProcessor.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,4CAAgD;AAEhD,sDAAkE;AAElE;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,kCAAuB;IACtD,QAAQ,CAA2D;IAEpF,YACE,QAA2B,EAC3B,OAAiE;QAEjE,KAAK,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"batchLogRecordProcessor.js","sourceRoot":"","sources":["../../../src/logs/batchLogRecordProcessor.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,4CAAgD;AAEhD,sDAAkE;AAElE;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,kCAAuB;IACtD,QAAQ,CAA2D;IAEpF,YACE,QAA2B,EAC3B,OAAiE;QAEjE,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,MAAM,CAAC,SAAuB;QACnC,gCAAgC;QAChC,IAAI,IAAI,CAAC,QAAQ,CAAC,+BAA+B,EAAE,CAAC;YAClD,IAAI,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;gBAC1D,wEAAwE;gBACxE,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,KAAK,gBAAU,CAAC,OAAO,EAAE,CAAC;oBAC5D,oDAAoD;oBACpD,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;CACF;AAxBD,oEAwBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { TraceFlags } from \"@opentelemetry/api\";\nimport type { LogRecordExporter, SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { BatchLogRecordProcessor } from \"@opentelemetry/sdk-logs\";\n\n/**\n * Azure Monitor BatchLogRecord Processor.\n * @internal\n */\nexport class AzureBatchLogRecordProcessor extends BatchLogRecordProcessor {\n private readonly _options: { enableTraceBasedSamplingForLogs: boolean | undefined };\n\n constructor(\n exporter: LogRecordExporter,\n options: { enableTraceBasedSamplingForLogs: boolean | undefined },\n ) {\n super({ exporter });\n this._options = options;\n }\n\n public onEmit(logRecord: SdkLogRecord): void {\n // Trace based sampling for logs\n if (this._options.enableTraceBasedSamplingForLogs) {\n if (logRecord.spanContext && logRecord.spanContext.spanId) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n if (logRecord.spanContext.traceFlags !== TraceFlags.SAMPLED) {\n // Do not export log for spans that were sampled out\n return;\n }\n }\n }\n super.onEmit(logRecord);\n }\n}\n"]}
|
|
@@ -13,6 +13,7 @@ export declare class LogHandler {
|
|
|
13
13
|
private _metricHandler;
|
|
14
14
|
private _config;
|
|
15
15
|
private _instrumentations;
|
|
16
|
+
private _consoleInstrumentation;
|
|
16
17
|
/**
|
|
17
18
|
* Initializes a new instance of the TraceHandler class.
|
|
18
19
|
* @param _config - Distro configuration.
|
|
@@ -22,6 +23,8 @@ export declare class LogHandler {
|
|
|
22
23
|
getAzureLogRecordProcessor(): AzureLogRecordProcessor;
|
|
23
24
|
getBatchLogRecordProcessor(): BatchLogRecordProcessor;
|
|
24
25
|
getInstrumentations(): Instrumentation[];
|
|
26
|
+
/** Returns the console instrumentation for explicit lifecycle management. */
|
|
27
|
+
getConsoleInstrumentation(): Instrumentation | undefined;
|
|
25
28
|
/**
|
|
26
29
|
* Start auto collection of telemetry
|
|
27
30
|
*/
|
|
@@ -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;
|
|
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,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAIlE;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,cAAc,CAA0B;IAChD,OAAO,CAAC,wBAAwB,CAA0B;IAC1D,OAAO,CAAC,6BAA6B,CAA+B;IACpE,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,iBAAiB,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;CAmCpC"}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.LogHandler = void 0;
|
|
6
6
|
const monitor_opentelemetry_exporter_1 = require("@azure/monitor-opentelemetry-exporter");
|
|
7
7
|
const instrumentation_bunyan_1 = require("@opentelemetry/instrumentation-bunyan");
|
|
8
|
+
const instrumentation_console_1 = require("@opentelemetry/instrumentation-console");
|
|
8
9
|
const instrumentation_winston_1 = require("@opentelemetry/instrumentation-winston");
|
|
9
10
|
const logRecordProcessor_js_1 = require("./logRecordProcessor.js");
|
|
10
11
|
const batchLogRecordProcessor_js_1 = require("./batchLogRecordProcessor.js");
|
|
@@ -19,6 +20,7 @@ class LogHandler {
|
|
|
19
20
|
_metricHandler;
|
|
20
21
|
_config;
|
|
21
22
|
_instrumentations;
|
|
23
|
+
_consoleInstrumentation;
|
|
22
24
|
/**
|
|
23
25
|
* Initializes a new instance of the TraceHandler class.
|
|
24
26
|
* @param _config - Distro configuration.
|
|
@@ -44,23 +46,41 @@ class LogHandler {
|
|
|
44
46
|
getInstrumentations() {
|
|
45
47
|
return this._instrumentations;
|
|
46
48
|
}
|
|
49
|
+
/** Returns the console instrumentation for explicit lifecycle management. */
|
|
50
|
+
getConsoleInstrumentation() {
|
|
51
|
+
return this._consoleInstrumentation;
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* Start auto collection of telemetry
|
|
49
55
|
*/
|
|
50
56
|
_initializeInstrumentations() {
|
|
57
|
+
if ((0, logUtils_js_1.isLogCollectionDisabled)()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
51
60
|
const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;
|
|
61
|
+
const logSeverity = logLevelEnv ? (0, logUtils_js_1.logLevelToSeverityNumber)(logLevelEnv) : undefined;
|
|
52
62
|
if (this._config.instrumentationOptions.bunyan?.enabled) {
|
|
53
63
|
this._instrumentations.push(new instrumentation_bunyan_1.BunyanInstrumentation({
|
|
54
64
|
...this._config.instrumentationOptions.bunyan,
|
|
55
|
-
logSeverity
|
|
65
|
+
logSeverity,
|
|
56
66
|
}));
|
|
57
67
|
}
|
|
58
68
|
if (this._config.instrumentationOptions.winston?.enabled) {
|
|
59
69
|
this._instrumentations.push(new instrumentation_winston_1.WinstonInstrumentation({
|
|
60
70
|
...this._config.instrumentationOptions.winston,
|
|
61
|
-
logSeverity
|
|
71
|
+
logSeverity,
|
|
62
72
|
}));
|
|
63
73
|
}
|
|
74
|
+
if (this._config.instrumentationOptions.console?.enabled) {
|
|
75
|
+
// Defer patching until registration so construction preserves the original methods.
|
|
76
|
+
const consoleInstrumentation = new instrumentation_console_1.ConsoleInstrumentation({
|
|
77
|
+
...this._config.instrumentationOptions.console,
|
|
78
|
+
enabled: false,
|
|
79
|
+
logSeverity,
|
|
80
|
+
});
|
|
81
|
+
this._consoleInstrumentation = consoleInstrumentation;
|
|
82
|
+
this._instrumentations.push(consoleInstrumentation);
|
|
83
|
+
}
|
|
64
84
|
}
|
|
65
85
|
}
|
|
66
86
|
exports.LogHandler = LogHandler;
|
|
@@ -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;AAIhF,mEAAkE;AAClE,6EAA4E;AAC5E,
|
|
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,MAAsB,EAAE,aAA4B;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,IAAI,wDAAuB,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;QACtF,IAAI,CAAC,6BAA6B,GAAG,IAAI,yDAA4B,CAAC,IAAI,CAAC,cAAc,EAAE;YACzF,+BAA+B,EAAE,IAAI,CAAC,OAAO,CAAC,+BAA+B;SAC9E,CAAC,CAAC;QACH,IAAI,CAAC,wBAAwB,GAAG,IAAI,+CAAuB,CAAC,IAAI,CAAC,cAAc,CAA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;YACzD,oFAAoF;YACpF,MAAM,sBAAsB,GAAG,IAAI,gDAAsB,CAAC;gBACxD,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO;gBAC9C,OAAO,EAAE,KAAK;gBACd,WAAW;aACZ,CAAC,CAAC;YACH,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAjFD,gCAiFC","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 if (this._config.instrumentationOptions.console?.enabled) {\n // Defer patching until registration so construction preserves the original methods.\n const consoleInstrumentation = new ConsoleInstrumentation({\n ...this._config.instrumentationOptions.console,\n enabled: false,\n logSeverity,\n });\n this._consoleInstrumentation = consoleInstrumentation;\n this._instrumentations.push(consoleInstrumentation);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/metrics/handler.ts"],"names":[],"m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EG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,gBAAgB,CAAC,CAAkB;IAC3C,OAAO,CAAC,oBAAoB,CAAC,CAA4B;IACzD,OAAO,CAAC,YAAY,CAAC,CAAc;IACnC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,MAAM,CAAgB;IAE9B;;;;OAIG;gBACS,MAAM,EAAE,cAAc;IAmD3B,eAAe,IAAI,6BAA6B;IAIhD,QAAQ,IAAI,WAAW,EAAE;IAIzB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIrC,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAMpC,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAM/C;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAKvC"}
|
|
@@ -120,11 +120,10 @@ class MetricHandler {
|
|
|
120
120
|
/**
|
|
121
121
|
* Shutdown handler
|
|
122
122
|
*/
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
124
123
|
async shutdown() {
|
|
125
124
|
this._standardMetrics?.shutdown();
|
|
126
|
-
this._liveMetrics?.shutdown();
|
|
127
|
-
this._performanceCounters?.shutdown();
|
|
125
|
+
await this._liveMetrics?.shutdown();
|
|
126
|
+
await this._performanceCounters?.shutdown();
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
129
|
exports.MetricHandler = MetricHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/metrics/handler.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,0FAAmF;AAMnF,4DAIoC;AAGpC,6DAAuD;AAEvD,yCAAiG;AACjG,gEAA0D;AAC1D,qEAAqE;AACrE,yDAAoD;AAIpD,MAAM,qCAAqC,GACzC,0DAA0D,C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,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAEM,SAAS,CAAC,SAAuB;QACtC,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACxC,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,4DAA4D;IACrD,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,gBAAgB,EAAE,QAAQ,EAAE,CAAC;QAClC,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,oBAAoB,EAAE,QAAQ,EAAE,CAAC;IACxC,CAAC;CACF;AAlGD,sCAkGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n AggregationOption,\n PeriodicExportingMetricReaderOptions,\n ViewOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport {\n AggregationType,\n InstrumentType,\n PeriodicExportingMetricReader,\n} from \"@opentelemetry/sdk-metrics\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport type { InternalConfig } from \"../shared/config.js\";\nimport { StandardMetrics } from \"./standardMetrics.js\";\nimport type { ReadableSpan, Span } from \"@opentelemetry/sdk-trace-base\";\nimport { APPLICATION_INSIGHTS_NO_STANDARD_METRICS, HISTOGRAM_AGGREGATION_MAP } from \"./types.js\";\nimport { LiveMetrics } from \"./quickpulse/liveMetrics.js\";\nimport { PerformanceCounterMetrics } from \"./performanceCounters.js\";\nimport { Logger } from \"../shared/logging/index.js\";\n\ntype MetricExporterOptions = ConstructorParameters<typeof AzureMonitorMetricExporter>[0];\n\nconst DEFAULT_HISTOGRAM_AGGREGATION_ENV_VAR =\n \"OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION\";\n\nfunction resolveHistogramAggregationFromEnv(): AggregationOption | undefined {\n const envValue = process.env[DEFAULT_HISTOGRAM_AGGREGATION_ENV_VAR];\n if (!envValue) {\n return undefined;\n }\n\n const normalized = envValue.trim().toLowerCase();\n const aggregation = HISTOGRAM_AGGREGATION_MAP[normalized];\n if (aggregation) {\n return aggregation;\n }\n\n const validValues = Object.keys(HISTOGRAM_AGGREGATION_MAP)\n .map((v) => `'${v}'`)\n .join(\" and \");\n Logger.getInstance().warn(\n `${DEFAULT_HISTOGRAM_AGGREGATION_ENV_VAR} has unsupported value '${envValue}'. Supported values are ${validValues}.`,\n );\n return undefined;\n}\n\nclass AzureMonitorMetricExporterWithAggregation extends AzureMonitorMetricExporter {\n private _histogramAggregation?: AggregationOption;\n\n constructor(options: MetricExporterOptions, histogramAggregation?: AggregationOption) {\n super(options);\n this._histogramAggregation = histogramAggregation;\n }\n\n public selectAggregation(instrumentType: InstrumentType): AggregationOption {\n if (instrumentType === InstrumentType.HISTOGRAM && this._histogramAggregation) {\n return this._histogramAggregation;\n }\n\n return { type: AggregationType.DEFAULT };\n }\n}\n\n/**\n * Azure Monitor OpenTelemetry Metric Handler\n */\nexport class MetricHandler {\n private _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _standardMetrics?: StandardMetrics;\n private _performanceCounters?: PerformanceCounterMetrics;\n private _liveMetrics?: LiveMetrics;\n private _config: InternalConfig;\n private _views: ViewOptions[];\n\n /**\n * Initializes a new instance of the MetricHandler class.\n * @param config - Distro configuration.\n * @param options - Metric Handler options.\n */\n constructor(config: InternalConfig) {\n const defaultInterval = 60000;\n this._config = config;\n // Adding Views of instrumentations will allow customer to add Metric Readers after, and get access to previously created metrics using the views shared state\n this._views = [];\n if (config.instrumentationOptions.azureSdk?.enabled) {\n this._views.push({ meterName: \"@azure/opentelemetry-instrumentation-azure-sdk\" });\n }\n if (config.instrumentationOptions.http?.enabled) {\n this._views.push({ meterName: \"@azure/opentelemetry-instrumentation-http\" });\n }\n if (config.instrumentationOptions.mongoDb?.enabled) {\n this._views.push({ meterName: \"@azure/opentelemetry-instrumentation-mongodb\" });\n }\n if (config.instrumentationOptions.mySql?.enabled) {\n this._views.push({ meterName: \"@opentelemetry/instrumentation-mysql\" });\n }\n if (config.instrumentationOptions.postgreSql?.enabled) {\n this._views.push({ meterName: \"@opentelemetry/instrumentation-pg\" });\n }\n if (\n config.instrumentationOptions.redis?.enabled ||\n config.instrumentationOptions.redis4?.enabled\n ) {\n this._views.push({ meterName: \"@opentelemetry/instrumentation-redis\" });\n }\n const histogramAggregation = resolveHistogramAggregationFromEnv();\n this._azureExporter = new AzureMonitorMetricExporterWithAggregation(\n this._config.azureMonitorExporterOptions,\n histogramAggregation,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this._azureExporter as any,\n exportIntervalMillis: this._config.metricExportIntervalMillis || defaultInterval,\n };\n this._metricReader = new PeriodicExportingMetricReader(metricReaderOptions);\n\n if (\n this._config.enableStandardMetrics &&\n !process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]\n ) {\n this._standardMetrics = new StandardMetrics(this._config);\n }\n if (this._config.enableLiveMetrics) {\n this._liveMetrics = new LiveMetrics(this._config);\n }\n if (this._config.enablePerformanceCounters) {\n this._performanceCounters = new PerformanceCounterMetrics(this._config);\n }\n }\n\n public getMetricReader(): PeriodicExportingMetricReader {\n return this._metricReader;\n }\n\n public getViews(): ViewOptions[] {\n return this._views;\n }\n\n public markSpanAsProcessed(span: Span): void {\n this._standardMetrics?.markSpanAsProcessed(span);\n }\n\n public recordSpan(span: ReadableSpan): void {\n this._standardMetrics?.recordSpan(span);\n this._liveMetrics?.recordSpan(span);\n this._performanceCounters?.recordSpan(span);\n }\n\n public recordLog(logRecord: SdkLogRecord): void {\n this._standardMetrics?.recordLog(logRecord);\n this._liveMetrics?.recordLog(logRecord);\n this._performanceCounters?.recordLog(logRecord);\n }\n\n /**\n * Shutdown handler\n */\n // eslint-disable-next-line @typescript-eslint/require-await\n public async shutdown(): Promise<void> {\n this._standardMetrics?.shutdown();\n this._liveMetrics?.shutdown();\n this._performanceCounters?.shutdown();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/metrics/handler.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,0FAAmF;AAMnF,4DAIoC;AAGpC,6DAAuD;AAEvD,yCAAiG;AACjG,gEAA0D;AAC1D,qEAAqE;AACrE,yDAAoD;AAIpD,MAAM,qCAAqC,GACzC,0DAA0D,CAAC;AAE7D,SAAS,kCAAkC;IACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IACpE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACjD,MAAM,WAAW,GAAG,oCAAyB,CAAC,UAAU,CAAC,CAAC;IAC1D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,oCAAyB,CAAC;SACvD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;SACpB,IAAI,CAAC,OAAO,CAAC,CAAC;IACjB,iBAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CACvB,GAAG,qCAAqC,2BAA2B,QAAQ,2BAA2B,WAAW,GAAG,CACrH,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,yCAA0C,SAAQ,2DAA0B;IACxE,qBAAqB,CAAqB;IAElD,YAAY,OA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ACD,IAAI,IAAI,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC;YAC3C,IAAI,CAAC,oBAAoB,GAAG,IAAI,kDAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEM,mBAAmB,CAAC,IAAU;QACnC,IAAI,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAEM,UAAU,CAAC,IAAkB;QAClC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAEM,SAAS,CAAC,SAAuB;QACtC,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACxC,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,gBAAgB,EAAE,QAAQ,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,CAAC,oBAAoB,EAAE,QAAQ,EAAE,CAAC;IAC9C,CAAC;CACF;AAjGD,sCAiGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n AggregationOption,\n PeriodicExportingMetricReaderOptions,\n ViewOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport {\n AggregationType,\n InstrumentType,\n PeriodicExportingMetricReader,\n} from \"@opentelemetry/sdk-metrics\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport type { InternalConfig } from \"../shared/config.js\";\nimport { StandardMetrics } from \"./standardMetrics.js\";\nimport type { ReadableSpan, Span } from \"@opentelemetry/sdk-trace-base\";\nimport { APPLICATION_INSIGHTS_NO_STANDARD_METRICS, HISTOGRAM_AGGREGATION_MAP } from \"./types.js\";\nimport { LiveMetrics } from \"./quickpulse/liveMetrics.js\";\nimport { PerformanceCounterMetrics } from \"./performanceCounters.js\";\nimport { Logger } from \"../shared/logging/index.js\";\n\ntype MetricExporterOptions = ConstructorParameters<typeof AzureMonitorMetricExporter>[0];\n\nconst DEFAULT_HISTOGRAM_AGGREGATION_ENV_VAR =\n \"OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION\";\n\nfunction resolveHistogramAggregationFromEnv(): AggregationOption | undefined {\n const envValue = process.env[DEFAULT_HISTOGRAM_AGGREGATION_ENV_VAR];\n if (!envValue) {\n return undefined;\n }\n\n const normalized = envValue.trim().toLowerCase();\n const aggregation = HISTOGRAM_AGGREGATION_MAP[normalized];\n if (aggregation) {\n return aggregation;\n }\n\n const validValues = Object.keys(HISTOGRAM_AGGREGATION_MAP)\n .map((v) => `'${v}'`)\n .join(\" and \");\n Logger.getInstance().warn(\n `${DEFAULT_HISTOGRAM_AGGREGATION_ENV_VAR} has unsupported value '${envValue}'. Supported values are ${validValues}.`,\n );\n return undefined;\n}\n\nclass AzureMonitorMetricExporterWithAggregation extends AzureMonitorMetricExporter {\n private _histogramAggregation?: AggregationOption;\n\n constructor(options: MetricExporterOptions, histogramAggregation?: AggregationOption) {\n super(options);\n this._histogramAggregation = histogramAggregation;\n }\n\n public selectAggregation(instrumentType: InstrumentType): AggregationOption {\n if (instrumentType === InstrumentType.HISTOGRAM && this._histogramAggregation) {\n return this._histogramAggregation;\n }\n\n return { type: AggregationType.DEFAULT };\n }\n}\n\n/**\n * Azure Monitor OpenTelemetry Metric Handler\n */\nexport class MetricHandler {\n private _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _standardMetrics?: StandardMetrics;\n private _performanceCounters?: PerformanceCounterMetrics;\n private _liveMetrics?: LiveMetrics;\n private _config: InternalConfig;\n private _views: ViewOptions[];\n\n /**\n * Initializes a new instance of the MetricHandler class.\n * @param config - Distro configuration.\n * @param options - Metric Handler options.\n */\n constructor(config: InternalConfig) {\n const defaultInterval = 60000;\n this._config = config;\n // Adding Views of instrumentations will allow customer to add Metric Readers after, and get access to previously created metrics using the views shared state\n this._views = [];\n if (config.instrumentationOptions.azureSdk?.enabled) {\n this._views.push({ meterName: \"@azure/opentelemetry-instrumentation-azure-sdk\" });\n }\n if (config.instrumentationOptions.http?.enabled) {\n this._views.push({ meterName: \"@azure/opentelemetry-instrumentation-http\" });\n }\n if (config.instrumentationOptions.mongoDb?.enabled) {\n this._views.push({ meterName: \"@azure/opentelemetry-instrumentation-mongodb\" });\n }\n if (config.instrumentationOptions.mySql?.enabled) {\n this._views.push({ meterName: \"@opentelemetry/instrumentation-mysql\" });\n }\n if (config.instrumentationOptions.postgreSql?.enabled) {\n this._views.push({ meterName: \"@opentelemetry/instrumentation-pg\" });\n }\n if (\n config.instrumentationOptions.redis?.enabled ||\n config.instrumentationOptions.redis4?.enabled\n ) {\n this._views.push({ meterName: \"@opentelemetry/instrumentation-redis\" });\n }\n const histogramAggregation = resolveHistogramAggregationFromEnv();\n this._azureExporter = new AzureMonitorMetricExporterWithAggregation(\n this._config.azureMonitorExporterOptions,\n histogramAggregation,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this._azureExporter,\n exportIntervalMillis: this._config.metricExportIntervalMillis || defaultInterval,\n };\n this._metricReader = new PeriodicExportingMetricReader(metricReaderOptions);\n\n if (\n this._config.enableStandardMetrics &&\n !process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]\n ) {\n this._standardMetrics = new StandardMetrics(this._config);\n }\n if (this._config.enableLiveMetrics) {\n this._liveMetrics = new LiveMetrics(this._config);\n }\n if (this._config.enablePerformanceCounters) {\n this._performanceCounters = new PerformanceCounterMetrics(this._config);\n }\n }\n\n public getMetricReader(): PeriodicExportingMetricReader {\n return this._metricReader;\n }\n\n public getViews(): ViewOptions[] {\n return this._views;\n }\n\n public markSpanAsProcessed(span: Span): void {\n this._standardMetrics?.markSpanAsProcessed(span);\n }\n\n public recordSpan(span: ReadableSpan): void {\n this._standardMetrics?.recordSpan(span);\n this._liveMetrics?.recordSpan(span);\n this._performanceCounters?.recordSpan(span);\n }\n\n public recordLog(logRecord: SdkLogRecord): void {\n this._standardMetrics?.recordLog(logRecord);\n this._liveMetrics?.recordLog(logRecord);\n this._performanceCounters?.recordLog(logRecord);\n }\n\n /**\n * Shutdown handler\n */\n public async shutdown(): Promise<void> {\n this._standardMetrics?.shutdown();\n await this._liveMetrics?.shutdown();\n await this._performanceCounters?.shutdown();\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ManagedIdentityCredential } from "@azure/identity";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves an Azure Active Directory (AAD) credential from the
|
|
4
|
+
* `APPLICATIONINSIGHTS_AUTHENTICATION_STRING` environment variable (the App Service /
|
|
5
|
+
* Functions convention) which has the form `Authorization=AAD;ClientId=<client-id>`.
|
|
6
|
+
* A `ManagedIdentityCredential` is created using the supplied `ClientId` when present.
|
|
7
|
+
*
|
|
8
|
+
* Returns `undefined` when the variable is absent, malformed, or does not request AAD
|
|
9
|
+
* authorization. This is intended as a fallback for callers that were not given an
|
|
10
|
+
* explicit credential.
|
|
11
|
+
*
|
|
12
|
+
* @returns A `ManagedIdentityCredential`, or `undefined` when none applies.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAuthenticationCredentialFromEnv(): ManagedIdentityCredential | undefined;
|
|
16
|
+
//# sourceMappingURL=credentialUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentialUtils.d.ts","sourceRoot":"","sources":["../../../../src/metrics/quickpulse/credentialUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAI5D;;;;;;;;;;;;GAYG;AACH,wBAAgB,kCAAkC,IAAI,yBAAyB,GAAG,SAAS,CA2B1F"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getAuthenticationCredentialFromEnv = getAuthenticationCredentialFromEnv;
|
|
6
|
+
const identity_1 = require("@azure/identity");
|
|
7
|
+
const types_js_1 = require("../../types.js");
|
|
8
|
+
const logger_js_1 = require("../../shared/logging/logger.js");
|
|
9
|
+
/**
|
|
10
|
+
* Resolves an Azure Active Directory (AAD) credential from the
|
|
11
|
+
* `APPLICATIONINSIGHTS_AUTHENTICATION_STRING` environment variable (the App Service /
|
|
12
|
+
* Functions convention) which has the form `Authorization=AAD;ClientId=<client-id>`.
|
|
13
|
+
* A `ManagedIdentityCredential` is created using the supplied `ClientId` when present.
|
|
14
|
+
*
|
|
15
|
+
* Returns `undefined` when the variable is absent, malformed, or does not request AAD
|
|
16
|
+
* authorization. This is intended as a fallback for callers that were not given an
|
|
17
|
+
* explicit credential.
|
|
18
|
+
*
|
|
19
|
+
* @returns A `ManagedIdentityCredential`, or `undefined` when none applies.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
function getAuthenticationCredentialFromEnv() {
|
|
23
|
+
const authString = process.env[types_js_1.APPLICATIONINSIGHTS_AUTHENTICATION_STRING];
|
|
24
|
+
if (!authString) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const authStringMap = new Map();
|
|
29
|
+
for (const pair of authString.split(";")) {
|
|
30
|
+
const keyValue = pair.split("=");
|
|
31
|
+
if (keyValue.length !== 2) {
|
|
32
|
+
throw new Error(`Invalid key-value pair: "${pair}"`);
|
|
33
|
+
}
|
|
34
|
+
authStringMap.set(keyValue[0].toLowerCase(), keyValue[1]);
|
|
35
|
+
}
|
|
36
|
+
if (authStringMap.get("authorization") === "AAD") {
|
|
37
|
+
const clientId = authStringMap.get("clientid");
|
|
38
|
+
return clientId
|
|
39
|
+
? new identity_1.ManagedIdentityCredential({ clientId })
|
|
40
|
+
: new identity_1.ManagedIdentityCredential();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
logger_js_1.Logger.getInstance().error(`APPLICATIONINSIGHTS_AUTHENTICATION_STRING, ${authString}, has invalid format:`, error);
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=credentialUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentialUtils.js","sourceRoot":"","sources":["../../../../src/metrics/quickpulse/credentialUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAmBlC,gFA2BC;AA5CD,8CAA4D;AAC5D,6CAA2E;AAC3E,8DAAwD;AAExD;;;;;;;;;;;;GAYG;AACH,SAAgB,kCAAkC;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,oDAAyC,CAAC,CAAC;IAC1E,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QAChD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACjC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,GAAG,CAAC,CAAC;YACvD,CAAC;YACD,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,KAAK,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC/C,OAAO,QAAQ;gBACb,CAAC,CAAC,IAAI,oCAAyB,CAAC,EAAE,QAAQ,EAAE,CAAC;gBAC7C,CAAC,CAAC,IAAI,oCAAyB,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,kBAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CACxB,8CAA8C,UAAU,uBAAuB,EAC/E,KAAK,CACN,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { ManagedIdentityCredential } from \"@azure/identity\";\nimport { APPLICATIONINSIGHTS_AUTHENTICATION_STRING } from \"../../types.js\";\nimport { Logger } from \"../../shared/logging/logger.js\";\n\n/**\n * Resolves an Azure Active Directory (AAD) credential from the\n * `APPLICATIONINSIGHTS_AUTHENTICATION_STRING` environment variable (the App Service /\n * Functions convention) which has the form `Authorization=AAD;ClientId=<client-id>`.\n * A `ManagedIdentityCredential` is created using the supplied `ClientId` when present.\n *\n * Returns `undefined` when the variable is absent, malformed, or does not request AAD\n * authorization. This is intended as a fallback for callers that were not given an\n * explicit credential.\n *\n * @returns A `ManagedIdentityCredential`, or `undefined` when none applies.\n * @internal\n */\nexport function getAuthenticationCredentialFromEnv(): ManagedIdentityCredential | undefined {\n const authString = process.env[APPLICATIONINSIGHTS_AUTHENTICATION_STRING];\n if (!authString) {\n return undefined;\n }\n try {\n const authStringMap = new Map<string, string>();\n for (const pair of authString.split(\";\")) {\n const keyValue = pair.split(\"=\");\n if (keyValue.length !== 2) {\n throw new Error(`Invalid key-value pair: \"${pair}\"`);\n }\n authStringMap.set(keyValue[0].toLowerCase(), keyValue[1]);\n }\n if (authStringMap.get(\"authorization\") === \"AAD\") {\n const clientId = authStringMap.get(\"clientid\");\n return clientId\n ? new ManagedIdentityCredential({ clientId })\n : new ManagedIdentityCredential();\n }\n } catch (error) {\n Logger.getInstance().error(\n `APPLICATIONINSIGHTS_AUTHENTICATION_STRING, ${authString}, has invalid format:`,\n error,\n );\n }\n return undefined;\n}\n"]}
|
|
@@ -41,6 +41,16 @@ export declare class QuickpulseSender {
|
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
43
|
publish(optionalParams: PublishOptionalParams): Promise<QuickpulseResponse | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* Apply a server-issued Live Metrics redirect (`x-ms-qps-service-endpoint-redirect-v2`) by
|
|
46
|
+
* re-pointing the underlying client at the new host.
|
|
47
|
+
*
|
|
48
|
+
* Cross-origin redirects are refused (no state mutated) when the target is neither the configured
|
|
49
|
+
* Live Metrics host nor under a known Azure Monitor ingestion domain suffix. Refusing them is
|
|
50
|
+
* required to prevent an attacker-controlled redirect from causing the bearer auth policy to
|
|
51
|
+
* attach a freshly-signed AAD token (scope `https://monitor.azure.com/.default`) — and the
|
|
52
|
+
* telemetry body — to a foreign host on the next ping/publish call.
|
|
53
|
+
*/
|
|
44
54
|
handlePermanentRedirect(location: string | undefined): void;
|
|
45
55
|
}
|
|
46
56
|
//# sourceMappingURL=sender.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EACV,0BAA0B,EAC1B,qBAAqB,EAErB,2BAA2B,EAC5B,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EACV,0BAA0B,EAC1B,qBAAqB,EAErB,2BAA2B,EAC5B,MAAM,6BAA6B,CAAC;AAMrC;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,2BAA2B;IACrE,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B;IAC1B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,6CAA6C;IAC7C,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAC1C,yCAAyC;IACzC,+BAA+B,CAAC,EAAE,MAAM,CAAC;CAC1C;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,gBAAgB,CAAW;gBAEvB,OAAO,EAAE;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE,eAAe,CAAC;QAC7B,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACtC;IAyBD,OAAO,CAAC,sBAAsB;IAO9B;;;OAGG;IACG,YAAY,CAChB,cAAc,EAAE,0BAA0B,GACzC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAuB1C;;;OAGG;IACG,OAAO,CAAC,cAAc,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAqB7F;;;;;;;;;OASG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAkC5D"}
|
|
@@ -8,6 +8,7 @@ const url_1 = tslib_1.__importDefault(require("url"));
|
|
|
8
8
|
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
|
|
9
9
|
const api_1 = require("@opentelemetry/api");
|
|
10
10
|
const index_js_1 = require("../../../generated/index.js");
|
|
11
|
+
const redirectUtils_js_1 = require("../redirectUtils.js");
|
|
11
12
|
const applicationInsightsResource = "https://monitor.azure.com/.default";
|
|
12
13
|
/**
|
|
13
14
|
* Quickpulse sender class
|
|
@@ -99,17 +100,45 @@ class QuickpulseSender {
|
|
|
99
100
|
}
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Apply a server-issued Live Metrics redirect (`x-ms-qps-service-endpoint-redirect-v2`) by
|
|
105
|
+
* re-pointing the underlying client at the new host.
|
|
106
|
+
*
|
|
107
|
+
* Cross-origin redirects are refused (no state mutated) when the target is neither the configured
|
|
108
|
+
* Live Metrics host nor under a known Azure Monitor ingestion domain suffix. Refusing them is
|
|
109
|
+
* required to prevent an attacker-controlled redirect from causing the bearer auth policy to
|
|
110
|
+
* attach a freshly-signed AAD token (scope `https://monitor.azure.com/.default`) — and the
|
|
111
|
+
* telemetry body — to a foreign host on the next ping/publish call.
|
|
112
|
+
*/
|
|
102
113
|
handlePermanentRedirect(location) {
|
|
103
114
|
if (location) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
let locUrl;
|
|
116
|
+
try {
|
|
117
|
+
locUrl = new url_1.default.URL(location);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!locUrl.host) {
|
|
123
|
+
return;
|
|
112
124
|
}
|
|
125
|
+
let currentHost = "";
|
|
126
|
+
try {
|
|
127
|
+
currentHost = new url_1.default.URL(this.endpointUrl).host;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
currentHost = "";
|
|
131
|
+
}
|
|
132
|
+
if (!(0, redirectUtils_js_1.isSameRegisteredDomain)(currentHost, locUrl.host)) {
|
|
133
|
+
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
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.endpointUrl = "https://" + locUrl.host;
|
|
137
|
+
// Recreate the client so subsequent requests use the new endpoint
|
|
138
|
+
this.quickpulseClient = this.createQuickpulseClient({
|
|
139
|
+
endpoint: this.endpointUrl,
|
|
140
|
+
credentials: { scopes: this.credentialScopes },
|
|
141
|
+
});
|
|
113
142
|
}
|
|
114
143
|
}
|
|
115
144
|
}
|