@azure/monitor-opentelemetry 1.18.2 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +19 -15
- 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 +23 -2
- package/dist/commonjs/logs/handler.js.map +1 -1
- package/dist/commonjs/metrics/performanceCounters.d.ts +3 -0
- package/dist/commonjs/metrics/performanceCounters.d.ts.map +1 -1
- package/dist/commonjs/metrics/performanceCounters.js +26 -26
- package/dist/commonjs/metrics/performanceCounters.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/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.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.js +8 -7
- package/dist/commonjs/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/commonjs/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/package.json +6 -1
- package/dist/commonjs/shared/config.d.ts +7 -0
- package/dist/commonjs/shared/config.d.ts.map +1 -1
- package/dist/commonjs/shared/config.js +28 -6
- 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.map +1 -1
- package/dist/commonjs/traces/handler.js +1 -7
- package/dist/commonjs/traces/handler.js.map +1 -1
- package/dist/commonjs/traces/sampler.js +1 -1
- package/dist/commonjs/traces/sampler.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/types.d.ts +20 -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 +34 -0
- package/dist/commonjs/utils/common.d.ts.map +1 -1
- package/dist/commonjs/utils/common.js +63 -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 +38 -31
- package/dist/commonjs/utils/statsbeat.js.map +1 -1
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +19 -15
- 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 +24 -3
- package/dist/esm/logs/handler.js.map +1 -1
- package/dist/esm/metrics/performanceCounters.d.ts +3 -0
- package/dist/esm/metrics/performanceCounters.d.ts.map +1 -1
- package/dist/esm/metrics/performanceCounters.js +26 -26
- package/dist/esm/metrics/performanceCounters.js.map +1 -1
- package/dist/esm/metrics/quickpulse/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.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.js +8 -7
- package/dist/esm/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/esm/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/package.json +6 -1
- package/dist/esm/shared/config.d.ts +7 -0
- package/dist/esm/shared/config.d.ts.map +1 -1
- package/dist/esm/shared/config.js +29 -7
- 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.map +1 -1
- package/dist/esm/traces/handler.js +1 -7
- package/dist/esm/traces/handler.js.map +1 -1
- package/dist/esm/traces/sampler.js +1 -1
- package/dist/esm/traces/sampler.js.map +1 -1
- package/dist/esm/types.d.ts +20 -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 +34 -0
- package/dist/esm/utils/common.d.ts.map +1 -1
- package/dist/esm/utils/common.js +59 -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 +39 -32
- package/dist/esm/utils/statsbeat.js.map +1 -1
- package/package.json +31 -29
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQ7C,OAAO,EACL,mCAAmC,EACnC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AE,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,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,YAAY,EAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;IACpB,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,2EAA2E;IAC3E,2EAA2E;IAC3E,2BAA2B,EAAE,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAC5B,OAAO,GAAG,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,gDAAgD;AAChD,MAAM,UAAU,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;AAElC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAS7C,OAAO,EACL,mCAAmC,EACnC,qCAAqC,GACtC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,uCAAuC,EAAE,MAAM,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E,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,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,YAAY,EAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;IACpB,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,2EAA2E;IAC3E,2EAA2E;IAC3E,2BAA2B,EAAE,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,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,MAAM,UAAU,eAAe;IAC7B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport type { NodeSDKConfiguration } from \"@opentelemetry/sdk-node\";\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\nimport type { MetricReader, ViewOptions } from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"./shared/config.js\";\nimport { MetricHandler } from \"./metrics/index.js\";\nimport { TraceHandler } from \"./traces/handler.js\";\nimport { LogHandler } from \"./logs/index.js\";\nimport type {\n StatsbeatFeatures,\n StatsbeatInstrumentations,\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n ConsoleInstrumentationOptions,\n BrowserSdkLoaderOptions,\n} from \"./types.js\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n APPLICATIONINSIGHTS_SDKSTATS_DISABLED,\n} from \"./types.js\";\nimport { BrowserSdkLoader } from \"./browserSdkLoader/browserSdkLoader.js\";\nimport { setSdkPrefix } from \"./metrics/quickpulse/utils.js\";\nimport type { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport type { LogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport { getInstance } from \"./utils/statsbeat.js\";\nimport { patchOpenTelemetryInstrumentationEnable } from \"./utils/opentelemetryInstrumentationPatcher.js\";\nimport { ensureAzureSdkTracingBridge } from \"./utils/azureSdkTracingBridge.js\";\nimport { isFunctionApp, parseResourceDetectorsFromEnvVar } from \"./utils/common.js\";\nimport { isLogCollectionDisabled } from \"./utils/logUtils.js\";\nimport { Logger } from \"./shared/logging/index.js\";\nimport { AZURE_MONITOR_AUTO_ATTACH } from \"./types.js\";\n\nexport type {\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n ConsoleInstrumentationOptions,\n BrowserSdkLoaderOptions,\n};\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet sdk: NodeSDK;\nlet browserSdkLoader: BrowserSdkLoader | undefined;\n// Track the global console patch because NodeSDK does not disable instrumentations.\nlet consoleInstrumentation: Instrumentation | undefined;\n\n/**\n * Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.\n */\nfunction sendAttachWarning(): void {\n if (process.env[AZURE_MONITOR_AUTO_ATTACH] === \"true\" && !isFunctionApp()) {\n // TODO: When AKS attach is public, update this message with disablement instructions for AKS\n const message =\n \"Distro detected that automatic instrumentation may have occurred. Only use autoinstrumentation if you \" +\n \"are not using manual instrumentation of OpenTelemetry in your code, such as with \" +\n \"@azure/monitor-opentelemetry or @azure/monitor-opentelemetry-exporter. For App Service resources, disable \" +\n \"autoinstrumentation in the Application Insights experience on your App Service resource or by setting \" +\n \"the ApplicationInsightsAgent_EXTENSION_VERSION app setting to 'disabled'.\";\n // Surface in the log stream\n console.warn(message);\n // Also log via diagnostic logging\n Logger.getInstance().warn(message);\n }\n}\n\n/**\n * Initialize Azure Monitor Distro\n * @param options - Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions): void {\n const config = new InternalConfig(options);\n patchOpenTelemetryInstrumentationEnable();\n // Omit disabled log instrumentations from Statsbeat.\n const logInstrumentationsEnabled = !isLogCollectionDisabled();\n const statsbeatInstrumentations: StatsbeatInstrumentations = {\n // Instrumentations\n azureSdk: config.instrumentationOptions?.azureSdk?.enabled,\n mongoDb: config.instrumentationOptions?.mongoDb?.enabled,\n mySql: config.instrumentationOptions?.mySql?.enabled,\n postgreSql: config.instrumentationOptions?.postgreSql?.enabled,\n redis: config.instrumentationOptions?.redis?.enabled,\n bunyan: logInstrumentationsEnabled && config.instrumentationOptions?.bunyan?.enabled,\n winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,\n console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,\n };\n // Only report this feature when the AKS resource detector itself was able to populate the AKS\n // cluster attributes, which requires the customer to have configured access to the\n // aks-cluster-metadata ConfigMap (RBAC + env var or mounted file).\n const statsbeatFeatures: StatsbeatFeatures = {\n browserSdkLoader: config.browserSdkLoaderOptions.enabled,\n aadHandling: !!config.azureMonitorExporterOptions?.credential,\n diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,\n customerSdkStats: process.env[APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === \"true\",\n aksResourceDetectorPopulation: config.aksResourceDetectorPopulated,\n };\n getInstance().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);\n\n if (config.browserSdkLoaderOptions.enabled) {\n browserSdkLoader = new BrowserSdkLoader(config);\n }\n // Remove global providers in OpenTelemetry, these would be overridden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n // Restore any console patch from the previous initialization.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n\n // Clear the entire OpenTelemetry API global state to avoid version conflicts.\n // The disable() calls above remove individual providers but leave the `version` field\n // on the global object intact. If a different version of @opentelemetry/api was loaded\n // first (e.g. by a VS Code extension host or another extension), the stale version\n // causes registerGlobal() in sdk.start() to fail with \"All API registration versions\n // must match\", resulting in Noop providers. Deleting the global object forces\n // registerGlobal() to create a fresh one with the correct version.\n const globalOpentelemetryApiKey = Symbol.for(\"opentelemetry.js.api.1\");\n Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);\n\n // Create internal handlers\n const metricHandler = new MetricHandler(config);\n const traceHandler = new TraceHandler(config, metricHandler);\n const logHandler = new LogHandler(config, metricHandler);\n\n const instrumentations = traceHandler\n .getInstrumentations()\n .concat(logHandler.getInstrumentations());\n consoleInstrumentation = logHandler.getConsoleInstrumentation();\n\n const resourceDetectorsList = parseResourceDetectorsFromEnvVar();\n\n // Add extra SpanProcessors, and logRecordProcessors from user configuration\n const spanProcessors: SpanProcessor[] = options?.spanProcessors || [];\n const logRecordProcessors: LogRecordProcessor[] = options?.logRecordProcessors || [];\n const customViews: ViewOptions[] = options?.views || [];\n\n // Prepare metric readers - always include Azure Monitor\n const metricReaders: MetricReader[] = [\n metricHandler.getMetricReader(),\n ...(options?.metricReaders || []),\n ];\n\n const views: ViewOptions[] = metricHandler.getViews().concat(customViews);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n metricReaders: metricReaders,\n views,\n instrumentations: instrumentations,\n logRecordProcessors: [\n logHandler.getAzureLogRecordProcessor(),\n ...logRecordProcessors,\n logHandler.getBatchLogRecordProcessor(),\n ],\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessors: [\n traceHandler.getAzureMonitorSpanProcessor(),\n ...spanProcessors,\n traceHandler.getBatchSpanProcessor(),\n ],\n resourceDetectors: resourceDetectorsList,\n };\n sdk = new NodeSDK(sdkConfig);\n setSdkPrefix();\n sendAttachWarning();\n sdk.start();\n\n // Eagerly install the Azure SDK tracing bridge in case @azure/core-tracing\n // was loaded before useAzureMonitor() (the RITM hook misses it otherwise).\n ensureAzureSdkTracingBridge();\n}\n\n/**\n * Shutdown Azure Monitor Open Telemetry Distro\n * @see https://github.com/open-telemetry/opentelemetry-js/blob/0229434cb5a3179f63c021105f36270ae7897929/experimental/packages/opentelemetry-sdk-node/src/sdk.ts#L398\n */\nexport function shutdownAzureMonitor(): Promise<void> {\n browserSdkLoader?.dispose();\n // NodeSDK.shutdown() does not restore the global console.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n return sdk?.shutdown();\n}\n\n/**\n * Get the internal SDK instance for testing purposes\n * @internal\n */\n// eslint-disable-next-line no-underscore-dangle\nexport function _getSdkInstance(): NodeSDK | undefined {\n return sdk;\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
|
9
9
|
export class AzureBatchLogRecordProcessor extends BatchLogRecordProcessor {
|
|
10
10
|
_options;
|
|
11
11
|
constructor(exporter, options) {
|
|
12
|
-
super(exporter);
|
|
12
|
+
super({ exporter });
|
|
13
13
|
this._options = options;
|
|
14
14
|
}
|
|
15
15
|
onEmit(logRecord) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchLogRecordProcessor.js","sourceRoot":"","sources":["../../../src/logs/batchLogRecordProcessor.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;GAGG;AACH,MAAM,OAAO,4BAA6B,SAAQ,uBAAuB;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,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;GAGG;AACH,MAAM,OAAO,4BAA6B,SAAQ,uBAAuB;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,UAAU,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","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;CAoCpC"}
|
package/dist/esm/logs/handler.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import { AzureMonitorLogExporter } from "@azure/monitor-opentelemetry-exporter";
|
|
4
4
|
import { BunyanInstrumentation } from "@opentelemetry/instrumentation-bunyan";
|
|
5
|
+
import { ConsoleInstrumentation } from "@opentelemetry/instrumentation-console";
|
|
5
6
|
import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";
|
|
6
7
|
import { AzureLogRecordProcessor } from "./logRecordProcessor.js";
|
|
7
8
|
import { AzureBatchLogRecordProcessor } from "./batchLogRecordProcessor.js";
|
|
8
|
-
import { logLevelToSeverityNumber } from "../utils/logUtils.js";
|
|
9
|
+
import { isLogCollectionDisabled, logLevelToSeverityNumber } from "../utils/logUtils.js";
|
|
9
10
|
/**
|
|
10
11
|
* Azure Monitor OpenTelemetry Log Handler
|
|
11
12
|
*/
|
|
@@ -16,6 +17,7 @@ export class LogHandler {
|
|
|
16
17
|
_metricHandler;
|
|
17
18
|
_config;
|
|
18
19
|
_instrumentations;
|
|
20
|
+
_consoleInstrumentation;
|
|
19
21
|
/**
|
|
20
22
|
* Initializes a new instance of the TraceHandler class.
|
|
21
23
|
* @param _config - Distro configuration.
|
|
@@ -41,23 +43,42 @@ export class LogHandler {
|
|
|
41
43
|
getInstrumentations() {
|
|
42
44
|
return this._instrumentations;
|
|
43
45
|
}
|
|
46
|
+
/** Returns the console instrumentation for explicit lifecycle management. */
|
|
47
|
+
getConsoleInstrumentation() {
|
|
48
|
+
return this._consoleInstrumentation;
|
|
49
|
+
}
|
|
44
50
|
/**
|
|
45
51
|
* Start auto collection of telemetry
|
|
46
52
|
*/
|
|
47
53
|
_initializeInstrumentations() {
|
|
54
|
+
if (isLogCollectionDisabled()) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
48
57
|
const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;
|
|
58
|
+
const logSeverity = logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined;
|
|
49
59
|
if (this._config.instrumentationOptions.bunyan?.enabled) {
|
|
50
60
|
this._instrumentations.push(new BunyanInstrumentation({
|
|
51
61
|
...this._config.instrumentationOptions.bunyan,
|
|
52
|
-
logSeverity
|
|
62
|
+
logSeverity,
|
|
53
63
|
}));
|
|
54
64
|
}
|
|
55
65
|
if (this._config.instrumentationOptions.winston?.enabled) {
|
|
56
66
|
this._instrumentations.push(new WinstonInstrumentation({
|
|
57
67
|
...this._config.instrumentationOptions.winston,
|
|
58
|
-
logSeverity
|
|
68
|
+
logSeverity,
|
|
59
69
|
}));
|
|
60
70
|
}
|
|
71
|
+
const consoleOptions = this._config.instrumentationOptions.console;
|
|
72
|
+
if (consoleOptions?.enabled) {
|
|
73
|
+
// Defer patching until registration so construction preserves the original methods.
|
|
74
|
+
const consoleInstrumentation = new ConsoleInstrumentation({
|
|
75
|
+
...consoleOptions,
|
|
76
|
+
enabled: false,
|
|
77
|
+
logSeverity: consoleOptions.logSeverity ?? logSeverity,
|
|
78
|
+
});
|
|
79
|
+
this._consoleInstrumentation = consoleInstrumentation;
|
|
80
|
+
this._instrumentations.push(consoleInstrumentation);
|
|
81
|
+
}
|
|
61
82
|
}
|
|
62
83
|
}
|
|
63
84
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAIhF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAIhF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,4BAA4B,EA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iDAAiD,CAAC;QAClF,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAEpF,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACxD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,qBAAqB,CAAC;gBACxB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM;gBAC7C,WAAW;aACZ,CAAC,CACH,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YACzD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,sBAAsB,CAAC;gBACzB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO;gBAC9C,WAAW;aACZ,CAAC,CACH,CAAC;QACJ,CAAC;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC;QACnE,IAAI,cAAc,EAAE,OAAO,EAAE,CAAC;YAC5B,oFAAoF;YACpF,MAAM,sBAAsB,GAAG,IAAI,sBAAsB,CAAC;gBACxD,GAAG,cAAc;gBACjB,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,WAAW;aACvD,CAAC,CAAC;YACH,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzureMonitorLogExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BunyanInstrumentation } from \"@opentelemetry/instrumentation-bunyan\";\nimport { ConsoleInstrumentation } from \"@opentelemetry/instrumentation-console\";\nimport { WinstonInstrumentation } from \"@opentelemetry/instrumentation-winston\";\nimport type { BatchLogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport type { InternalConfig } from \"../shared/config.js\";\nimport type { MetricHandler } from \"../metrics/handler.js\";\nimport { AzureLogRecordProcessor } from \"./logRecordProcessor.js\";\nimport { AzureBatchLogRecordProcessor } from \"./batchLogRecordProcessor.js\";\nimport { isLogCollectionDisabled, logLevelToSeverityNumber } from \"../utils/logUtils.js\";\n\n/**\n * Azure Monitor OpenTelemetry Log Handler\n */\nexport class LogHandler {\n private _azureExporter: AzureMonitorLogExporter;\n private _azureLogRecordProcessor: AzureLogRecordProcessor;\n private _azureBatchLogRecordProcessor: AzureBatchLogRecordProcessor;\n private _metricHandler: MetricHandler;\n private _config: InternalConfig;\n private _instrumentations: Instrumentation[];\n private _consoleInstrumentation: Instrumentation | undefined;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Distro configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);\n this._azureBatchLogRecordProcessor = new AzureBatchLogRecordProcessor(this._azureExporter, {\n enableTraceBasedSamplingForLogs: this._config.enableTraceBasedSamplingForLogs,\n });\n this._azureLogRecordProcessor = new AzureLogRecordProcessor(this._metricHandler);\n this._instrumentations = [];\n this._initializeInstrumentations();\n }\n\n public getAzureLogRecordProcessor(): AzureLogRecordProcessor {\n return this._azureLogRecordProcessor;\n }\n\n public getBatchLogRecordProcessor(): BatchLogRecordProcessor {\n return this._azureBatchLogRecordProcessor;\n }\n\n public getInstrumentations(): Instrumentation[] {\n return this._instrumentations;\n }\n\n /** Returns the console instrumentation for explicit lifecycle management. */\n public getConsoleInstrumentation(): Instrumentation | undefined {\n return this._consoleInstrumentation;\n }\n\n /**\n * Start auto collection of telemetry\n */\n private _initializeInstrumentations(): void {\n if (isLogCollectionDisabled()) {\n return;\n }\n\n const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;\n const logSeverity = logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined;\n\n if (this._config.instrumentationOptions.bunyan?.enabled) {\n this._instrumentations.push(\n new BunyanInstrumentation({\n ...this._config.instrumentationOptions.bunyan,\n logSeverity,\n }),\n );\n }\n if (this._config.instrumentationOptions.winston?.enabled) {\n this._instrumentations.push(\n new WinstonInstrumentation({\n ...this._config.instrumentationOptions.winston,\n logSeverity,\n }),\n );\n }\n const consoleOptions = this._config.instrumentationOptions.console;\n if (consoleOptions?.enabled) {\n // Defer patching until registration so construction preserves the original methods.\n const consoleInstrumentation = new ConsoleInstrumentation({\n ...consoleOptions,\n enabled: false,\n logSeverity: consoleOptions.logSeverity ?? logSeverity,\n });\n this._consoleInstrumentation = consoleInstrumentation;\n this._instrumentations.push(consoleInstrumentation);\n }\n }\n}\n"]}
|
|
@@ -34,6 +34,9 @@ export declare class PerformanceCounterMetrics {
|
|
|
34
34
|
private lastHrtime;
|
|
35
35
|
private lastCpus;
|
|
36
36
|
private lastCpusProcess;
|
|
37
|
+
private lastAppCpuUsageNormalized;
|
|
38
|
+
private lastHrtimeNormalized;
|
|
39
|
+
private lastCpusProcessNormalized;
|
|
37
40
|
private totalExceptionCount;
|
|
38
41
|
/**
|
|
39
42
|
* Creates performance counter instruments.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceCounters.d.ts","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAM5D,OAAO,EAAE,aAAa,EAAiC,MAAM,4BAA4B,CAAC;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,+BAA+B,CAAC;AAG9E,OAAO,KA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AAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAkB3C;;;OAGG;IACI,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAO/C,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,mBAAmB;IAwC3B,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,wBAAwB;IA0ChC,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,gBAAgB;CAgBzB"}
|
|
@@ -34,7 +34,7 @@ export class PerformanceCounterMetrics {
|
|
|
34
34
|
processTimeGaugeCallback;
|
|
35
35
|
exceptionCountGauge;
|
|
36
36
|
exceptionCountGaugeCallback;
|
|
37
|
-
lastExceptionRate
|
|
37
|
+
lastExceptionRate;
|
|
38
38
|
totalCount = 0;
|
|
39
39
|
intervalExecutionTime = 0;
|
|
40
40
|
lastRequestRate;
|
|
@@ -42,6 +42,9 @@ export class PerformanceCounterMetrics {
|
|
|
42
42
|
lastHrtime;
|
|
43
43
|
lastCpus;
|
|
44
44
|
lastCpusProcess;
|
|
45
|
+
lastAppCpuUsageNormalized;
|
|
46
|
+
lastHrtimeNormalized;
|
|
47
|
+
lastCpusProcessNormalized;
|
|
45
48
|
totalExceptionCount = 0;
|
|
46
49
|
/**
|
|
47
50
|
* Creates performance counter instruments.
|
|
@@ -54,11 +57,15 @@ export class PerformanceCounterMetrics {
|
|
|
54
57
|
this.lastCpusProcess = os.cpus();
|
|
55
58
|
this.lastAppCpuUsage = process.cpuUsage();
|
|
56
59
|
this.lastHrtime = process.hrtime();
|
|
60
|
+
this.lastCpusProcessNormalized = os.cpus();
|
|
61
|
+
this.lastAppCpuUsageNormalized = process.cpuUsage();
|
|
62
|
+
this.lastHrtimeNormalized = process.hrtime();
|
|
57
63
|
this.lastRequestRate = {
|
|
58
64
|
count: this.totalCount,
|
|
59
65
|
time: +new Date(),
|
|
60
66
|
executionInterval: this.intervalExecutionTime,
|
|
61
67
|
};
|
|
68
|
+
this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };
|
|
62
69
|
this.azureExporter = new AzureMonitorMetricExporter(this.internalConfig.azureMonitorExporterOptions);
|
|
63
70
|
const metricReaderOptions = {
|
|
64
71
|
exporter: this.azureExporter,
|
|
@@ -70,7 +77,6 @@ export class PerformanceCounterMetrics {
|
|
|
70
77
|
};
|
|
71
78
|
this.meterProvider = new MeterProvider(meterProviderConfig);
|
|
72
79
|
this.meter = this.meterProvider.getMeter("AzureMonitorPerformanceCountersMeter");
|
|
73
|
-
this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };
|
|
74
80
|
// Create Instruments
|
|
75
81
|
this.requestDurationHistogram = this.meter.createHistogram(PerformanceCounterMetricNames.REQUEST_DURATION, { valueType: ValueType.DOUBLE });
|
|
76
82
|
this.requestRateGauge = this.meter.createObservableGauge(PerformanceCounterMetricNames.REQUEST_RATE, {
|
|
@@ -244,33 +250,31 @@ export class PerformanceCounterMetrics {
|
|
|
244
250
|
const cpus = os.cpus();
|
|
245
251
|
if (cpus &&
|
|
246
252
|
cpus.length &&
|
|
247
|
-
this.
|
|
248
|
-
cpus.length === this.
|
|
253
|
+
this.lastCpusProcessNormalized &&
|
|
254
|
+
cpus.length === this.lastCpusProcessNormalized.length) {
|
|
249
255
|
// Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)
|
|
250
256
|
let appCpuPercent = undefined;
|
|
251
257
|
const appCpuUsage = process.cpuUsage();
|
|
252
258
|
const hrtime = process.hrtime();
|
|
253
259
|
const totalApp = appCpuUsage.user -
|
|
254
|
-
this.
|
|
255
|
-
(appCpuUsage.system - this.
|
|
256
|
-
if (typeof this.
|
|
257
|
-
|
|
260
|
+
this.lastAppCpuUsageNormalized.user +
|
|
261
|
+
(appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;
|
|
262
|
+
if (typeof this.lastHrtimeNormalized !== "undefined" &&
|
|
263
|
+
this.lastHrtimeNormalized.length === 2) {
|
|
264
|
+
const elapsedTime = (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +
|
|
265
|
+
(hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds
|
|
258
266
|
appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);
|
|
259
267
|
}
|
|
260
268
|
// Set previous
|
|
261
|
-
this.
|
|
262
|
-
this.
|
|
263
|
-
const cpuTotals = this.getTotalCombinedCpu(cpus, this.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
270
|
-
}
|
|
269
|
+
this.lastAppCpuUsageNormalized = appCpuUsage;
|
|
270
|
+
this.lastHrtimeNormalized = hrtime;
|
|
271
|
+
const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);
|
|
272
|
+
const value = appCpuPercent !== undefined
|
|
273
|
+
? appCpuPercent
|
|
274
|
+
: (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
271
275
|
observableResult.observe(value);
|
|
272
276
|
}
|
|
273
|
-
this.
|
|
277
|
+
this.lastCpusProcessNormalized = cpus;
|
|
274
278
|
}
|
|
275
279
|
getProcessTime(observableResult) {
|
|
276
280
|
// this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary
|
|
@@ -296,13 +300,9 @@ export class PerformanceCounterMetrics {
|
|
|
296
300
|
this.lastAppCpuUsage = appCpuUsage;
|
|
297
301
|
this.lastHrtime = hrtime;
|
|
298
302
|
const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
305
|
-
}
|
|
303
|
+
const value = appCpuPercent !== undefined
|
|
304
|
+
? appCpuPercent
|
|
305
|
+
: (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
|
|
306
306
|
observableResult.observe(value);
|
|
307
307
|
}
|
|
308
308
|
this.lastCpusProcess = cpus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AAQzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAKnF,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE1F,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,yBAAyB;IAC5B,cAAc,CAAmC;IACjD,kBAAkB,GAAG,KAAK,CAAC,CAAC,aAAa;IACzC,aAAa,CAAgB;IAC7B,aAAa,CAA6B;IAC1C,KAAK,CAAQ;IACb,wBAAwB,CAAY;IACpC,gBAAgB,CAAkB;IAClC,wBAAwB,CAAqB;IAC7C,uBAAuB,CAAkB;IACzC,+BAA+B,CAAqB;IACpD,yBAAyB,CAAkB;IAC3C,iCAAiC,CAAqB;IACtD,kBAAkB,CAAkB;IACpC,0BAA0B,CAAqB;IAC/C,0BAA0B,CAAkB;IAC5C,kCAAkC,CAAqB;IACvD,gBAAgB,CAAkB;IAClC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AAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;QAC5D,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,cAAc,GAAG,SAAS,GAAG,IAAI,CAAC;YACxC,MAAM,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;YACjD,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number } = { count: 0, time: 0 };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
|
|
1
|
+
{"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;A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AC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastAppCpuUsageNormalized: { user: number; system: number };\n private lastHrtimeNormalized: number[];\n private lastCpusProcessNormalized: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n this.lastCpusProcessNormalized = os.cpus();\n this.lastAppCpuUsageNormalized = process.cpuUsage();\n this.lastHrtimeNormalized = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcessNormalized &&\n cpus.length === this.lastCpusProcessNormalized.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsageNormalized.user +\n (appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;\n\n if (\n typeof this.lastHrtimeNormalized !== \"undefined\" &&\n this.lastHrtimeNormalized.length === 2\n ) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +\n (hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsageNormalized = appCpuUsage;\n this.lastHrtimeNormalized = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);\n const value =\n appCpuPercent !== undefined\n ? appCpuPercent\n : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n observableResult.observe(value);\n }\n this.lastCpusProcessNormalized = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n const value =\n appCpuPercent !== undefined\n ? appCpuPercent\n : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
|
|
@@ -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,45 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { ManagedIdentityCredential } from "@azure/identity";
|
|
4
|
+
import { APPLICATIONINSIGHTS_AUTHENTICATION_STRING } from "../../types.js";
|
|
5
|
+
import { Logger } from "../../shared/logging/logger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves an Azure Active Directory (AAD) credential from the
|
|
8
|
+
* `APPLICATIONINSIGHTS_AUTHENTICATION_STRING` environment variable (the App Service /
|
|
9
|
+
* Functions convention) which has the form `Authorization=AAD;ClientId=<client-id>`.
|
|
10
|
+
* A `ManagedIdentityCredential` is created using the supplied `ClientId` when present.
|
|
11
|
+
*
|
|
12
|
+
* Returns `undefined` when the variable is absent, malformed, or does not request AAD
|
|
13
|
+
* authorization. This is intended as a fallback for callers that were not given an
|
|
14
|
+
* explicit credential.
|
|
15
|
+
*
|
|
16
|
+
* @returns A `ManagedIdentityCredential`, or `undefined` when none applies.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export function getAuthenticationCredentialFromEnv() {
|
|
20
|
+
const authString = process.env[APPLICATIONINSIGHTS_AUTHENTICATION_STRING];
|
|
21
|
+
if (!authString) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const authStringMap = new Map();
|
|
26
|
+
for (const pair of authString.split(";")) {
|
|
27
|
+
const keyValue = pair.split("=");
|
|
28
|
+
if (keyValue.length !== 2) {
|
|
29
|
+
throw new Error(`Invalid key-value pair: "${pair}"`);
|
|
30
|
+
}
|
|
31
|
+
authStringMap.set(keyValue[0].toLowerCase(), keyValue[1]);
|
|
32
|
+
}
|
|
33
|
+
if (authStringMap.get("authorization") === "AAD") {
|
|
34
|
+
const clientId = authStringMap.get("clientid");
|
|
35
|
+
return clientId
|
|
36
|
+
? new ManagedIdentityCredential({ clientId })
|
|
37
|
+
: new ManagedIdentityCredential();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
Logger.getInstance().error(`APPLICATIONINSIGHTS_AUTHENTICATION_STRING, ${authString}, has invalid format:`, error);
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
//# 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;AAElC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EA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right (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":"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,C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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;CAmC5D"}
|
|
@@ -118,13 +118,14 @@ export class QuickpulseSender {
|
|
|
118
118
|
if (!locUrl.host) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
const currentHost = (() => {
|
|
122
|
+
try {
|
|
123
|
+
return new url.URL(this.endpointUrl).host;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
128
129
|
if (!isSameRegisteredDomain(currentHost, locUrl.host)) {
|
|
129
130
|
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.`);
|
|
130
131
|
return;
|