@azure/monitor-opentelemetry 1.19.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/README.md +7 -3
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
- package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +18 -31
- 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 +14 -8
- package/dist/commonjs/logs/handler.js.map +1 -1
- package/dist/commonjs/metrics/performanceCounters.d.ts +3 -0
- package/dist/commonjs/metrics/performanceCounters.d.ts.map +1 -1
- package/dist/commonjs/metrics/performanceCounters.js +26 -26
- package/dist/commonjs/metrics/performanceCounters.js.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/commonjs/metrics/quickpulse/export/sender.js +29 -23
- 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 +6 -1
- package/dist/commonjs/shared/config.d.ts +7 -0
- package/dist/commonjs/shared/config.d.ts.map +1 -1
- package/dist/commonjs/shared/config.js +27 -6
- package/dist/commonjs/shared/config.js.map +1 -1
- package/dist/commonjs/traces/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 +14 -43
- 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 +11 -2
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +1 -1
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/utils/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/common.d.ts +24 -0
- package/dist/commonjs/utils/common.d.ts.map +1 -1
- package/dist/commonjs/utils/common.js +47 -0
- package/dist/commonjs/utils/common.js.map +1 -1
- package/dist/commonjs/utils/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/commonjs/utils/statsbeat.d.ts.map +1 -1
- package/dist/commonjs/utils/statsbeat.js +3 -1
- package/dist/commonjs/utils/statsbeat.js.map +1 -1
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
- package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +18 -31
- 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 +14 -8
- package/dist/esm/logs/handler.js.map +1 -1
- package/dist/esm/metrics/performanceCounters.d.ts +3 -0
- package/dist/esm/metrics/performanceCounters.d.ts.map +1 -1
- package/dist/esm/metrics/performanceCounters.js +26 -26
- package/dist/esm/metrics/performanceCounters.js.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.d.ts +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.d.ts.map +1 -1
- package/dist/esm/metrics/quickpulse/export/sender.js +29 -23
- 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 +6 -1
- package/dist/esm/shared/config.d.ts +7 -0
- package/dist/esm/shared/config.d.ts.map +1 -1
- package/dist/esm/shared/config.js +28 -7
- package/dist/esm/shared/config.js.map +1 -1
- package/dist/esm/traces/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 +14 -42
- package/dist/esm/traces/handler.js.map +1 -1
- package/dist/esm/traces/sampler.js +1 -1
- package/dist/esm/traces/sampler.js.map +1 -1
- package/dist/esm/types.d.ts +11 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/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/common.d.ts +24 -0
- package/dist/esm/utils/common.d.ts.map +1 -1
- package/dist/esm/utils/common.js +45 -0
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/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/dist/esm/utils/statsbeat.d.ts.map +1 -1
- package/dist/esm/utils/statsbeat.js +4 -2
- package/dist/esm/utils/statsbeat.js.map +1 -1
- package/package.json +33 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,8DAAyB;AAQzB,4CAAyD;AAEzD,0FAAmF;AAKnF,4DAA0F;AAE1F,yCAA2D;AAC3D,8CAA2D;AAE3D,oDAAoE;AAEpE,2DAAqD;AACrD,yCAAiD;AACjD,wEAAmC;AAEnC;;GAEG;AACH,MAAa,yBAAyB;IAC5B,cAAc,CAAmC;IACjD,kBAAkB,GAAG,KAAK,CAAC,CAAC,aAAa;IACzC,aAAa,CAAgB;IAC7B,aAAa,CAA6B;IAC1C,KAAK,CAAQ;IACb,wBAAwB,CAAY;IACpC,gBAAgB,CAAkB;IAClC,wBAAwB,CAAqB;IAC7C,uBAAuB,CAAkB;IACzC,+BAA+B,CAAqB;IACpD,yBAAyB,CAAkB;IAC3C,iCAAiC,CAAqB;IACtD,kBAAkB,CAAkB;IACpC,0BAA0B,CAAqB;IAC/C,0BAA0B,CAAkB;IAC5C,kCAAkC,CAAqB;IACvD,gBAAgB,CAAkB;IAClC,wBAAwB,CAAqB;IAC7C,mBAAmB,CAAkB;IACrC,2BAA2B,CAAqB;IAChD,i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iB,CAAC,IAAI,CAAC;QAC5D,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,cAAc,GAAG,SAAS,GAAG,IAAI,CAAC;YACxC,MAAM,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;YACjD,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF;AAzXD,8DAyXC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number } = { count: 0, time: 0 };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
|
|
1
|
+
{"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,kCAAkC;AACl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M,CAAC;gBACzB,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;gBACvE,MAAM,KAAK,GACT,aAAa,KAAK,SAAS;oBACzB,CAAC,CAAC,aAAa;oBACf,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;gBAC5D,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,kBAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,gBAAkC;QACzD,MAAM,WAAW,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC,CAAC;QAClF,MAAM,SAAS,GAAG,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;QAC5D,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,cAAc,GAAG,SAAS,GAAG,IAAI,CAAC;YACxC,MAAM,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;YACjD,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF;AAlYD,8DAkYC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastAppCpuUsageNormalized: { user: number; system: number };\n private lastHrtimeNormalized: number[];\n private lastCpusProcessNormalized: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n this.lastCpusProcessNormalized = os.cpus();\n this.lastAppCpuUsageNormalized = process.cpuUsage();\n this.lastHrtimeNormalized = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcessNormalized &&\n cpus.length === this.lastCpusProcessNormalized.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsageNormalized.user +\n (appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;\n\n if (\n typeof this.lastHrtimeNormalized !== \"undefined\" &&\n this.lastHrtimeNormalized.length === 2\n ) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +\n (hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsageNormalized = appCpuUsage;\n this.lastHrtimeNormalized = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);\n const value =\n appCpuPercent !== undefined\n ? appCpuPercent\n : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n observableResult.observe(value);\n }\n this.lastCpusProcessNormalized = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n const value =\n appCpuPercent !== undefined\n ? appCpuPercent\n : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
|
|
@@ -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"}
|
|
@@ -7,7 +7,8 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
const url_1 = tslib_1.__importDefault(require("url"));
|
|
8
8
|
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
|
|
9
9
|
const api_1 = require("@opentelemetry/api");
|
|
10
|
-
const index_js_1 = require("../../../generated/index.js");
|
|
10
|
+
const index_js_1 = require("../../../generated/api/index.js");
|
|
11
|
+
const operations_js_1 = require("../../../generated/api/operations.js");
|
|
11
12
|
const redirectUtils_js_1 = require("../redirectUtils.js");
|
|
12
13
|
const applicationInsightsResource = "https://monitor.azure.com/.default";
|
|
13
14
|
/**
|
|
@@ -43,7 +44,14 @@ class QuickpulseSender {
|
|
|
43
44
|
this.quickpulseClient = this.createQuickpulseClient(clientOptions);
|
|
44
45
|
}
|
|
45
46
|
createQuickpulseClient(clientOptions) {
|
|
46
|
-
const
|
|
47
|
+
const prefixFromOptions = clientOptions.userAgentOptions?.userAgentPrefix;
|
|
48
|
+
const userAgentPrefix = prefixFromOptions
|
|
49
|
+
? `${prefixFromOptions} azsdk-js-client`
|
|
50
|
+
: "azsdk-js-client";
|
|
51
|
+
const client = (0, index_js_1.createQuickpulse)(this.credential, {
|
|
52
|
+
...clientOptions,
|
|
53
|
+
userAgentOptions: { userAgentPrefix },
|
|
54
|
+
});
|
|
47
55
|
// Handle redirects in HTTP Sender
|
|
48
56
|
client.pipeline.removePolicy({ name: core_rest_pipeline_1.redirectPolicyName });
|
|
49
57
|
return client;
|
|
@@ -54,13 +62,12 @@ class QuickpulseSender {
|
|
|
54
62
|
*/
|
|
55
63
|
async isSubscribed(optionalParams) {
|
|
56
64
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
65
|
+
const response = await (0, operations_js_1._isSubscribedSend)(this.quickpulseClient, this.instrumentationKey, optionalParams);
|
|
66
|
+
// Keep optional-body compatibility outside the regenerated deserializer.
|
|
67
|
+
const body = response.status === "200" && response.body == null
|
|
68
|
+
? undefined
|
|
69
|
+
: await (0, operations_js_1._isSubscribedDeserialize)(response);
|
|
70
|
+
const responseHeaders = response.headers;
|
|
64
71
|
return {
|
|
65
72
|
...body,
|
|
66
73
|
xMsQpsSubscribed: responseHeaders["x-ms-qps-subscribed"],
|
|
@@ -81,13 +88,11 @@ class QuickpulseSender {
|
|
|
81
88
|
*/
|
|
82
89
|
async publish(optionalParams) {
|
|
83
90
|
try {
|
|
84
|
-
|
|
85
|
-
const body =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
+
const response = await (0, operations_js_1._publishSend)(this.quickpulseClient, this.instrumentationKey, optionalParams);
|
|
92
|
+
const body = response.status === "200" && response.body == null
|
|
93
|
+
? undefined
|
|
94
|
+
: await (0, operations_js_1._publishDeserialize)(response);
|
|
95
|
+
const responseHeaders = response.headers;
|
|
91
96
|
return {
|
|
92
97
|
...body,
|
|
93
98
|
xMsQpsSubscribed: responseHeaders["x-ms-qps-subscribed"],
|
|
@@ -122,13 +127,14 @@ class QuickpulseSender {
|
|
|
122
127
|
if (!locUrl.host) {
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const currentHost = (() => {
|
|
131
|
+
try {
|
|
132
|
+
return new url_1.default.URL(this.endpointUrl).host;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return "";
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
132
138
|
if (!(0, redirectUtils_js_1.isSameRegisteredDomain)(currentHost, locUrl.host)) {
|
|
133
139
|
api_1.diag.error(`Refusing cross-origin Live Metrics redirect to https://${locUrl.host}: target is neither the configured endpoint host nor under a known Azure Monitor ingestion domain.`);
|
|
134
140
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.js","sourceRoot":"","sources":["../../../../../src/metrics/quickpulse/export/sender.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,sDAAsB;AAEtB,kEAA+D;AAE/D,4CAA0C;AAO1C,0DAA+D;AAC/D,0DAA6D;AAE7D,MAAM,2BAA2B,GAAG,oCAAoC,CAAC;AAiBzE;;;GAGG;AACH,MAAa,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,gBAAgB,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,gBAAgB,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,aAAa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C,IAAI,CAAC,EAAE,CAAC;gBACtD,UAAI,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;AA9ID,4CA8IC","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 let currentHost = \"\";\n try {\n currentHost = new url.URL(this.endpointUrl).host;\n } catch {\n currentHost = \"\";\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,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gBACZ,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YAEL,IAAI,CAAC,IAAA,yCAAsB,EAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtD,UAAI,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;AA7JD,4CA6JC","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,OA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,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"}
|
|
@@ -55,6 +55,8 @@ class LiveMetrics {
|
|
|
55
55
|
quickpulseExporter;
|
|
56
56
|
pingSender;
|
|
57
57
|
isCollectingData;
|
|
58
|
+
isShutdown = false;
|
|
59
|
+
resetCountersOnActivation = true;
|
|
58
60
|
isDeactivating = false;
|
|
59
61
|
deactivatingPromise;
|
|
60
62
|
lastSuccessTime = Date.now();
|
|
@@ -146,23 +148,28 @@ class LiveMetrics {
|
|
|
146
148
|
this.isCollectingData = false;
|
|
147
149
|
this.pingInterval = PING_INTERVAL; // Default
|
|
148
150
|
this.postInterval = POST_INTERVAL;
|
|
149
|
-
|
|
150
|
-
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
151
|
-
this.handle.unref(); // Don't block apps from terminating
|
|
151
|
+
this.schedulePing();
|
|
152
152
|
this.lastCpuUsage = process.cpuUsage();
|
|
153
153
|
this.lastHrTime = process.hrtime.bigint();
|
|
154
154
|
}
|
|
155
155
|
async shutdown() {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// reactivate fallback in quickPulseDone(). Delegate to deactivateMetrics()
|
|
159
|
-
// which manages the in-flight deactivation promise so callers (including
|
|
160
|
-
// a concurrent failure-fallback in quickPulseDone) all observe the same
|
|
161
|
-
// completion and shutdown waits for any in-flight deactivation to finish.
|
|
156
|
+
this.isShutdown = true;
|
|
157
|
+
clearTimeout(this.handle);
|
|
162
158
|
this.isCollectingData = false;
|
|
163
159
|
await this.deactivateMetrics();
|
|
164
160
|
}
|
|
161
|
+
schedulePing() {
|
|
162
|
+
clearTimeout(this.handle);
|
|
163
|
+
if (!this.isShutdown && !this.isCollectingData) {
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
165
|
+
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
166
|
+
this.handle.unref();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
165
169
|
async goQuickpulse() {
|
|
170
|
+
if (this.isShutdown) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
166
173
|
if (!this.isCollectingData) {
|
|
167
174
|
// If not collecting, Ping
|
|
168
175
|
try {
|
|
@@ -173,21 +180,22 @@ class LiveMetrics {
|
|
|
173
180
|
};
|
|
174
181
|
await api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), async () => {
|
|
175
182
|
const response = await this.pingSender.isSubscribed(params);
|
|
176
|
-
this.quickPulseDone(response);
|
|
183
|
+
await this.quickPulseDone(response);
|
|
177
184
|
});
|
|
178
185
|
}
|
|
179
186
|
catch (error) {
|
|
180
|
-
this.quickPulseDone(undefined);
|
|
187
|
+
await this.quickPulseDone(undefined);
|
|
181
188
|
}
|
|
182
|
-
|
|
183
|
-
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
184
|
-
this.handle.unref();
|
|
189
|
+
this.schedulePing();
|
|
185
190
|
}
|
|
186
191
|
if (this.isCollectingData) {
|
|
187
192
|
this.activateMetrics({ collectionInterval: this.postInterval });
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
async quickPulseDone(response) {
|
|
196
|
+
if (this.isShutdown) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
191
199
|
if (!response) {
|
|
192
200
|
if (!this.isCollectingData) {
|
|
193
201
|
if (Date.now() - this.lastSuccessTime >= MAX_PING_WAIT_TIME) {
|
|
@@ -195,55 +203,26 @@ class LiveMetrics {
|
|
|
195
203
|
}
|
|
196
204
|
}
|
|
197
205
|
else {
|
|
198
|
-
if (Date.now() - this.lastSuccessTime >= MAX_POST_WAIT_TIME
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// synchronously from inside the shutdown's export call. If a
|
|
202
|
-
// deactivation is already in flight, bail out — awaiting the
|
|
203
|
-
// in-flight promise here would deadlock the exporter's callback.
|
|
204
|
-
if (this.isDeactivating) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
206
|
+
if (Date.now() - this.lastSuccessTime >= MAX_POST_WAIT_TIME &&
|
|
207
|
+
this.postInterval !== FALLBACK_INTERVAL &&
|
|
208
|
+
!this.isDeactivating) {
|
|
207
209
|
this.postInterval = FALLBACK_INTERVAL;
|
|
208
|
-
|
|
209
|
-
await this.deactivateMetrics();
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
// The exporter invokes postCallback without awaiting it, so a
|
|
213
|
-
// rejection here would surface as an unhandled rejection. Swallow
|
|
214
|
-
// and log so the failure path stays contained.
|
|
215
|
-
logger_js_1.Logger.getInstance().warn("Failed to deactivate Live Metrics during failure fallback", error);
|
|
216
|
-
}
|
|
217
|
-
// Reset the success-time baseline so the FALLBACK_INTERVAL backoff
|
|
218
|
-
// can take effect before we consider deactivating again.
|
|
219
|
-
this.lastSuccessTime = Date.now();
|
|
220
|
-
// Re-check after the await: shutdown() may have run concurrently and
|
|
221
|
-
// flipped isCollectingData to false. Don't restart collection in
|
|
222
|
-
// that case — doing so would re-create the meterProvider after
|
|
223
|
-
// shutdown has begun.
|
|
224
|
-
if (this.isCollectingData) {
|
|
225
|
-
this.activateMetrics({ collectionInterval: this.postInterval });
|
|
226
|
-
}
|
|
210
|
+
await this.restartMetrics();
|
|
227
211
|
}
|
|
228
212
|
}
|
|
229
213
|
}
|
|
230
214
|
else {
|
|
215
|
+
const wasBackingOff = this.postInterval !== POST_INTERVAL;
|
|
231
216
|
this.postInterval = POST_INTERVAL;
|
|
232
217
|
// Update using response if needed
|
|
233
218
|
this.lastSuccessTime = Date.now();
|
|
234
219
|
this.isCollectingData =
|
|
235
220
|
response.xMsQpsSubscribed && response.xMsQpsSubscribed === "true" ? true : false;
|
|
236
|
-
if (response.
|
|
221
|
+
if (response.eTag !== undefined &&
|
|
222
|
+
response.xMsQpsConfigurationEtag &&
|
|
223
|
+
this.etag !== response.xMsQpsConfigurationEtag) {
|
|
237
224
|
this.updateConfiguration(response);
|
|
238
225
|
}
|
|
239
|
-
// If collecting was stoped
|
|
240
|
-
if (!this.isCollectingData && this.meterProvider) {
|
|
241
|
-
this.etag = "";
|
|
242
|
-
await this.deactivateMetrics();
|
|
243
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
244
|
-
this.handle = setTimeout(this.goQuickpulse.bind(this), this.pingInterval);
|
|
245
|
-
this.handle.unref();
|
|
246
|
-
}
|
|
247
226
|
const endpointRedirect = response.xMsQpsServiceEndpointRedirectV2;
|
|
248
227
|
if (endpointRedirect) {
|
|
249
228
|
this.pingSender.handlePermanentRedirect(endpointRedirect);
|
|
@@ -256,11 +235,35 @@ class LiveMetrics {
|
|
|
256
235
|
else {
|
|
257
236
|
this.pingInterval = PING_INTERVAL;
|
|
258
237
|
}
|
|
238
|
+
if (!this.isCollectingData && (this.meterProvider || this.isDeactivating)) {
|
|
239
|
+
this.etag = "";
|
|
240
|
+
this.quickpulseExporter.setEtag("");
|
|
241
|
+
await this.restartMetrics(false);
|
|
242
|
+
}
|
|
243
|
+
else if (this.isCollectingData && wasBackingOff && !this.isDeactivating) {
|
|
244
|
+
await this.restartMetrics();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async restartMetrics(preserveConfiguration = true) {
|
|
249
|
+
// A reader's interval is fixed at construction. Preserve collection state when
|
|
250
|
+
// replacing it, and let the shutdown flush update the desired interval.
|
|
251
|
+
try {
|
|
252
|
+
await this.deactivateMetrics(preserveConfiguration);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
logger_js_1.Logger.getInstance().warn("Failed to restart Live Metrics collection", error);
|
|
256
|
+
}
|
|
257
|
+
if (this.isCollectingData) {
|
|
258
|
+
this.activateMetrics({ collectionInterval: this.postInterval });
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
this.schedulePing();
|
|
259
262
|
}
|
|
260
263
|
}
|
|
261
264
|
// Activate live metrics collection
|
|
262
265
|
activateMetrics(options) {
|
|
263
|
-
if (this.meterProvider) {
|
|
266
|
+
if (this.meterProvider || this.isDeactivating || this.isShutdown) {
|
|
264
267
|
return;
|
|
265
268
|
}
|
|
266
269
|
// Turn on live metrics active collection for statsbeat
|
|
@@ -268,20 +271,25 @@ class LiveMetrics {
|
|
|
268
271
|
(0, statsbeat_js_1.getInstance)().setStatsbeatFeatures({}, { liveMetrics: true });
|
|
269
272
|
this.statsbeatOptionsUpdated = true;
|
|
270
273
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
274
|
+
// Reader replacement must retain both totals and sampling baselines so
|
|
275
|
+
// telemetry recorded during the final flush is collected exactly once.
|
|
276
|
+
if (this.resetCountersOnActivation) {
|
|
277
|
+
this.totalDependencyCount = 0;
|
|
278
|
+
this.totalExceptionCount = 0;
|
|
279
|
+
this.totalFailedDependencyCount = 0;
|
|
280
|
+
this.totalFailedRequestCount = 0;
|
|
281
|
+
this.totalRequestCount = 0;
|
|
282
|
+
this.requestDuration = 0;
|
|
283
|
+
this.dependencyDuration = 0;
|
|
284
|
+
this.lastRequestDuration = { count: 0, duration: 0, time: 0 };
|
|
285
|
+
this.lastRequestRate = { count: 0, time: 0 };
|
|
286
|
+
this.lastFailedRequestRate = { count: 0, time: 0 };
|
|
287
|
+
this.lastDependencyDuration = { count: 0, duration: 0, time: 0 };
|
|
288
|
+
this.lastDependencyRate = { count: 0, time: 0 };
|
|
289
|
+
this.lastFailedDependencyRate = { count: 0, time: 0 };
|
|
290
|
+
this.lastExceptionRate = { count: 0, time: 0 };
|
|
291
|
+
this.resetCountersOnActivation = false;
|
|
292
|
+
}
|
|
285
293
|
const metricReaderOptions = {
|
|
286
294
|
exporter: this.quickpulseExporter,
|
|
287
295
|
exportIntervalMillis: options?.collectionInterval,
|
|
@@ -333,7 +341,17 @@ class LiveMetrics {
|
|
|
333
341
|
/**
|
|
334
342
|
* Deactivate metric collection
|
|
335
343
|
*/
|
|
336
|
-
async deactivateMetrics() {
|
|
344
|
+
async deactivateMetrics(preserveConfiguration = false) {
|
|
345
|
+
if (!preserveConfiguration) {
|
|
346
|
+
this.resetCountersOnActivation = true;
|
|
347
|
+
this.documents = [];
|
|
348
|
+
this.validDocumentFilterConjuctionGroupInfos.clear();
|
|
349
|
+
this.errorTracker.clearRunTimeErrors();
|
|
350
|
+
this.errorTracker.clearValidationTimeErrors();
|
|
351
|
+
this.validDerivedMetrics.clear();
|
|
352
|
+
this.derivedMetricProjection.clearProjectionMaps();
|
|
353
|
+
this.seenMetricIds.clear();
|
|
354
|
+
}
|
|
337
355
|
// Coalesce concurrent deactivations: callers (shutdown(), the
|
|
338
356
|
// failure-fallback in quickPulseDone(), and the "unsubscribed" branch in
|
|
339
357
|
// goQuickpulse()) can all race. Return the in-flight promise so every
|
|
@@ -345,13 +363,6 @@ class LiveMetrics {
|
|
|
345
363
|
this.isDeactivating = true;
|
|
346
364
|
this.deactivatingPromise = (async () => {
|
|
347
365
|
try {
|
|
348
|
-
this.documents = [];
|
|
349
|
-
this.validDocumentFilterConjuctionGroupInfos.clear();
|
|
350
|
-
this.errorTracker.clearRunTimeErrors();
|
|
351
|
-
this.errorTracker.clearValidationTimeErrors();
|
|
352
|
-
this.validDerivedMetrics.clear();
|
|
353
|
-
this.derivedMetricProjection.clearProjectionMaps();
|
|
354
|
-
this.seenMetricIds.clear();
|
|
355
366
|
// Capture and clear the reference before awaiting shutdown so any
|
|
356
367
|
// re-entrant calls triggered by the shutdown's final force-flush
|
|
357
368
|
// export observe meterProvider as undefined and exit early.
|
|
@@ -689,7 +700,7 @@ class LiveMetrics {
|
|
|
689
700
|
}
|
|
690
701
|
}
|
|
691
702
|
parseMetricFilterConfiguration(response) {
|
|
692
|
-
if (!response
|
|
703
|
+
if (!response.metrics || typeof response.metrics.forEach !== "function") {
|
|
693
704
|
return;
|
|
694
705
|
}
|
|
695
706
|
response.metrics.forEach((derivedMetricInfo) => {
|