@azure/monitor-opentelemetry 1.20.0 → 1.20.1
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/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +14 -18
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/logs/handler.d.ts +2 -1
- package/dist/commonjs/logs/handler.d.ts.map +1 -1
- package/dist/commonjs/logs/handler.js +10 -5
- package/dist/commonjs/logs/handler.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.js +21 -16
- package/dist/commonjs/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/liveMetrics.d.ts +5 -1
- package/dist/commonjs/metrics/quickpulse/liveMetrics.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/liveMetrics.js +86 -75
- package/dist/commonjs/metrics/quickpulse/liveMetrics.js.map +1 -1
- package/dist/commonjs/package.json +1 -1
- package/dist/commonjs/traces/azureSdkInstrumentation.d.ts +12 -0
- package/dist/commonjs/traces/azureSdkInstrumentation.d.ts.map +1 -0
- package/dist/commonjs/traces/azureSdkInstrumentation.js +64 -0
- package/dist/commonjs/traces/azureSdkInstrumentation.js.map +1 -0
- package/dist/commonjs/traces/handler.d.ts +2 -13
- package/dist/commonjs/traces/handler.d.ts.map +1 -1
- package/dist/commonjs/traces/handler.js +13 -36
- package/dist/commonjs/traces/handler.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/types.d.ts +1 -1
- package/dist/commonjs/types.js +1 -1
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/utils/azureSdkTracingBridge.d.ts +4 -4
- package/dist/commonjs/utils/azureSdkTracingBridge.d.ts.map +1 -1
- package/dist/commonjs/utils/azureSdkTracingBridge.js +10 -8
- package/dist/commonjs/utils/azureSdkTracingBridge.js.map +1 -1
- package/dist/commonjs/utils/instrumentation.d.ts +8 -0
- package/dist/commonjs/utils/instrumentation.d.ts.map +1 -0
- package/dist/commonjs/utils/instrumentation.js +26 -0
- package/dist/commonjs/utils/instrumentation.js.map +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +14 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logs/handler.d.ts +2 -1
- package/dist/esm/logs/handler.d.ts.map +1 -1
- package/dist/esm/logs/handler.js +10 -5
- package/dist/esm/logs/handler.js.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.d.ts +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.js +21 -16
- package/dist/esm/metrics/quickpulse/export/sender.js.map +1 -1
- package/dist/esm/metrics/quickpulse/liveMetrics.d.ts +5 -1
- package/dist/esm/metrics/quickpulse/liveMetrics.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/liveMetrics.js +86 -75
- package/dist/esm/metrics/quickpulse/liveMetrics.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/traces/azureSdkInstrumentation.d.ts +12 -0
- package/dist/esm/traces/azureSdkInstrumentation.d.ts.map +1 -0
- package/dist/esm/traces/azureSdkInstrumentation.js +60 -0
- package/dist/esm/traces/azureSdkInstrumentation.js.map +1 -0
- package/dist/esm/traces/handler.d.ts +2 -13
- package/dist/esm/traces/handler.d.ts.map +1 -1
- package/dist/esm/traces/handler.js +13 -35
- package/dist/esm/traces/handler.js.map +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/azureSdkTracingBridge.d.ts +4 -4
- package/dist/esm/utils/azureSdkTracingBridge.d.ts.map +1 -1
- package/dist/esm/utils/azureSdkTracingBridge.js +11 -7
- package/dist/esm/utils/azureSdkTracingBridge.js.map +1 -1
- package/dist/esm/utils/instrumentation.d.ts +8 -0
- package/dist/esm/utils/instrumentation.d.ts.map +1 -0
- package/dist/esm/utils/instrumentation.js +23 -0
- package/dist/esm/utils/instrumentation.js.map +1 -0
- package/package.json +8 -5
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;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,gDAAgD,CAAC;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AASvD,OAAO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AE;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"]}
|
|
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,gDAAgD,CAAC;AACzG,OAAO,EAAE,aAAa,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,E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AAgB;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;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAC5B,uBAAuB,EAAE,CAAC;IAC1B,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 { 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// NodeSDK shuts down providers, but leaves instrumentation hooks enabled.\nlet instrumentations: Instrumentation[] = [];\nconst instrumentationCache = new Map<string, Instrumentation>();\n\nfunction disableInstrumentations(): void {\n for (const instrumentation of instrumentations) {\n instrumentation.disable();\n }\n instrumentations = [];\n}\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 disableInstrumentations();\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\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, instrumentationCache);\n const logHandler = new LogHandler(config, metricHandler, instrumentationCache);\n\n instrumentations = traceHandler.getInstrumentations().concat(logHandler.getInstrumentations());\n\n const resourceDetectorsList = parseResourceDetectorsFromEnvVar();\n\n // Add extra SpanProcessors, and logRecordProcessors from user configuration\n const spanProcessors: SpanProcessor[] = options?.spanProcessors || [];\n const logRecordProcessors: LogRecordProcessor[] = options?.logRecordProcessors || [];\n const customViews: ViewOptions[] = options?.views || [];\n\n // Prepare metric readers - always include Azure Monitor\n const metricReaders: MetricReader[] = [\n metricHandler.getMetricReader(),\n ...(options?.metricReaders || []),\n ];\n\n const views: ViewOptions[] = metricHandler.getViews().concat(customViews);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n metricReaders: metricReaders,\n views,\n instrumentations: instrumentations,\n logRecordProcessors: [\n logHandler.getAzureLogRecordProcessor(),\n ...logRecordProcessors,\n logHandler.getBatchLogRecordProcessor(),\n ],\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessors: [\n traceHandler.getAzureMonitorSpanProcessor(),\n ...spanProcessors,\n traceHandler.getBatchSpanProcessor(),\n ],\n resourceDetectors: resourceDetectorsList,\n };\n sdk = new NodeSDK(sdkConfig);\n setSdkPrefix();\n sendAttachWarning();\n sdk.start();\n}\n\n/**\n * Shutdown Azure Monitor Open Telemetry Distro\n * @see https://github.com/open-telemetry/opentelemetry-js/blob/0229434cb5a3179f63c021105f36270ae7897929/experimental/packages/opentelemetry-sdk-node/src/sdk.ts#L398\n */\nexport function shutdownAzureMonitor(): Promise<void> {\n browserSdkLoader?.dispose();\n disableInstrumentations();\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"]}
|
|
@@ -7,6 +7,7 @@ import { AzureLogRecordProcessor } from "./logRecordProcessor.js";
|
|
|
7
7
|
* Azure Monitor OpenTelemetry Log Handler
|
|
8
8
|
*/
|
|
9
9
|
export declare class LogHandler {
|
|
10
|
+
private readonly instrumentationCache?;
|
|
10
11
|
private _azureExporter;
|
|
11
12
|
private _azureLogRecordProcessor;
|
|
12
13
|
private _azureBatchLogRecordProcessor;
|
|
@@ -19,7 +20,7 @@ export declare class LogHandler {
|
|
|
19
20
|
* @param _config - Distro configuration.
|
|
20
21
|
* @param _metricHandler - MetricHandler.
|
|
21
22
|
*/
|
|
22
|
-
constructor(config: InternalConfig, metricHandler: MetricHandler);
|
|
23
|
+
constructor(config: InternalConfig, metricHandler: MetricHandler, instrumentationCache?: Map<string, Instrumentation> | undefined);
|
|
23
24
|
getAzureLogRecordProcessor(): AzureLogRecordProcessor;
|
|
24
25
|
getBatchLogRecordProcessor(): BatchLogRecordProcessor;
|
|
25
26
|
getInstrumentations(): Instrumentation[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,KAAK,EAAE,uBA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CHANGED
|
@@ -7,10 +7,12 @@ import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";
|
|
|
7
7
|
import { AzureLogRecordProcessor } from "./logRecordProcessor.js";
|
|
8
8
|
import { AzureBatchLogRecordProcessor } from "./batchLogRecordProcessor.js";
|
|
9
9
|
import { isLogCollectionDisabled, logLevelToSeverityNumber } from "../utils/logUtils.js";
|
|
10
|
+
import { configureInstrumentation } from "../utils/instrumentation.js";
|
|
10
11
|
/**
|
|
11
12
|
* Azure Monitor OpenTelemetry Log Handler
|
|
12
13
|
*/
|
|
13
14
|
export class LogHandler {
|
|
15
|
+
instrumentationCache;
|
|
14
16
|
_azureExporter;
|
|
15
17
|
_azureLogRecordProcessor;
|
|
16
18
|
_azureBatchLogRecordProcessor;
|
|
@@ -23,7 +25,8 @@ export class LogHandler {
|
|
|
23
25
|
* @param _config - Distro configuration.
|
|
24
26
|
* @param _metricHandler - MetricHandler.
|
|
25
27
|
*/
|
|
26
|
-
constructor(config, metricHandler) {
|
|
28
|
+
constructor(config, metricHandler, instrumentationCache) {
|
|
29
|
+
this.instrumentationCache = instrumentationCache;
|
|
27
30
|
this._config = config;
|
|
28
31
|
this._metricHandler = metricHandler;
|
|
29
32
|
this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);
|
|
@@ -57,20 +60,22 @@ export class LogHandler {
|
|
|
57
60
|
const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;
|
|
58
61
|
const logSeverity = logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined;
|
|
59
62
|
if (this._config.instrumentationOptions.bunyan?.enabled) {
|
|
60
|
-
this._instrumentations.push(
|
|
63
|
+
this._instrumentations.push(configureInstrumentation(this.instrumentationCache, "bunyan", {
|
|
61
64
|
...this._config.instrumentationOptions.bunyan,
|
|
62
65
|
logSeverity,
|
|
63
|
-
}));
|
|
66
|
+
}, (options) => new BunyanInstrumentation(options)));
|
|
64
67
|
}
|
|
65
68
|
if (this._config.instrumentationOptions.winston?.enabled) {
|
|
66
|
-
this._instrumentations.push(
|
|
69
|
+
this._instrumentations.push(configureInstrumentation(this.instrumentationCache, "winston", {
|
|
67
70
|
...this._config.instrumentationOptions.winston,
|
|
68
71
|
logSeverity,
|
|
69
|
-
}));
|
|
72
|
+
}, (options) => new WinstonInstrumentation(options)));
|
|
70
73
|
}
|
|
71
74
|
const consoleOptions = this._config.instrumentationOptions.console;
|
|
72
75
|
if (consoleOptions?.enabled) {
|
|
73
76
|
// Defer patching until registration so construction preserves the original methods.
|
|
77
|
+
// Console patches globals rather than module hooks and caches its logger,
|
|
78
|
+
// so each SDK lifetime needs a fresh instance.
|
|
74
79
|
const consoleInstrumentation = new ConsoleInstrumentation({
|
|
75
80
|
...consoleOptions,
|
|
76
81
|
enabled: false,
|
|
@@ -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;AAChF,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,uBAAuB,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,uC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OAAO,EAAE,CAAC;YAC5B,oFAAoF;YACpF,0EAA0E;YAC1E,+CAA+C;YAC/C,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\";\nimport { configureInstrumentation } from \"../utils/instrumentation.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(\n config: InternalConfig,\n metricHandler: MetricHandler,\n private readonly instrumentationCache?: Map<string, Instrumentation>,\n ) {\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 configureInstrumentation(\n this.instrumentationCache,\n \"bunyan\",\n {\n ...this._config.instrumentationOptions.bunyan,\n logSeverity,\n },\n (options) => new BunyanInstrumentation(options),\n ),\n );\n }\n if (this._config.instrumentationOptions.winston?.enabled) {\n this._instrumentations.push(\n configureInstrumentation(\n this.instrumentationCache,\n \"winston\",\n {\n ...this._config.instrumentationOptions.winston,\n logSeverity,\n },\n (options) => new WinstonInstrumentation(options),\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 // Console patches globals rather than module hooks and caches its logger,\n // so each SDK lifetime needs a fresh instance.\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"]}
|
|
@@ -4,7 +4,7 @@ import type { IsSubscribedOptionalParams, PublishOptionalParams, CollectionConfi
|
|
|
4
4
|
* Response type that includes the body and response headers from the Live Metrics service.
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export interface QuickpulseResponse extends CollectionConfigurationInfo {
|
|
7
|
+
export interface QuickpulseResponse extends Partial<CollectionConfigurationInfo> {
|
|
8
8
|
/** Whether the instrumentation key is subscribed. */
|
|
9
9
|
xMsQpsSubscribed?: string;
|
|
10
10
|
/** Configuration ETag. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EACV,0BAA0B,EAC1B,qBAAqB,EAErB,2BAA2B,EAC5B,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EACV,0BAA0B,EAC1B,qBAAqB,EAErB,2BAA2B,EAC5B,MAAM,6BAA6B,CAAC;AAarC;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,OAAO,CAAC,2BAA2B,CAAC;IAC9E,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,CAAoB;IAC5C,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;IAc9B;;;OAGG;IACG,YAAY,CAChB,cAAc,EAAE,0BAA0B,GACzC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IA2B1C;;;OAGG;IACG,OAAO,CAAC,cAAc,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAwB7F;;;;;;;;;OASG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAmC5D"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import url from "url";
|
|
4
4
|
import { redirectPolicyName } from "@azure/core-rest-pipeline";
|
|
5
5
|
import { diag } from "@opentelemetry/api";
|
|
6
|
-
import {
|
|
6
|
+
import { createQuickpulse } from "../../../generated/api/index.js";
|
|
7
|
+
import { _isSubscribedSend, _isSubscribedDeserialize, _publishSend, _publishDeserialize, } from "../../../generated/api/operations.js";
|
|
7
8
|
import { isSameRegisteredDomain } from "../redirectUtils.js";
|
|
8
9
|
const applicationInsightsResource = "https://monitor.azure.com/.default";
|
|
9
10
|
/**
|
|
@@ -39,7 +40,14 @@ export class QuickpulseSender {
|
|
|
39
40
|
this.quickpulseClient = this.createQuickpulseClient(clientOptions);
|
|
40
41
|
}
|
|
41
42
|
createQuickpulseClient(clientOptions) {
|
|
42
|
-
const
|
|
43
|
+
const prefixFromOptions = clientOptions.userAgentOptions?.userAgentPrefix;
|
|
44
|
+
const userAgentPrefix = prefixFromOptions
|
|
45
|
+
? `${prefixFromOptions} azsdk-js-client`
|
|
46
|
+
: "azsdk-js-client";
|
|
47
|
+
const client = createQuickpulse(this.credential, {
|
|
48
|
+
...clientOptions,
|
|
49
|
+
userAgentOptions: { userAgentPrefix },
|
|
50
|
+
});
|
|
43
51
|
// Handle redirects in HTTP Sender
|
|
44
52
|
client.pipeline.removePolicy({ name: redirectPolicyName });
|
|
45
53
|
return client;
|
|
@@ -50,13 +58,12 @@ export class QuickpulseSender {
|
|
|
50
58
|
*/
|
|
51
59
|
async isSubscribed(optionalParams) {
|
|
52
60
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
61
|
+
const response = await _isSubscribedSend(this.quickpulseClient, this.instrumentationKey, optionalParams);
|
|
62
|
+
// Keep optional-body compatibility outside the regenerated deserializer.
|
|
63
|
+
const body = response.status === "200" && response.body == null
|
|
64
|
+
? undefined
|
|
65
|
+
: await _isSubscribedDeserialize(response);
|
|
66
|
+
const responseHeaders = response.headers;
|
|
60
67
|
return {
|
|
61
68
|
...body,
|
|
62
69
|
xMsQpsSubscribed: responseHeaders["x-ms-qps-subscribed"],
|
|
@@ -77,13 +84,11 @@ export class QuickpulseSender {
|
|
|
77
84
|
*/
|
|
78
85
|
async publish(optionalParams) {
|
|
79
86
|
try {
|
|
80
|
-
|
|
81
|
-
const body =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
+
const response = await _publishSend(this.quickpulseClient, this.instrumentationKey, optionalParams);
|
|
88
|
+
const body = response.status === "200" && response.body == null
|
|
89
|
+
? undefined
|
|
90
|
+
: await _publishDeserialize(response);
|
|
91
|
+
const responseHeaders = response.headers;
|
|
87
92
|
return {
|
|
88
93
|
...body,
|
|
89
94
|
xMsQpsSubscribed: responseHeaders["x-ms-qps-subscribed"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.js","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAO1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,MAAM,2BAA2B,GAAG,oCAAoC,CAAC;AAiBzE;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,gBAAgB,CAAmB;IACnC,kBAAkB,CAAS;IAC3B,WAAW,CAAS;IACpB,UAAU,CAAkB;IAC5B,gBAAgB,CAAW;IAEnC,YAAY,OAKX;QACC,gEAAgE;QAChE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,MAAM,aAAa,GAAmC;YACpD,QAAQ,EAAE,IAAI,CAAC,WAAW;SAC3B,CAAC;QAEF,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAA6B,CAAC;QAExD,8BAA8B;QAC9B,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,OAAO,CAAC,gBAAgB;gBAC1B,CAAC,CAAC,CAAC,OAAO,CAAC,gBA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C,WAAW,CAAC,CAAC,IAAI,CAAC;gBAC5C,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YAEL,IAAI,CAAC,sBAAsB,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtD,IAAI,CAAC,KAAK,CACR,0DAA0D,MAAM,CAAC,IAAI,oGAAoG,CAC1K,CAAC;gBACF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;YAC5C,kEAAkE;YAClE,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC;gBAClD,QAAQ,EAAE,IAAI,CAAC,WAAW;gBAC1B,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE;aAC/C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport url from \"url\";\nimport type { RestError } from \"@azure/core-rest-pipeline\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport { diag } from \"@opentelemetry/api\";\nimport type {\n IsSubscribedOptionalParams,\n PublishOptionalParams,\n QuickpulseClientOptionalParams,\n CollectionConfigurationInfo,\n} from \"../../../generated/index.js\";\nimport { QuickpulseClient } from \"../../../generated/index.js\";\nimport { isSameRegisteredDomain } from \"../redirectUtils.js\";\n\nconst applicationInsightsResource = \"https://monitor.azure.com/.default\";\n\n/**\n * Response type that includes the body and response headers from the Live Metrics service.\n * @internal\n */\nexport interface QuickpulseResponse extends CollectionConfigurationInfo {\n /** Whether the instrumentation key is subscribed. */\n xMsQpsSubscribed?: string;\n /** Configuration ETag. */\n xMsQpsConfigurationEtag?: string;\n /** Polling interval hint (only for ping). */\n xMsQpsServicePollingIntervalHint?: string;\n /** Endpoint redirect (only for ping). */\n xMsQpsServiceEndpointRedirectV2?: string;\n}\n\n/**\n * Quickpulse sender class\n * @internal\n */\nexport class QuickpulseSender {\n private quickpulseClient: QuickpulseClient;\n private instrumentationKey: string;\n private endpointUrl: string;\n private credential: TokenCredential;\n private credentialScopes: string[];\n\n constructor(options: {\n endpointUrl: string;\n instrumentationKey: string;\n credential?: TokenCredential;\n credentialScopes?: string | string[];\n }) {\n // Build endpoint using provided configuration or default values\n this.endpointUrl = options.endpointUrl;\n const clientOptions: QuickpulseClientOptionalParams = {\n endpoint: this.endpointUrl,\n };\n\n this.instrumentationKey = options.instrumentationKey;\n this.credential = options.credential as TokenCredential;\n\n // Configure credential scopes\n if (options.credentialScopes) {\n this.credentialScopes = Array.isArray(options.credentialScopes)\n ? options.credentialScopes\n : [options.credentialScopes];\n } else {\n this.credentialScopes = [applicationInsightsResource];\n }\n if (options.credential) {\n clientOptions.credentials = { scopes: this.credentialScopes };\n }\n\n this.quickpulseClient = this.createQuickpulseClient(clientOptions);\n }\n\n private createQuickpulseClient(clientOptions: QuickpulseClientOptionalParams): QuickpulseClient {\n const client = new QuickpulseClient(this.credential, clientOptions);\n // Handle redirects in HTTP Sender\n client.pipeline.removePolicy({ name: redirectPolicyName });\n return client;\n }\n\n /**\n * isSubscribed Quickpulse service\n * @internal\n */\n async isSubscribed(\n optionalParams: IsSubscribedOptionalParams,\n ): Promise<QuickpulseResponse | undefined> {\n try {\n let responseHeaders: Record<string, string> = {};\n const body = await this.quickpulseClient.isSubscribed(this.instrumentationKey, {\n ...optionalParams,\n onResponse: (rawResponse) => {\n responseHeaders = rawResponse.headers.toJSON();\n },\n });\n return {\n ...body,\n xMsQpsSubscribed: responseHeaders[\"x-ms-qps-subscribed\"],\n xMsQpsConfigurationEtag: responseHeaders[\"x-ms-qps-configuration-etag\"],\n xMsQpsServicePollingIntervalHint: responseHeaders[\"x-ms-qps-service-polling-interval-hint\"],\n xMsQpsServiceEndpointRedirectV2: responseHeaders[\"x-ms-qps-service-endpoint-redirect-v2\"],\n };\n } catch (error: any) {\n const restError = error as RestError;\n diag.info(\"Failed to ping Quickpulse service\", restError.message);\n }\n return;\n }\n\n /**\n * publish Quickpulse service\n * @internal\n */\n async publish(optionalParams: PublishOptionalParams): Promise<QuickpulseResponse | undefined> {\n try {\n let responseHeaders: Record<string, string> = {};\n const body = await this.quickpulseClient.publish(this.instrumentationKey, {\n ...optionalParams,\n onResponse: (rawResponse) => {\n responseHeaders = rawResponse.headers.toJSON();\n },\n });\n return {\n ...body,\n xMsQpsSubscribed: responseHeaders[\"x-ms-qps-subscribed\"],\n xMsQpsConfigurationEtag: responseHeaders[\"x-ms-qps-configuration-etag\"],\n };\n } catch (error: any) {\n const restError = error as RestError;\n diag.warn(\"Failed to post Quickpulse service\", restError.message);\n }\n return;\n }\n\n /**\n * Apply a server-issued Live Metrics redirect (`x-ms-qps-service-endpoint-redirect-v2`) by\n * re-pointing the underlying client at the new host.\n *\n * Cross-origin redirects are refused (no state mutated) when the target is neither the configured\n * Live Metrics host nor under a known Azure Monitor ingestion domain suffix. Refusing them is\n * required to prevent an attacker-controlled redirect from causing the bearer auth policy to\n * attach a freshly-signed AAD token (scope `https://monitor.azure.com/.default`) — and the\n * telemetry body — to a foreign host on the next ping/publish call.\n */\n handlePermanentRedirect(location: string | undefined): void {\n if (location) {\n let locUrl: url.URL;\n try {\n locUrl = new url.URL(location);\n } catch {\n return;\n }\n if (!locUrl.host) {\n return;\n }\n\n const currentHost = (() => {\n try {\n return new url.URL(this.endpointUrl).host;\n } catch {\n return \"\";\n }\n })();\n\n if (!isSameRegisteredDomain(currentHost, locUrl.host)) {\n diag.error(\n `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.`,\n );\n return;\n }\n\n this.endpointUrl = \"https://\" + locUrl.host;\n // Recreate the client so subsequent requests use the new endpoint\n this.quickpulseClient = this.createQuickpulseClient({\n endpoint: this.endpointUrl,\n credentials: { scopes: this.credentialScopes },\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sender.js","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAQ1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,GACpB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,MAAM,2BAA2B,GAAG,oCAAoC,CAAC;AAiBzE;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,gBAAgB,CAAoB;IACpC,kBAAkB,CAAS;IAC3B,WAAW,CAAS;IACpB,UAAU,CAAkB;IAC5B,gBAAgB,CAAW;IAEnC,YAAY,OAKX;QACC,gEAAgE;QAChE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,MAAM,aAAa,GAAmC;YACpD,QAAQ,EAAE,IAAI,CAAC,WAAW;SAC3B,CAAC;QAEF,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAA6B,CAAC;QAExD,8BAA8B;QAC9B,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,OAAO,CAAC,gBAAgB;gBAC1B,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;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,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACjC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO;YACT,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACjB,OAAO;YACT,CAAC;YAED,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE;gBACxB,IAAI,CAAC;oBACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;gBAC5C,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YAEL,IAAI,CAAC,sBAAsB,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtD,IAAI,CAAC,KAAK,CACR,0DAA0D,MAAM,CAAC,IAAI,oGAAoG,CAC1K,CAAC;gBACF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;YAC5C,kEAAkE;YAClE,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC;gBAClD,QAAQ,EAAE,IAAI,CAAC,WAAW;gBAC1B,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE;aAC/C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport url from \"url\";\nimport type { RestError } from \"@azure/core-rest-pipeline\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport { diag } from \"@opentelemetry/api\";\nimport type {\n IsSubscribedOptionalParams,\n PublishOptionalParams,\n QuickpulseClientOptionalParams,\n CollectionConfigurationInfo,\n} from \"../../../generated/index.js\";\nimport type { QuickpulseContext } from \"../../../generated/api/index.js\";\nimport { createQuickpulse } from \"../../../generated/api/index.js\";\nimport {\n _isSubscribedSend,\n _isSubscribedDeserialize,\n _publishSend,\n _publishDeserialize,\n} from \"../../../generated/api/operations.js\";\nimport { isSameRegisteredDomain } from \"../redirectUtils.js\";\n\nconst applicationInsightsResource = \"https://monitor.azure.com/.default\";\n\n/**\n * Response type that includes the body and response headers from the Live Metrics service.\n * @internal\n */\nexport interface QuickpulseResponse extends Partial<CollectionConfigurationInfo> {\n /** Whether the instrumentation key is subscribed. */\n xMsQpsSubscribed?: string;\n /** Configuration ETag. */\n xMsQpsConfigurationEtag?: string;\n /** Polling interval hint (only for ping). */\n xMsQpsServicePollingIntervalHint?: string;\n /** Endpoint redirect (only for ping). */\n xMsQpsServiceEndpointRedirectV2?: string;\n}\n\n/**\n * Quickpulse sender class\n * @internal\n */\nexport class QuickpulseSender {\n private quickpulseClient: QuickpulseContext;\n private instrumentationKey: string;\n private endpointUrl: string;\n private credential: TokenCredential;\n private credentialScopes: string[];\n\n constructor(options: {\n endpointUrl: string;\n instrumentationKey: string;\n credential?: TokenCredential;\n credentialScopes?: string | string[];\n }) {\n // Build endpoint using provided configuration or default values\n this.endpointUrl = options.endpointUrl;\n const clientOptions: QuickpulseClientOptionalParams = {\n endpoint: this.endpointUrl,\n };\n\n this.instrumentationKey = options.instrumentationKey;\n this.credential = options.credential as TokenCredential;\n\n // Configure credential scopes\n if (options.credentialScopes) {\n this.credentialScopes = Array.isArray(options.credentialScopes)\n ? options.credentialScopes\n : [options.credentialScopes];\n } else {\n this.credentialScopes = [applicationInsightsResource];\n }\n if (options.credential) {\n clientOptions.credentials = { scopes: this.credentialScopes };\n }\n\n this.quickpulseClient = this.createQuickpulseClient(clientOptions);\n }\n\n private createQuickpulseClient(clientOptions: QuickpulseClientOptionalParams): QuickpulseContext {\n const prefixFromOptions = clientOptions.userAgentOptions?.userAgentPrefix;\n const userAgentPrefix = prefixFromOptions\n ? `${prefixFromOptions} azsdk-js-client`\n : \"azsdk-js-client\";\n const client = createQuickpulse(this.credential, {\n ...clientOptions,\n userAgentOptions: { userAgentPrefix },\n });\n // Handle redirects in HTTP Sender\n client.pipeline.removePolicy({ name: redirectPolicyName });\n return client;\n }\n\n /**\n * isSubscribed Quickpulse service\n * @internal\n */\n async isSubscribed(\n optionalParams: IsSubscribedOptionalParams,\n ): Promise<QuickpulseResponse | undefined> {\n try {\n const response = await _isSubscribedSend(\n this.quickpulseClient,\n this.instrumentationKey,\n optionalParams,\n );\n // Keep optional-body compatibility outside the regenerated deserializer.\n const body =\n response.status === \"200\" && response.body == null\n ? undefined\n : await _isSubscribedDeserialize(response);\n const responseHeaders = response.headers;\n return {\n ...body,\n xMsQpsSubscribed: responseHeaders[\"x-ms-qps-subscribed\"],\n xMsQpsConfigurationEtag: responseHeaders[\"x-ms-qps-configuration-etag\"],\n xMsQpsServicePollingIntervalHint: responseHeaders[\"x-ms-qps-service-polling-interval-hint\"],\n xMsQpsServiceEndpointRedirectV2: responseHeaders[\"x-ms-qps-service-endpoint-redirect-v2\"],\n };\n } catch (error: any) {\n const restError = error as RestError;\n diag.info(\"Failed to ping Quickpulse service\", restError.message);\n }\n return;\n }\n\n /**\n * publish Quickpulse service\n * @internal\n */\n async publish(optionalParams: PublishOptionalParams): Promise<QuickpulseResponse | undefined> {\n try {\n const response = await _publishSend(\n this.quickpulseClient,\n this.instrumentationKey,\n optionalParams,\n );\n const body =\n response.status === \"200\" && response.body == null\n ? undefined\n : await _publishDeserialize(response);\n const responseHeaders = response.headers;\n return {\n ...body,\n xMsQpsSubscribed: responseHeaders[\"x-ms-qps-subscribed\"],\n xMsQpsConfigurationEtag: responseHeaders[\"x-ms-qps-configuration-etag\"],\n };\n } catch (error: any) {\n const restError = error as RestError;\n diag.warn(\"Failed to post Quickpulse service\", restError.message);\n }\n return;\n }\n\n /**\n * Apply a server-issued Live Metrics redirect (`x-ms-qps-service-endpoint-redirect-v2`) by\n * re-pointing the underlying client at the new host.\n *\n * Cross-origin redirects are refused (no state mutated) when the target is neither the configured\n * Live Metrics host nor under a known Azure Monitor ingestion domain suffix. Refusing them is\n * required to prevent an attacker-controlled redirect from causing the bearer auth policy to\n * attach a freshly-signed AAD token (scope `https://monitor.azure.com/.default`) — and the\n * telemetry body — to a foreign host on the next ping/publish call.\n */\n handlePermanentRedirect(location: string | undefined): void {\n if (location) {\n let locUrl: url.URL;\n try {\n locUrl = new url.URL(location);\n } catch {\n return;\n }\n if (!locUrl.host) {\n return;\n }\n\n const currentHost = (() => {\n try {\n return new url.URL(this.endpointUrl).host;\n } catch {\n return \"\";\n }\n })();\n\n if (!isSameRegisteredDomain(currentHost, locUrl.host)) {\n diag.error(\n `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.`,\n );\n return;\n }\n\n this.endpointUrl = \"https://\" + locUrl.host;\n // Recreate the client so subsequent requests use the new endpoint\n this.quickpulseClient = this.createQuickpulseClient({\n endpoint: this.endpointUrl,\n credentials: { scopes: this.credentialScopes },\n });\n }\n }\n}\n"]}
|
|
@@ -28,6 +28,8 @@ export declare class LiveMetrics {
|
|
|
28
28
|
private quickpulseExporter;
|
|
29
29
|
private pingSender;
|
|
30
30
|
private isCollectingData;
|
|
31
|
+
private isShutdown;
|
|
32
|
+
private resetCountersOnActivation;
|
|
31
33
|
private isDeactivating;
|
|
32
34
|
private deactivatingPromise;
|
|
33
35
|
private lastSuccessTime;
|
|
@@ -65,15 +67,17 @@ export declare class LiveMetrics {
|
|
|
65
67
|
*/
|
|
66
68
|
constructor(config: InternalConfig);
|
|
67
69
|
shutdown(): Promise<void>;
|
|
70
|
+
private schedulePing;
|
|
68
71
|
private goQuickpulse;
|
|
69
72
|
private quickPulseDone;
|
|
73
|
+
private restartMetrics;
|
|
70
74
|
activateMetrics(options?: {
|
|
71
75
|
collectionInterval: number;
|
|
72
76
|
}): void;
|
|
73
77
|
/**
|
|
74
78
|
* Deactivate metric collection
|
|
75
79
|
*/
|
|
76
|
-
deactivateMetrics(): Promise<void>;
|
|
80
|
+
deactivateMetrics(preserveConfiguration?: boolean): Promise<void>;
|
|
77
81
|
/**
|
|
78
82
|
* Force flush Meter Provider.
|
|
79
83
|
*/
|
|
@@ -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,CAAC;AA8BlC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAsB7E;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,oBAAoB,CAA8B;IAC1D,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,sBAAsB,CAA8B;IAC5D,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,yBAAyB,CAA8B;IAC/D,OAAO,CAAC,yBAAyB,CAA8B;IAC/D,OAAO,CAAC,mCAAmC,CAA8B;IACzE,OAAO,CAAC,mBAAmB,CAA8B;IAEzD,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,kBAAkB,CAA2B;IACrD,OAAO,CAAC,UAAU,CAAmB;IACrC,OA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,CAAC,OAAO,CAAC,EAAE;QAAE,kBAAkB,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IA8GtE;;OAEG;IACU,iBAAiB,CAAC,qBAAqB,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC5E;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;OAEG;IACI,gBAAgB,IAAI,aAAa,GAAG,SAAS;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"}
|
|
@@ -51,6 +51,8 @@ export class LiveMetrics {
|
|
|
51
51
|
quickpulseExporter;
|
|
52
52
|
pingSender;
|
|
53
53
|
isCollectingData;
|
|
54
|
+
isShutdown = false;
|
|
55
|
+
resetCountersOnActivation = true;
|
|
54
56
|
isDeactivating = false;
|
|
55
57
|
deactivatingPromise;
|
|
56
58
|
lastSuccessTime = Date.now();
|
|
@@ -142,23 +144,28 @@ export class LiveMetrics {
|
|
|
142
144
|
this.isCollectingData = false;
|
|
143
145
|
this.pingInterval = PING_INTERVAL; // Default
|
|
144
146
|
this.postInterval = POST_INTERVAL;
|
|
145
|
-
|
|
146
|
-
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
147
|
-
this.handle.unref(); // Don't block apps from terminating
|
|
147
|
+
this.schedulePing();
|
|
148
148
|
this.lastCpuUsage = process.cpuUsage();
|
|
149
149
|
this.lastHrTime = process.hrtime.bigint();
|
|
150
150
|
}
|
|
151
151
|
async shutdown() {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// reactivate fallback in quickPulseDone(). Delegate to deactivateMetrics()
|
|
155
|
-
// which manages the in-flight deactivation promise so callers (including
|
|
156
|
-
// a concurrent failure-fallback in quickPulseDone) all observe the same
|
|
157
|
-
// completion and shutdown waits for any in-flight deactivation to finish.
|
|
152
|
+
this.isShutdown = true;
|
|
153
|
+
clearTimeout(this.handle);
|
|
158
154
|
this.isCollectingData = false;
|
|
159
155
|
await this.deactivateMetrics();
|
|
160
156
|
}
|
|
157
|
+
schedulePing() {
|
|
158
|
+
clearTimeout(this.handle);
|
|
159
|
+
if (!this.isShutdown && !this.isCollectingData) {
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
161
|
+
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
162
|
+
this.handle.unref();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
161
165
|
async goQuickpulse() {
|
|
166
|
+
if (this.isShutdown) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
162
169
|
if (!this.isCollectingData) {
|
|
163
170
|
// If not collecting, Ping
|
|
164
171
|
try {
|
|
@@ -169,21 +176,22 @@ export class LiveMetrics {
|
|
|
169
176
|
};
|
|
170
177
|
await context.with(suppressTracing(context.active()), async () => {
|
|
171
178
|
const response = await this.pingSender.isSubscribed(params);
|
|
172
|
-
this.quickPulseDone(response);
|
|
179
|
+
await this.quickPulseDone(response);
|
|
173
180
|
});
|
|
174
181
|
}
|
|
175
182
|
catch (error) {
|
|
176
|
-
this.quickPulseDone(undefined);
|
|
183
|
+
await this.quickPulseDone(undefined);
|
|
177
184
|
}
|
|
178
|
-
|
|
179
|
-
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
180
|
-
this.handle.unref();
|
|
185
|
+
this.schedulePing();
|
|
181
186
|
}
|
|
182
187
|
if (this.isCollectingData) {
|
|
183
188
|
this.activateMetrics({ collectionInterval: this.postInterval });
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
191
|
async quickPulseDone(response) {
|
|
192
|
+
if (this.isShutdown) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
187
195
|
if (!response) {
|
|
188
196
|
if (!this.isCollectingData) {
|
|
189
197
|
if (Date.now() - this.lastSuccessTime >= MAX_PING_WAIT_TIME) {
|
|
@@ -191,55 +199,26 @@ export class LiveMetrics {
|
|
|
191
199
|
}
|
|
192
200
|
}
|
|
193
201
|
else {
|
|
194
|
-
if (Date.now() - this.lastSuccessTime >= MAX_POST_WAIT_TIME
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// synchronously from inside the shutdown's export call. If a
|
|
198
|
-
// deactivation is already in flight, bail out — awaiting the
|
|
199
|
-
// in-flight promise here would deadlock the exporter's callback.
|
|
200
|
-
if (this.isDeactivating) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
202
|
+
if (Date.now() - this.lastSuccessTime >= MAX_POST_WAIT_TIME &&
|
|
203
|
+
this.postInterval !== FALLBACK_INTERVAL &&
|
|
204
|
+
!this.isDeactivating) {
|
|
203
205
|
this.postInterval = FALLBACK_INTERVAL;
|
|
204
|
-
|
|
205
|
-
await this.deactivateMetrics();
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
// The exporter invokes postCallback without awaiting it, so a
|
|
209
|
-
// rejection here would surface as an unhandled rejection. Swallow
|
|
210
|
-
// and log so the failure path stays contained.
|
|
211
|
-
Logger.getInstance().warn("Failed to deactivate Live Metrics during failure fallback", error);
|
|
212
|
-
}
|
|
213
|
-
// Reset the success-time baseline so the FALLBACK_INTERVAL backoff
|
|
214
|
-
// can take effect before we consider deactivating again.
|
|
215
|
-
this.lastSuccessTime = Date.now();
|
|
216
|
-
// Re-check after the await: shutdown() may have run concurrently and
|
|
217
|
-
// flipped isCollectingData to false. Don't restart collection in
|
|
218
|
-
// that case — doing so would re-create the meterProvider after
|
|
219
|
-
// shutdown has begun.
|
|
220
|
-
if (this.isCollectingData) {
|
|
221
|
-
this.activateMetrics({ collectionInterval: this.postInterval });
|
|
222
|
-
}
|
|
206
|
+
await this.restartMetrics();
|
|
223
207
|
}
|
|
224
208
|
}
|
|
225
209
|
}
|
|
226
210
|
else {
|
|
211
|
+
const wasBackingOff = this.postInterval !== POST_INTERVAL;
|
|
227
212
|
this.postInterval = POST_INTERVAL;
|
|
228
213
|
// Update using response if needed
|
|
229
214
|
this.lastSuccessTime = Date.now();
|
|
230
215
|
this.isCollectingData =
|
|
231
216
|
response.xMsQpsSubscribed && response.xMsQpsSubscribed === "true" ? true : false;
|
|
232
|
-
if (response.
|
|
217
|
+
if (response.eTag !== undefined &&
|
|
218
|
+
response.xMsQpsConfigurationEtag &&
|
|
219
|
+
this.etag !== response.xMsQpsConfigurationEtag) {
|
|
233
220
|
this.updateConfiguration(response);
|
|
234
221
|
}
|
|
235
|
-
// If collecting was stoped
|
|
236
|
-
if (!this.isCollectingData && this.meterProvider) {
|
|
237
|
-
this.etag = "";
|
|
238
|
-
await this.deactivateMetrics();
|
|
239
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
240
|
-
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
241
|
-
this.handle.unref();
|
|
242
|
-
}
|
|
243
222
|
const endpointRedirect = response.xMsQpsServiceEndpointRedirectV2;
|
|
244
223
|
if (endpointRedirect) {
|
|
245
224
|
this.pingSender.handlePermanentRedirect(endpointRedirect);
|
|
@@ -252,11 +231,35 @@ export class LiveMetrics {
|
|
|
252
231
|
else {
|
|
253
232
|
this.pingInterval = PING_INTERVAL;
|
|
254
233
|
}
|
|
234
|
+
if (!this.isCollectingData && (this.meterProvider || this.isDeactivating)) {
|
|
235
|
+
this.etag = "";
|
|
236
|
+
this.quickpulseExporter.setEtag("");
|
|
237
|
+
await this.restartMetrics(false);
|
|
238
|
+
}
|
|
239
|
+
else if (this.isCollectingData && wasBackingOff && !this.isDeactivating) {
|
|
240
|
+
await this.restartMetrics();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async restartMetrics(preserveConfiguration = true) {
|
|
245
|
+
// A reader's interval is fixed at construction. Preserve collection state when
|
|
246
|
+
// replacing it, and let the shutdown flush update the desired interval.
|
|
247
|
+
try {
|
|
248
|
+
await this.deactivateMetrics(preserveConfiguration);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
Logger.getInstance().warn("Failed to restart Live Metrics collection", error);
|
|
252
|
+
}
|
|
253
|
+
if (this.isCollectingData) {
|
|
254
|
+
this.activateMetrics({ collectionInterval: this.postInterval });
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.schedulePing();
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
260
|
// Activate live metrics collection
|
|
258
261
|
activateMetrics(options) {
|
|
259
|
-
if (this.meterProvider) {
|
|
262
|
+
if (this.meterProvider || this.isDeactivating || this.isShutdown) {
|
|
260
263
|
return;
|
|
261
264
|
}
|
|
262
265
|
// Turn on live metrics active collection for statsbeat
|
|
@@ -264,20 +267,25 @@ export class LiveMetrics {
|
|
|
264
267
|
getInstance().setStatsbeatFeatures({}, { liveMetrics: true });
|
|
265
268
|
this.statsbeatOptionsUpdated = true;
|
|
266
269
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
270
|
+
// Reader replacement must retain both totals and sampling baselines so
|
|
271
|
+
// telemetry recorded during the final flush is collected exactly once.
|
|
272
|
+
if (this.resetCountersOnActivation) {
|
|
273
|
+
this.totalDependencyCount = 0;
|
|
274
|
+
this.totalExceptionCount = 0;
|
|
275
|
+
this.totalFailedDependencyCount = 0;
|
|
276
|
+
this.totalFailedRequestCount = 0;
|
|
277
|
+
this.totalRequestCount = 0;
|
|
278
|
+
this.requestDuration = 0;
|
|
279
|
+
this.dependencyDuration = 0;
|
|
280
|
+
this.lastRequestDuration = { count: 0, duration: 0, time: 0 };
|
|
281
|
+
this.lastRequestRate = { count: 0, time: 0 };
|
|
282
|
+
this.lastFailedRequestRate = { count: 0, time: 0 };
|
|
283
|
+
this.lastDependencyDuration = { count: 0, duration: 0, time: 0 };
|
|
284
|
+
this.lastDependencyRate = { count: 0, time: 0 };
|
|
285
|
+
this.lastFailedDependencyRate = { count: 0, time: 0 };
|
|
286
|
+
this.lastExceptionRate = { count: 0, time: 0 };
|
|
287
|
+
this.resetCountersOnActivation = false;
|
|
288
|
+
}
|
|
281
289
|
const metricReaderOptions = {
|
|
282
290
|
exporter: this.quickpulseExporter,
|
|
283
291
|
exportIntervalMillis: options?.collectionInterval,
|
|
@@ -329,7 +337,17 @@ export class LiveMetrics {
|
|
|
329
337
|
/**
|
|
330
338
|
* Deactivate metric collection
|
|
331
339
|
*/
|
|
332
|
-
async deactivateMetrics() {
|
|
340
|
+
async deactivateMetrics(preserveConfiguration = false) {
|
|
341
|
+
if (!preserveConfiguration) {
|
|
342
|
+
this.resetCountersOnActivation = true;
|
|
343
|
+
this.documents = [];
|
|
344
|
+
this.validDocumentFilterConjuctionGroupInfos.clear();
|
|
345
|
+
this.errorTracker.clearRunTimeErrors();
|
|
346
|
+
this.errorTracker.clearValidationTimeErrors();
|
|
347
|
+
this.validDerivedMetrics.clear();
|
|
348
|
+
this.derivedMetricProjection.clearProjectionMaps();
|
|
349
|
+
this.seenMetricIds.clear();
|
|
350
|
+
}
|
|
333
351
|
// Coalesce concurrent deactivations: callers (shutdown(), the
|
|
334
352
|
// failure-fallback in quickPulseDone(), and the "unsubscribed" branch in
|
|
335
353
|
// goQuickpulse()) can all race. Return the in-flight promise so every
|
|
@@ -341,13 +359,6 @@ export class LiveMetrics {
|
|
|
341
359
|
this.isDeactivating = true;
|
|
342
360
|
this.deactivatingPromise = (async () => {
|
|
343
361
|
try {
|
|
344
|
-
this.documents = [];
|
|
345
|
-
this.validDocumentFilterConjuctionGroupInfos.clear();
|
|
346
|
-
this.errorTracker.clearRunTimeErrors();
|
|
347
|
-
this.errorTracker.clearValidationTimeErrors();
|
|
348
|
-
this.validDerivedMetrics.clear();
|
|
349
|
-
this.derivedMetricProjection.clearProjectionMaps();
|
|
350
|
-
this.seenMetricIds.clear();
|
|
351
362
|
// Capture and clear the reference before awaiting shutdown so any
|
|
352
363
|
// re-entrant calls triggered by the shutdown's final force-flush
|
|
353
364
|
// export observe meterProvider as undefined and exit early.
|
|
@@ -685,7 +696,7 @@ export class LiveMetrics {
|
|
|
685
696
|
}
|
|
686
697
|
}
|
|
687
698
|
parseMetricFilterConfiguration(response) {
|
|
688
|
-
if (!response
|
|
699
|
+
if (!response.metrics || typeof response.metrics.forEach !== "function") {
|
|
689
700
|
return;
|
|
690
701
|
}
|
|
691
702
|
response.metrics.forEach((derivedMetricInfo) => {
|