@azure/monitor-opentelemetry 1.18.2 → 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 +15 -2
- 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/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/liveMetrics.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/liveMetrics.js +4 -2
- package/dist/commonjs/metrics/quickpulse/liveMetrics.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/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/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 +15 -2
- 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/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/liveMetrics.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/liveMetrics.js +4 -2
- package/dist/esm/metrics/quickpulse/liveMetrics.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/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/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 +26 -24
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
|
@@ -19,6 +19,7 @@ const statsbeat_js_1 = require("./utils/statsbeat.js");
|
|
|
19
19
|
const opentelemetryInstrumentationPatcher_js_1 = require("./utils/opentelemetryInstrumentationPatcher.js");
|
|
20
20
|
const azureSdkTracingBridge_js_1 = require("./utils/azureSdkTracingBridge.js");
|
|
21
21
|
const common_js_1 = require("./utils/common.js");
|
|
22
|
+
const logUtils_js_1 = require("./utils/logUtils.js");
|
|
22
23
|
const index_js_3 = require("./shared/logging/index.js");
|
|
23
24
|
const types_js_2 = require("./types.js");
|
|
24
25
|
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
@@ -30,6 +31,8 @@ const CLOUD_RESOURCE_ID_ATTRIBUTE = "cloud.resource_id";
|
|
|
30
31
|
process.env["AZURE_MONITOR_DISTRO_VERSION"] = types_js_1.AZURE_MONITOR_OPENTELEMETRY_VERSION;
|
|
31
32
|
let sdk;
|
|
32
33
|
let browserSdkLoader;
|
|
34
|
+
// Track the global console patch because NodeSDK does not disable instrumentations.
|
|
35
|
+
let consoleInstrumentation;
|
|
33
36
|
/**
|
|
34
37
|
* Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.
|
|
35
38
|
*/
|
|
@@ -54,6 +57,8 @@ function sendAttachWarning() {
|
|
|
54
57
|
function useAzureMonitor(options) {
|
|
55
58
|
const config = new config_js_1.InternalConfig(options);
|
|
56
59
|
(0, opentelemetryInstrumentationPatcher_js_1.patchOpenTelemetryInstrumentationEnable)();
|
|
60
|
+
// Omit disabled log instrumentations from Statsbeat.
|
|
61
|
+
const logInstrumentationsEnabled = !(0, logUtils_js_1.isLogCollectionDisabled)();
|
|
57
62
|
const statsbeatInstrumentations = {
|
|
58
63
|
// Instrumentations
|
|
59
64
|
azureSdk: config.instrumentationOptions?.azureSdk?.enabled,
|
|
@@ -61,8 +66,9 @@ function useAzureMonitor(options) {
|
|
|
61
66
|
mySql: config.instrumentationOptions?.mySql?.enabled,
|
|
62
67
|
postgreSql: config.instrumentationOptions?.postgreSql?.enabled,
|
|
63
68
|
redis: config.instrumentationOptions?.redis?.enabled,
|
|
64
|
-
bunyan: config.instrumentationOptions?.bunyan?.enabled,
|
|
65
|
-
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,
|
|
66
72
|
};
|
|
67
73
|
// Check if the AKS resource detector successfully populated specific resource attributes
|
|
68
74
|
// (k8s.cluster.name or cloud.resource_id) beyond the basic cloud.platform/cloud.provider
|
|
@@ -85,6 +91,9 @@ function useAzureMonitor(options) {
|
|
|
85
91
|
api_1.metrics.disable();
|
|
86
92
|
api_1.trace.disable();
|
|
87
93
|
api_logs_1.logs.disable();
|
|
94
|
+
// Restore any console patch from the previous initialization.
|
|
95
|
+
consoleInstrumentation?.disable();
|
|
96
|
+
consoleInstrumentation = undefined;
|
|
88
97
|
// Clear the entire OpenTelemetry API global state to avoid version conflicts.
|
|
89
98
|
// The disable() calls above remove individual providers but leave the `version` field
|
|
90
99
|
// on the global object intact. If a different version of @opentelemetry/api was loaded
|
|
@@ -101,6 +110,7 @@ function useAzureMonitor(options) {
|
|
|
101
110
|
const instrumentations = traceHandler
|
|
102
111
|
.getInstrumentations()
|
|
103
112
|
.concat(logHandler.getInstrumentations());
|
|
113
|
+
consoleInstrumentation = logHandler.getConsoleInstrumentation();
|
|
104
114
|
const resourceDetectorsList = (0, common_js_1.parseResourceDetectorsFromEnvVar)();
|
|
105
115
|
// Add extra SpanProcessors, and logRecordProcessors from user configuration
|
|
106
116
|
const spanProcessors = options?.spanProcessors || [];
|
|
@@ -146,6 +156,9 @@ function useAzureMonitor(options) {
|
|
|
146
156
|
*/
|
|
147
157
|
function shutdownAzureMonitor() {
|
|
148
158
|
browserSdkLoader?.dispose();
|
|
159
|
+
// NodeSDK.shutdown() does not restore the global console.
|
|
160
|
+
consoleInstrumentation?.disable();
|
|
161
|
+
consoleInstrumentation = undefined;
|
|
149
162
|
return sdk?.shutdown();
|
|
150
163
|
}
|
|
151
164
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAsElC,0CAmGC;AAMD,oDAGC;AAOD,0CAEC;AAzLD,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,+EAA+E;AAC/E,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,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,0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,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,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 { 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 { 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 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\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 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,GAAG,8CAAmC,CAAC;AAElF,IAAI,GAAY,CAAC;AACjB,IAAI,gBAA8C,CAAC;AACnD,oFAAoF;AACpF,IAAI,sBAAmD,CAAC;AAExD;;GAEG;AACH,SAA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AAE;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,CAAC,CAAC;QACjF,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,2BAA2B,EAAE,CAAC;IACrC,CAAC;IAEM,0BAA0B;QAC/B,OAAO,IA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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"]}
|
|
@@ -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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveMetrics.d.ts","sourceRoot":"","sources":["../../../../src/metrics/quickpulse/liveMetrics.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAiC,MAAM,4BAA4B,CAAC;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,+BAA+B,CAAC;AAE9E,OAAO,KAAK,EACV,eAAe,EAUhB,MAAM,0BAA0B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;IAI7C,YAAY,IAAI,eAAe,EAAE;IAMjC,SAAS,IAAI,4BAA4B,EAAE;IAM3C,sBAAsB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIpD,OAAO,CAAC,WAAW;IAUnB;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IA4D3C;;;OAGG;IACI,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IA4B/C,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,0BAA0B;IAWlC,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,gCAAgC;IAyDxC,OAAO,CAAC,oBAAoB;IAiC5B,OAAO,CAAC,8BAA8B;IAoDtC,OAAO,CAAC,oCAAoC;CAgC7C"}
|
|
@@ -13,6 +13,7 @@ const exporter_js_1 = require("./export/exporter.js");
|
|
|
13
13
|
const sender_js_1 = require("./export/sender.js");
|
|
14
14
|
const connectionStringParser_js_1 = require("../../utils/connectionStringParser.js");
|
|
15
15
|
const types_js_1 = require("../../types.js");
|
|
16
|
+
const credentialUtils_js_1 = require("./credentialUtils.js");
|
|
16
17
|
const types_js_2 = require("./types.js");
|
|
17
18
|
const core_1 = require("@opentelemetry/core");
|
|
18
19
|
const statsbeat_js_1 = require("../../utils/statsbeat.js");
|
|
@@ -120,17 +121,18 @@ class LiveMetrics {
|
|
|
120
121
|
};
|
|
121
122
|
const parsedConnectionString = connectionStringParser_js_1.ConnectionStringParser.parse(this.config.azureMonitorExporterOptions.connectionString ||
|
|
122
123
|
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"]);
|
|
124
|
+
const credential = this.config.azureMonitorExporterOptions.credential ?? (0, credentialUtils_js_1.getAuthenticationCredentialFromEnv)();
|
|
123
125
|
this.pingSender = new sender_js_1.QuickpulseSender({
|
|
124
126
|
endpointUrl: parsedConnectionString.liveendpoint || types_js_1.DEFAULT_LIVEMETRICS_ENDPOINT,
|
|
125
127
|
instrumentationKey: parsedConnectionString.instrumentationkey || "",
|
|
126
|
-
credential:
|
|
128
|
+
credential: credential,
|
|
127
129
|
credentialScopes: parsedConnectionString.aadaudience ||
|
|
128
130
|
this.config.azureMonitorExporterOptions.credentialScopes,
|
|
129
131
|
});
|
|
130
132
|
const exporterOptions = {
|
|
131
133
|
endpointUrl: parsedConnectionString.liveendpoint || types_js_1.DEFAULT_LIVEMETRICS_ENDPOINT,
|
|
132
134
|
instrumentationKey: parsedConnectionString.instrumentationkey || "",
|
|
133
|
-
credential:
|
|
135
|
+
credential: credential,
|
|
134
136
|
credentialScopes: parsedConnectionString.aadaudience ||
|
|
135
137
|
this.config.azureMonitorExporterOptions.credentialScopes,
|
|
136
138
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|