@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.
Files changed (117) hide show
  1. package/README.md +7 -3
  2. package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
  3. package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
  4. package/dist/commonjs/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
  5. package/dist/commonjs/index.d.ts +2 -2
  6. package/dist/commonjs/index.d.ts.map +1 -1
  7. package/dist/commonjs/index.js +18 -31
  8. package/dist/commonjs/index.js.map +1 -1
  9. package/dist/commonjs/logs/handler.d.ts +2 -1
  10. package/dist/commonjs/logs/handler.d.ts.map +1 -1
  11. package/dist/commonjs/logs/handler.js +14 -8
  12. package/dist/commonjs/logs/handler.js.map +1 -1
  13. package/dist/commonjs/metrics/performanceCounters.d.ts +3 -0
  14. package/dist/commonjs/metrics/performanceCounters.d.ts.map +1 -1
  15. package/dist/commonjs/metrics/performanceCounters.js +26 -26
  16. package/dist/commonjs/metrics/performanceCounters.js.map +1 -1
  17. package/dist/commonjs/metrics/quickpulse/export/sender.d.ts +1 -1
  18. package/dist/commonjs/metrics/quickpulse/export/sender.d.ts.map +1 -1
  19. package/dist/commonjs/metrics/quickpulse/export/sender.js +29 -23
  20. package/dist/commonjs/metrics/quickpulse/export/sender.js.map +1 -1
  21. package/dist/commonjs/metrics/quickpulse/liveMetrics.d.ts +5 -1
  22. package/dist/commonjs/metrics/quickpulse/liveMetrics.d.ts.map +1 -1
  23. package/dist/commonjs/metrics/quickpulse/liveMetrics.js +86 -75
  24. package/dist/commonjs/metrics/quickpulse/liveMetrics.js.map +1 -1
  25. package/dist/commonjs/package.json +6 -1
  26. package/dist/commonjs/shared/config.d.ts +7 -0
  27. package/dist/commonjs/shared/config.d.ts.map +1 -1
  28. package/dist/commonjs/shared/config.js +27 -6
  29. package/dist/commonjs/shared/config.js.map +1 -1
  30. package/dist/commonjs/traces/azureSdkInstrumentation.d.ts +12 -0
  31. package/dist/commonjs/traces/azureSdkInstrumentation.d.ts.map +1 -0
  32. package/dist/commonjs/traces/azureSdkInstrumentation.js +64 -0
  33. package/dist/commonjs/traces/azureSdkInstrumentation.js.map +1 -0
  34. package/dist/commonjs/traces/handler.d.ts +2 -13
  35. package/dist/commonjs/traces/handler.d.ts.map +1 -1
  36. package/dist/commonjs/traces/handler.js +14 -43
  37. package/dist/commonjs/traces/handler.js.map +1 -1
  38. package/dist/commonjs/traces/sampler.js +1 -1
  39. package/dist/commonjs/traces/sampler.js.map +1 -1
  40. package/dist/commonjs/tsdoc-metadata.json +1 -1
  41. package/dist/commonjs/types.d.ts +11 -2
  42. package/dist/commonjs/types.d.ts.map +1 -1
  43. package/dist/commonjs/types.js +1 -1
  44. package/dist/commonjs/types.js.map +1 -1
  45. package/dist/commonjs/utils/azureSdkTracingBridge.d.ts +4 -4
  46. package/dist/commonjs/utils/azureSdkTracingBridge.d.ts.map +1 -1
  47. package/dist/commonjs/utils/azureSdkTracingBridge.js +10 -8
  48. package/dist/commonjs/utils/azureSdkTracingBridge.js.map +1 -1
  49. package/dist/commonjs/utils/common.d.ts +24 -0
  50. package/dist/commonjs/utils/common.d.ts.map +1 -1
  51. package/dist/commonjs/utils/common.js +47 -0
  52. package/dist/commonjs/utils/common.js.map +1 -1
  53. package/dist/commonjs/utils/instrumentation.d.ts +8 -0
  54. package/dist/commonjs/utils/instrumentation.d.ts.map +1 -0
  55. package/dist/commonjs/utils/instrumentation.js +26 -0
  56. package/dist/commonjs/utils/instrumentation.js.map +1 -0
  57. package/dist/commonjs/utils/statsbeat.d.ts.map +1 -1
  58. package/dist/commonjs/utils/statsbeat.js +3 -1
  59. package/dist/commonjs/utils/statsbeat.js.map +1 -1
  60. package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.d.ts.map +1 -1
  61. package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js +1 -2
  62. package/dist/esm/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
  63. package/dist/esm/index.d.ts +2 -2
  64. package/dist/esm/index.d.ts.map +1 -1
  65. package/dist/esm/index.js +18 -31
  66. package/dist/esm/index.js.map +1 -1
  67. package/dist/esm/logs/handler.d.ts +2 -1
  68. package/dist/esm/logs/handler.d.ts.map +1 -1
  69. package/dist/esm/logs/handler.js +14 -8
  70. package/dist/esm/logs/handler.js.map +1 -1
  71. package/dist/esm/metrics/performanceCounters.d.ts +3 -0
  72. package/dist/esm/metrics/performanceCounters.d.ts.map +1 -1
  73. package/dist/esm/metrics/performanceCounters.js +26 -26
  74. package/dist/esm/metrics/performanceCounters.js.map +1 -1
  75. package/dist/esm/metrics/quickpulse/export/sender.d.ts +1 -1
  76. package/dist/esm/metrics/quickpulse/export/sender.d.ts.map +1 -1
  77. package/dist/esm/metrics/quickpulse/export/sender.js +29 -23
  78. package/dist/esm/metrics/quickpulse/export/sender.js.map +1 -1
  79. package/dist/esm/metrics/quickpulse/liveMetrics.d.ts +5 -1
  80. package/dist/esm/metrics/quickpulse/liveMetrics.d.ts.map +1 -1
  81. package/dist/esm/metrics/quickpulse/liveMetrics.js +86 -75
  82. package/dist/esm/metrics/quickpulse/liveMetrics.js.map +1 -1
  83. package/dist/esm/package.json +6 -1
  84. package/dist/esm/shared/config.d.ts +7 -0
  85. package/dist/esm/shared/config.d.ts.map +1 -1
  86. package/dist/esm/shared/config.js +28 -7
  87. package/dist/esm/shared/config.js.map +1 -1
  88. package/dist/esm/traces/azureSdkInstrumentation.d.ts +12 -0
  89. package/dist/esm/traces/azureSdkInstrumentation.d.ts.map +1 -0
  90. package/dist/esm/traces/azureSdkInstrumentation.js +60 -0
  91. package/dist/esm/traces/azureSdkInstrumentation.js.map +1 -0
  92. package/dist/esm/traces/handler.d.ts +2 -13
  93. package/dist/esm/traces/handler.d.ts.map +1 -1
  94. package/dist/esm/traces/handler.js +14 -42
  95. package/dist/esm/traces/handler.js.map +1 -1
  96. package/dist/esm/traces/sampler.js +1 -1
  97. package/dist/esm/traces/sampler.js.map +1 -1
  98. package/dist/esm/types.d.ts +11 -2
  99. package/dist/esm/types.d.ts.map +1 -1
  100. package/dist/esm/types.js +1 -1
  101. package/dist/esm/types.js.map +1 -1
  102. package/dist/esm/utils/azureSdkTracingBridge.d.ts +4 -4
  103. package/dist/esm/utils/azureSdkTracingBridge.d.ts.map +1 -1
  104. package/dist/esm/utils/azureSdkTracingBridge.js +11 -7
  105. package/dist/esm/utils/azureSdkTracingBridge.js.map +1 -1
  106. package/dist/esm/utils/common.d.ts +24 -0
  107. package/dist/esm/utils/common.d.ts.map +1 -1
  108. package/dist/esm/utils/common.js +45 -0
  109. package/dist/esm/utils/common.js.map +1 -1
  110. package/dist/esm/utils/instrumentation.d.ts +8 -0
  111. package/dist/esm/utils/instrumentation.d.ts.map +1 -0
  112. package/dist/esm/utils/instrumentation.js +23 -0
  113. package/dist/esm/utils/instrumentation.js.map +1 -0
  114. package/dist/esm/utils/statsbeat.d.ts.map +1 -1
  115. package/dist/esm/utils/statsbeat.js +4 -2
  116. package/dist/esm/utils/statsbeat.js.map +1 -1
  117. package/package.json +33 -30
@@ -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,23 +60,26 @@ 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(new BunyanInstrumentation({
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(new WinstonInstrumentation({
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
- if (this._config.instrumentationOptions.console?.enabled) {
74
+ const consoleOptions = this._config.instrumentationOptions.console;
75
+ if (consoleOptions?.enabled) {
72
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.
73
79
  const consoleInstrumentation = new ConsoleInstrumentation({
74
- ...this._config.instrumentationOptions.console,
80
+ ...consoleOptions,
75
81
  enabled: false,
76
- logSeverity,
82
+ logSeverity: consoleOptions.logSeverity ?? logSeverity,
77
83
  });
78
84
  this._consoleInstrumentation = consoleInstrumentation;
79
85
  this._instrumentations.push(consoleInstrumentation);
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,k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tD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzureMonitorLogExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BunyanInstrumentation } from \"@opentelemetry/instrumentation-bunyan\";\nimport { ConsoleInstrumentation } from \"@opentelemetry/instrumentation-console\";\nimport { WinstonInstrumentation } from \"@opentelemetry/instrumentation-winston\";\nimport type { BatchLogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport type { InternalConfig } from \"../shared/config.js\";\nimport type { MetricHandler } from \"../metrics/handler.js\";\nimport { AzureLogRecordProcessor } from \"./logRecordProcessor.js\";\nimport { AzureBatchLogRecordProcessor } from \"./batchLogRecordProcessor.js\";\nimport { isLogCollectionDisabled, logLevelToSeverityNumber } from \"../utils/logUtils.js\";\n\n/**\n * Azure Monitor OpenTelemetry Log Handler\n */\nexport class LogHandler {\n private _azureExporter: AzureMonitorLogExporter;\n private _azureLogRecordProcessor: AzureLogRecordProcessor;\n private _azureBatchLogRecordProcessor: AzureBatchLogRecordProcessor;\n private _metricHandler: MetricHandler;\n private _config: InternalConfig;\n private _instrumentations: Instrumentation[];\n private _consoleInstrumentation: Instrumentation | undefined;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Distro configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);\n this._azureBatchLogRecordProcessor = new AzureBatchLogRecordProcessor(this._azureExporter, {\n enableTraceBasedSamplingForLogs: this._config.enableTraceBasedSamplingForLogs,\n });\n this._azureLogRecordProcessor = new AzureLogRecordProcessor(this._metricHandler);\n this._instrumentations = [];\n this._initializeInstrumentations();\n }\n\n public getAzureLogRecordProcessor(): AzureLogRecordProcessor {\n return this._azureLogRecordProcessor;\n }\n\n public getBatchLogRecordProcessor(): BatchLogRecordProcessor {\n return this._azureBatchLogRecordProcessor;\n }\n\n public getInstrumentations(): Instrumentation[] {\n return this._instrumentations;\n }\n\n /** Returns the console instrumentation for explicit lifecycle management. */\n public getConsoleInstrumentation(): Instrumentation | undefined {\n return this._consoleInstrumentation;\n }\n\n /**\n * Start auto collection of telemetry\n */\n private _initializeInstrumentations(): void {\n if (isLogCollectionDisabled()) {\n return;\n }\n\n const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;\n const logSeverity = logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined;\n\n if (this._config.instrumentationOptions.bunyan?.enabled) {\n this._instrumentations.push(\n new BunyanInstrumentation({\n ...this._config.instrumentationOptions.bunyan,\n logSeverity,\n }),\n );\n }\n if (this._config.instrumentationOptions.winston?.enabled) {\n this._instrumentations.push(\n new WinstonInstrumentation({\n ...this._config.instrumentationOptions.winston,\n logSeverity,\n }),\n );\n }\n if (this._config.instrumentationOptions.console?.enabled) {\n // Defer patching until registration so construction preserves the original methods.\n const consoleInstrumentation = new ConsoleInstrumentation({\n ...this._config.instrumentationOptions.console,\n enabled: false,\n logSeverity,\n });\n this._consoleInstrumentation = consoleInstrumentation;\n this._instrumentations.push(consoleInstrumentation);\n }\n }\n}\n"]}
1
+ {"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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AAE,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"]}
@@ -34,6 +34,9 @@ export declare class PerformanceCounterMetrics {
34
34
  private lastHrtime;
35
35
  private lastCpus;
36
36
  private lastCpusProcess;
37
+ private lastAppCpuUsageNormalized;
38
+ private lastHrtimeNormalized;
39
+ private lastCpusProcessNormalized;
37
40
  private totalExceptionCount;
38
41
  /**
39
42
  * Creates performance counter instruments.
@@ -1 +1 @@
1
- {"version":3,"file":"performanceCounters.d.ts","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAM5D,OAAO,EAAE,aAAa,EAAiC,MAAM,4BAA4B,CAAC;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,+BAA+B,CAAC;AAG9E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AAOpE;;GAEG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,wBAAwB,CAAY;IAC5C,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,uBAAuB,CAAkB;IACjD,OAAO,CAAC,+BAA+B,CAAqB;IAC5D,OAAO,CAAC,yBAAyB,CAAkB;IACnD,OAAO,CAAC,iCAAiC,CAAqB;IAC9D,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,0BAA0B,CAAqB;IACvD,OAAO,CAAC,0BAA0B,CAAkB;IACpD,OAAO,CAAC,kCAAkC,CAAqB;IAC/D,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,wBAAwB,CAAqB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AM,CAAA;KAAE;IAkG9F;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;OAEG;IACI,gBAAgB,IAAI,aAAa;IAIxC;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAkB3C;;;OAGG;IACI,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAO/C,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,mBAAmB;IAwC3B,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,wBAAwB;IA0ChC,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -34,7 +34,7 @@ export class PerformanceCounterMetrics {
34
34
  processTimeGaugeCallback;
35
35
  exceptionCountGauge;
36
36
  exceptionCountGaugeCallback;
37
- lastExceptionRate = { count: 0, time: 0 };
37
+ lastExceptionRate;
38
38
  totalCount = 0;
39
39
  intervalExecutionTime = 0;
40
40
  lastRequestRate;
@@ -42,6 +42,9 @@ export class PerformanceCounterMetrics {
42
42
  lastHrtime;
43
43
  lastCpus;
44
44
  lastCpusProcess;
45
+ lastAppCpuUsageNormalized;
46
+ lastHrtimeNormalized;
47
+ lastCpusProcessNormalized;
45
48
  totalExceptionCount = 0;
46
49
  /**
47
50
  * Creates performance counter instruments.
@@ -54,11 +57,15 @@ export class PerformanceCounterMetrics {
54
57
  this.lastCpusProcess = os.cpus();
55
58
  this.lastAppCpuUsage = process.cpuUsage();
56
59
  this.lastHrtime = process.hrtime();
60
+ this.lastCpusProcessNormalized = os.cpus();
61
+ this.lastAppCpuUsageNormalized = process.cpuUsage();
62
+ this.lastHrtimeNormalized = process.hrtime();
57
63
  this.lastRequestRate = {
58
64
  count: this.totalCount,
59
65
  time: +new Date(),
60
66
  executionInterval: this.intervalExecutionTime,
61
67
  };
68
+ this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };
62
69
  this.azureExporter = new AzureMonitorMetricExporter(this.internalConfig.azureMonitorExporterOptions);
63
70
  const metricReaderOptions = {
64
71
  exporter: this.azureExporter,
@@ -70,7 +77,6 @@ export class PerformanceCounterMetrics {
70
77
  };
71
78
  this.meterProvider = new MeterProvider(meterProviderConfig);
72
79
  this.meter = this.meterProvider.getMeter("AzureMonitorPerformanceCountersMeter");
73
- this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };
74
80
  // Create Instruments
75
81
  this.requestDurationHistogram = this.meter.createHistogram(PerformanceCounterMetricNames.REQUEST_DURATION, { valueType: ValueType.DOUBLE });
76
82
  this.requestRateGauge = this.meter.createObservableGauge(PerformanceCounterMetricNames.REQUEST_RATE, {
@@ -244,33 +250,31 @@ export class PerformanceCounterMetrics {
244
250
  const cpus = os.cpus();
245
251
  if (cpus &&
246
252
  cpus.length &&
247
- this.lastCpusProcess &&
248
- cpus.length === this.lastCpusProcess.length) {
253
+ this.lastCpusProcessNormalized &&
254
+ cpus.length === this.lastCpusProcessNormalized.length) {
249
255
  // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)
250
256
  let appCpuPercent = undefined;
251
257
  const appCpuUsage = process.cpuUsage();
252
258
  const hrtime = process.hrtime();
253
259
  const totalApp = appCpuUsage.user -
254
- this.lastAppCpuUsage.user +
255
- (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;
256
- if (typeof this.lastHrtime !== "undefined" && this.lastHrtime.length === 2) {
257
- const elapsedTime = (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds
260
+ this.lastAppCpuUsageNormalized.user +
261
+ (appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;
262
+ if (typeof this.lastHrtimeNormalized !== "undefined" &&
263
+ this.lastHrtimeNormalized.length === 2) {
264
+ const elapsedTime = (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +
265
+ (hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds
258
266
  appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);
259
267
  }
260
268
  // Set previous
261
- this.lastAppCpuUsage = appCpuUsage;
262
- this.lastHrtime = hrtime;
263
- const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);
264
- let value = 0;
265
- if (appCpuPercent !== undefined) {
266
- value = appCpuPercent;
267
- }
268
- else {
269
- value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
270
- }
269
+ this.lastAppCpuUsageNormalized = appCpuUsage;
270
+ this.lastHrtimeNormalized = hrtime;
271
+ const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);
272
+ const value = appCpuPercent !== undefined
273
+ ? appCpuPercent
274
+ : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
271
275
  observableResult.observe(value);
272
276
  }
273
- this.lastCpusProcess = cpus;
277
+ this.lastCpusProcessNormalized = cpus;
274
278
  }
275
279
  getProcessTime(observableResult) {
276
280
  // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary
@@ -296,13 +300,9 @@ export class PerformanceCounterMetrics {
296
300
  this.lastAppCpuUsage = appCpuUsage;
297
301
  this.lastHrtime = hrtime;
298
302
  const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);
299
- let value = 0;
300
- if (appCpuPercent !== undefined) {
301
- value = appCpuPercent;
302
- }
303
- else {
304
- value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
305
- }
303
+ const value = appCpuPercent !== undefined
304
+ ? appCpuPercent
305
+ : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
306
306
  observableResult.observe(value);
307
307
  }
308
308
  this.lastCpusProcess = cpus;
@@ -1 +1 @@
1
- {"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"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AC;QACvC,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG;YACvB,KAAK,EAAE,IAAI,CAAC,mBAAmB;YAC/B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;CAGF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport os from \"node:os\";\nimport type {\n Histogram,\n Meter,\n ObservableCallback,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport { SpanKind, ValueType } from \"@opentelemetry/api\";\nimport type { SdkLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type {\n MeterProviderOptions,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { MeterProvider, PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { PerformanceCounterMetricNames } from \"./types.js\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport type { AzureMonitorOpenTelemetryOptions } from \"../types.js\";\nimport { getLogData, isExceptionData } from \"./quickpulse/utils.js\";\nimport type { ExceptionData, TraceData } from \"./quickpulse/types.js\";\nimport { Logger } from \"../shared/logging/logger.js\";\nimport { readAvailableMemory } from \"./utils.js\";\nimport process from \"node:process\";\n\n/**\n * Azure Monitor PerformanceCounter Metrics\n */\nexport class PerformanceCounterMetrics {\n private internalConfig: AzureMonitorOpenTelemetryOptions;\n private collectionInterval = 60000; // 60 seconds\n private meterProvider: MeterProvider;\n private azureExporter: AzureMonitorMetricExporter;\n private meter: Meter;\n private requestDurationHistogram: Histogram;\n private requestRateGauge: ObservableGauge;\n private requestRateGaugeCallback: ObservableCallback;\n private memoryPrivateBytesGauge: ObservableGauge;\n private memoryPrivateBytesGaugeCallback: ObservableCallback;\n private memoryAvailableBytesGauge: ObservableGauge;\n private memoryAvailableBytesGaugeCallback: ObservableCallback;\n private processorTimeGauge: ObservableGauge;\n private processorTimeGaugeCallback: ObservableCallback;\n private processTimeNormalizedGauge: ObservableGauge;\n private processTimeNormalizedGaugeCallback: ObservableCallback;\n private processTimeGauge: ObservableGauge;\n private processTimeGaugeCallback: ObservableCallback;\n private exceptionCountGauge: ObservableGauge;\n private exceptionCountGaugeCallback: ObservableCallback;\n private lastExceptionRate: { count: number; time: number } = { count: 0, time: 0 };\n private totalCount: number = 0;\n private intervalExecutionTime = 0;\n private lastRequestRate: { count: number; time: number; executionInterval: number };\n private lastAppCpuUsage: { user: number; system: number };\n private lastHrtime: number[];\n private lastCpus: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private lastCpusProcess: {\n model: string;\n speed: number;\n times: { user: number; nice: number; sys: number; idle: number; irq: number };\n }[];\n private totalExceptionCount: number = 0;\n\n /**\n * Creates performance counter instruments.\n * @param options - Distro configuration.\n * @param config - Application Insights configuration.\n */\n constructor(config: AzureMonitorOpenTelemetryOptions, options?: { collectionInterval: number }) {\n this.internalConfig = config;\n this.lastCpus = os.cpus();\n this.lastCpusProcess = os.cpus();\n this.lastAppCpuUsage = process.cpuUsage();\n this.lastHrtime = process.hrtime();\n\n this.lastRequestRate = {\n count: this.totalCount,\n time: +new Date(),\n executionInterval: this.intervalExecutionTime,\n };\n\n this.azureExporter = new AzureMonitorMetricExporter(\n this.internalConfig.azureMonitorExporterOptions,\n );\n const metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.azureExporter,\n exportIntervalMillis: options?.collectionInterval || this.collectionInterval,\n };\n const meterProviderConfig: MeterProviderOptions = {\n readers: [new PeriodicExportingMetricReader(metricReaderOptions)],\n resource: this.internalConfig.resource,\n };\n this.meterProvider = new MeterProvider(meterProviderConfig);\n this.meter = this.meterProvider.getMeter(\"AzureMonitorPerformanceCountersMeter\");\n\n this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };\n\n // Create Instruments\n this.requestDurationHistogram = this.meter.createHistogram(\n PerformanceCounterMetricNames.REQUEST_DURATION,\n { valueType: ValueType.DOUBLE },\n );\n this.requestRateGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.REQUEST_RATE,\n {\n description: \"Incoming Requests Average Execution Time\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.memoryPrivateBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PRIVATE_BYTES,\n { description: \"Amount of memory process has used in bytes\", valueType: ValueType.INT },\n );\n this.memoryAvailableBytesGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.AVAILABLE_BYTES,\n { description: \"Amount of available memory in bytes\", valueType: ValueType.INT },\n );\n this.processorTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESSOR_TIME,\n {\n description: \"Processor time as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_STANDARD,\n {\n description: \"Process CPU usage as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.processTimeNormalizedGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.PROCESS_TIME_NORMALIZED,\n {\n description: \"Process CPU usage normalized as a percentage\",\n valueType: ValueType.DOUBLE,\n },\n );\n this.exceptionCountGauge = this.meter.createObservableGauge(\n PerformanceCounterMetricNames.EXCEPTION_RATE,\n {\n description: \"Exception Rate\",\n valueType: ValueType.DOUBLE,\n },\n );\n\n // Add callbacks\n this.requestRateGaugeCallback = this.getRequestRate.bind(this);\n this.memoryPrivateBytesGaugeCallback = this.getPrivateMemory.bind(this);\n this.memoryAvailableBytesGaugeCallback = this.getAvailableMemory.bind(this);\n this.processorTimeGaugeCallback = this.getProcessorTime.bind(this);\n this.processTimeGaugeCallback = this.getProcessTime.bind(this);\n this.processTimeNormalizedGaugeCallback = this.getNormalizedProcessTime.bind(this);\n this.exceptionCountGaugeCallback = this.getExceptionRate.bind(this);\n\n this.memoryPrivateBytesGauge.addCallback(this.memoryPrivateBytesGaugeCallback);\n this.memoryAvailableBytesGauge.addCallback(this.memoryAvailableBytesGaugeCallback);\n this.processTimeGauge.addCallback(this.processTimeGaugeCallback);\n this.processTimeNormalizedGauge.addCallback(this.processTimeNormalizedGaugeCallback);\n this.processorTimeGauge.addCallback(this.processorTimeGaugeCallback);\n this.requestRateGauge.addCallback(this.requestRateGaugeCallback);\n this.exceptionCountGauge.addCallback(this.exceptionCountGaugeCallback);\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public async shutdown(): Promise<void> {\n return this.meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n return this.meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this.meterProvider;\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n if (span.kind !== SpanKind.SERVER) {\n return;\n }\n this.totalCount++;\n const durationMs = hrTimeToMilliseconds(span.duration);\n this.intervalExecutionTime += durationMs;\n this.requestDurationHistogram.record(durationMs);\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n this.totalExceptionCount++;\n }\n });\n }\n }\n\n /**\n * Record Log metrics\n * @internal\n */\n public recordLog(logRecord: SdkLogRecord): void {\n const columns: TraceData | ExceptionData = getLogData(logRecord);\n if (isExceptionData(columns)) {\n this.totalExceptionCount++;\n }\n }\n\n private getRequestRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalRequests = this.totalCount - this.lastRequestRate.count || 0;\n const elapsedMs = currentTime - this.lastRequestRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const requestsPerSec = intervalRequests / elapsedSeconds;\n observableResult.observe(requestsPerSec);\n }\n this.lastRequestRate = {\n count: this.totalCount,\n time: currentTime,\n executionInterval: this.lastRequestRate.executionInterval,\n };\n }\n\n private getPrivateMemory(observableResult: ObservableResult): void {\n if (process?.memoryUsage) {\n observableResult.observe(process.memoryUsage().rss);\n } else {\n Logger.getInstance().debug(\"Couldn't report Private Memory. Process is not defined.\");\n }\n }\n\n private getAvailableMemory(observableResult: ObservableResult): void {\n observableResult.observe(readAvailableMemory());\n }\n\n private getTotalCombinedCpu(cpus: os.CpuInfo[], lastCpus: os.CpuInfo[]) {\n let totalUser = 0;\n let totalSys = 0;\n let totalNice = 0;\n let totalIdle = 0;\n let totalIrq = 0;\n for (let i = 0; !!cpus && i < cpus.length; i++) {\n const cpu = cpus[i];\n const lastCpu = lastCpus[i];\n const times = cpu.times;\n const lastTimes = lastCpu.times;\n // user cpu time (or) % CPU time spent in user space\n let user = times.user - lastTimes.user;\n user = user > 0 ? user : 0; // Avoid negative values\n totalUser += user;\n // system cpu time (or) % CPU time spent in kernel space\n let sys = times.sys - lastTimes.sys;\n sys = sys > 0 ? sys : 0; // Avoid negative values\n totalSys += sys;\n // user nice cpu time (or) % CPU time spent on low priority processes\n let nice = times.nice - lastTimes.nice;\n nice = nice > 0 ? nice : 0; // Avoid negative values\n totalNice += nice;\n // idle cpu time (or) % CPU time spent idle\n let idle = times.idle - lastTimes.idle;\n idle = idle > 0 ? idle : 0; // Avoid negative values\n totalIdle += idle;\n // irq (or) % CPU time spent servicing/handling hardware interrupts\n let irq = times.irq - lastTimes.irq;\n irq = irq > 0 ? irq : 0; // Avoid negative values\n totalIrq += irq;\n }\n const combinedTotal = totalUser + totalSys + totalNice + totalIdle + totalIrq;\n return {\n combinedTotal: combinedTotal,\n totalUser: totalUser,\n totalIdle: totalIdle,\n };\n }\n\n private getProcessorTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (cpus && cpus.length && this.lastCpus && cpus.length === this.lastCpus.length) {\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpus);\n\n const value =\n cpuTotals.combinedTotal > 0\n ? ((cpuTotals.combinedTotal - cpuTotals.totalIdle) / cpuTotals.combinedTotal) * 100\n : 0;\n observableResult.observe(value);\n }\n this.lastCpus = cpus;\n }\n\n private getNormalizedProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n\n appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n }\n\n private getProcessTime(observableResult: ObservableResult): void {\n // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary\n // to find the delta since the last measurement\n if (process) {\n const cpus = os.cpus();\n if (\n cpus &&\n cpus.length &&\n this.lastCpusProcess &&\n cpus.length === this.lastCpusProcess.length\n ) {\n // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)\n let appCpuPercent: number | undefined = undefined;\n const appCpuUsage = process.cpuUsage();\n const hrtime = process.hrtime();\n const totalApp =\n appCpuUsage.user -\n this.lastAppCpuUsage.user +\n (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;\n\n if (typeof this.lastHrtime !== \"undefined\" && this.lastHrtime.length === 2) {\n const elapsedTime =\n (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds\n appCpuPercent = (100 * totalApp) / elapsedTime;\n }\n // Set previous\n this.lastAppCpuUsage = appCpuUsage;\n this.lastHrtime = hrtime;\n const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);\n let value = 0;\n if (appCpuPercent !== undefined) {\n value = appCpuPercent;\n } else {\n value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;\n }\n observableResult.observe(value);\n }\n this.lastCpusProcess = cpus;\n } else {\n Logger.getInstance().debug(\"Couldn't report process time. Process is not defined.\");\n }\n }\n\n private getExceptionRate(observableResult: ObservableResult): void {\n const currentTime = +new Date();\n const intervalData = this.totalExceptionCount - this.lastExceptionRate.count || 0;\n const elapsedMs = currentTime - this.lastExceptionRate.time;\n if (elapsedMs > 0) {\n const elapsedSeconds = elapsedMs / 1000;\n const dataPerSec = intervalData / elapsedSeconds;\n observableResult.observe(dataPerSec);\n }\n this.lastExceptionRate = {\n count: this.totalExceptionCount,\n time: currentTime,\n };\n }\n\n // TODO: Add Process I/O Rate\n}\n"]}
1
+ {"version":3,"file":"performanceCounters.js","sourceRoot":"","sources":["../../../src/metrics/performanceCounters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AAQzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAKnF,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE1F,OAAO,EAA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import 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;AAMrC;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,2BAA2B;IACrE,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B;IAC1B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,6CAA6C;IAC7C,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAC1C,yCAAyC;IACzC,+BAA+B,CAAC,EAAE,MAAM,CAAC;CAC1C;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,gBAAgB,CAAW;gBAEvB,OAAO,EAAE;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE,eAAe,CAAC;QAC7B,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACtC;IAyBD,OAAO,CAAC,sBAAsB;IAO9B;;;OAGG;IACG,YAAY,CAChB,cAAc,EAAE,0BAA0B,GACzC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAuB1C;;;OAGG;IACG,OAAO,CAAC,cAAc,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAqB7F;;;;;;;;;OASG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAkC5D"}
1
+ {"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../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PolicyName } from "@azure/core-rest-pipeline";
5
5
  import { diag } from "@opentelemetry/api";
6
- import { QuickpulseClient } from "../../../generated/index.js";
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 client = new QuickpulseClient(this.credential, clientOptions);
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
- let responseHeaders = {};
54
- const body = await this.quickpulseClient.isSubscribed(this.instrumentationKey, {
55
- ...optionalParams,
56
- onResponse: (rawResponse) => {
57
- responseHeaders = rawResponse.headers.toJSON();
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
- let responseHeaders = {};
81
- const body = await this.quickpulseClient.publish(this.instrumentationKey, {
82
- ...optionalParams,
83
- onResponse: (rawResponse) => {
84
- responseHeaders = rawResponse.headers.toJSON();
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"],
@@ -118,13 +123,14 @@ export class QuickpulseSender {
118
123
  if (!locUrl.host) {
119
124
  return;
120
125
  }
121
- let currentHost = "";
122
- try {
123
- currentHost = new url.URL(this.endpointUrl).host;
124
- }
125
- catch {
126
- currentHost = "";
127
- }
126
+ const currentHost = (() => {
127
+ try {
128
+ return new url.URL(this.endpointUrl).host;
129
+ }
130
+ catch {
131
+ return "";
132
+ }
133
+ })();
128
134
  if (!isSameRegisteredDomain(currentHost, locUrl.host)) {
129
135
  diag.error(`Refusing cross-origin Live Metrics redirect to https://${locUrl.host}: target is neither the configured endpoint host nor under a known Azure Monitor ingestion domain.`);
130
136
  return;
@@ -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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ACpB,MAAM,SAAS,GAAG,KAAkB,CAAC;YACrC,IAAI,CAAC,IAAI,CAAC,mCAAmC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QACpE,CAAC;QACD,OAAO;IACT,CAAC;IAED;;;;;;;;;OASG;IACH,uBAAuB,CAAC,QAA4B;QAClD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,MAAe,CAAC;YACpB,IAAI,CAAC;gBACH,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,IAAI,WAAW,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;YACnD,CAAC;YAAC,MAAM,CAAC;gBACP,WAAW,GAAG,EAAE,CAAC;YACnB,CAAC;YAED,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 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,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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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,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