@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
package/README.md CHANGED
@@ -40,6 +40,7 @@ useAzureMonitor(options);
40
40
  ```
41
41
 
42
42
  - Connection String can be set via `APPLICATIONINSIGHTS_CONNECTION_STRING`.
43
+ - Batch span processing can be configured with the standard OpenTelemetry environment variables `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`, `OTEL_BSP_SCHEDULE_DELAY`, and `OTEL_BSP_EXPORT_TIMEOUT`.
43
44
  - Sampler can be set via the OpenTelemetry env vars `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG` (takes precedence over the `samplingRatio` option). Supported sampler values: `microsoft.rate_limited`, `microsoft.fixed_percentage`, `always_on`, `always_off`, `trace_id_ratio`, `parentbased_always_on`, `parentbased_always_off`, `parentbased_trace_id_ratio`. For `microsoft.rate_limited`, the arg is spans per second; for `trace_id_ratio`/parentbased, the arg is a probability in [0,1]. When the arg is omitted, defaults apply (rate limit disabled; probability defaults to 1). See the upstream OpenTelemetry environment variable spec for full context: https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/.
44
45
  - To use the **fixed percentage sampler** (instead of the default rate-limited sampler), you can either:
45
46
  - Set the environment variable `OTEL_TRACES_SAMPLER=microsoft.fixed_percentage` with an optional `OTEL_TRACES_SAMPLER_ARG` for the sampling probability (e.g., `0.5` for 50%).
@@ -86,6 +87,7 @@ For CommonJS applications, no additional flags are needed - the loader is automa
86
87
  ```ts snippet:ReadmeSampleConfiguration
87
88
  import { resourceFromAttributes } from "@opentelemetry/resources";
88
89
  import { AzureMonitorOpenTelemetryOptions, useAzureMonitor } from "@azure/monitor-opentelemetry";
90
+ import { SeverityNumber } from "@opentelemetry/api-logs";
89
91
 
90
92
  const resource = resourceFromAttributes({ testAttribute: "testValue" });
91
93
  const options: AzureMonitorOpenTelemetryOptions = {
@@ -111,8 +113,10 @@ const options: AzureMonitorOpenTelemetryOptions = {
111
113
  // Instrumentations generating logs
112
114
  bunyan: { enabled: true },
113
115
  winston: { enabled: true },
114
- // Console log collection is opt-in (disabled by default)
115
- console: { enabled: false },
116
+ // Console log collection is opt-in (disabled by default).
117
+ // `logSeverity` takes precedence over the
118
+ // APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL environment variable.
119
+ console: { enabled: false, logSeverity: SeverityNumber.WARN },
116
120
  },
117
121
  enableLiveMetrics: true,
118
122
  enableStandardMetrics: true,
@@ -278,7 +282,7 @@ The following OpenTelemetry Instrumentation libraries are included as part of Az
278
282
 
279
283
  - [Console](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-console) (disabled by default; enable with `instrumentationOptions: { console: { enabled: true } }`)
280
284
 
281
- Once enabled, the set of `console` methods collected is filtered by the `APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL` environment variable (`NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `VERBOSE`, `ALL`; see [Self-diagnostics](#self-diagnostics)). For example, `WARN` collects only `console.warn` and `console.error`, while `NONE` disables collection of `console` (and all other) logs entirely.
285
+ Once enabled, the set of `console` methods collected is filtered by the `logSeverity` value on the `console` instrumentation options, falling back to the `APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL` environment variable (`NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `VERBOSE`, `ALL`; see [Self-diagnostics](#self-diagnostics)) when `logSeverity` is not set. For example, `WARN` collects only `console.warn` and `console.error`, while `NONE` disables collection of `console` (and all other) logs entirely.
282
286
 
283
287
  Other OpenTelemetry Instrumentations are available [here](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages) and could be added using TracerProvider in AzureMonitorOpenTelemetryClient.
284
288
 
@@ -1 +1 @@
1
- {"version":3,"file":"browserSdkLoaderHelper.d.ts","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoaderHelper.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,oBAAY,qBAAqB;IAC/B,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,EAAE,OAAO;CACV;AAGD,eAAO,MAAM,mBAAmB,UAS/B,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAO,OAGpC,CAAC;AAEF,eAAO,MAAM,SAAS,gCAAuB,CAAC;AAC9C,eAAO,MAAM,WAAW,kCAAyB,CAAC;AAClD,eAAO,MAAM,YAAY,mCAA0B,CAAC;AACpD,eAAO,MAAM,YAAY,mCAA0B,CAAC;AAGpD,eAAO,MAAM,sBAAsB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAMnE,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAOlE,C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AAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAMnE,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAOlE,CAAC;AAGF,eAAO,MAAM,wBAAwB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAMrE,CAAC;AAGF,eAAO,MAAM,uBAAuB,GAAI,YAAY,GAAG,KAAG,QAAQ,GAAG,IAOpE,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,GAAG,IAStE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,IAShE,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,gBAAgB,MAAM,KACrB,qBAAqB,GAAG,IAe1B,CAAC;AAIF,eAAO,MAAM,6BAA6B,GACxC,UAAU,IAAI,CAAC,cAAc,KAC5B,qBAAqB,EAAE,GAAG,IAW5B,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,OAAO,MAAM,EACb,MAAM,MAAM,EACZ,SAAS,MAAM,KACd,MAAM,GAAG,IAMX,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,UAAU,IAAI,CAAC,cAAc,KAAG,OAWvE,CAAC"}
@@ -130,10 +130,9 @@ exports.getContentEncodingFromHeaders = getContentEncodingFromHeaders;
130
130
  const insertBrowserSdkLoaderByIndex = (index, html, snippet) => {
131
131
  if (index < 0)
132
132
  return null;
133
- let newHtml = null;
134
133
  const subStart = html.substring(0, index);
135
134
  const subEnd = html.substring(index);
136
- newHtml = subStart + '<script type="text/javascript">' + snippet + "</script>" + subEnd;
135
+ const newHtml = subStart + '<script type="text/javascript">' + snippet + "</script>" + subEnd;
137
136
  return newHtml;
138
137
  };
139
138
  exports.insertBrowserSdkLoaderByIndex = insertBrowserSdkLoaderByIndex;
@@ -1 +1 @@
1
- {"version":3,"file":"browserSdkLoaderHelper.js","sourceR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AAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\nimport * as zlib from \"zlib\";\nimport { promisify } from \"node:util\";\nimport type http from \"node:http\";\n\n// currently support the following encoding types\nexport enum contentEncodingMethod {\n GZIP = \"gzip\",\n DEFLATE = \"deflate\",\n BR = \"br\",\n}\n\n// current supported encoding types\nexport const bufferEncodingTypes = [\n \"utf8\",\n \"utf16le\",\n \"latin1\",\n \"base64\",\n \"hex\",\n \"ascii\",\n \"binary\",\n \"ucs2\",\n];\n\n// for node version under 10, Brotli compression is not supported.\nexport const isBrotliSupported = (): boolean => {\n const majVer = process.versions.node.split(\".\")[0];\n return parseInt(majVer) >= 10;\n};\n\nexport const gzipAsync = promisify(zlib.gzip);\nexport const gunzipAsync = promisify(zlib.gunzip);\nexport const deflateAsync = promisify(zlib.deflate);\nexport const inflateAsync = promisify(zlib.inflate);\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompress === \"function\") {\n return promisify(zlibObject.brotliCompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliCompressSync;\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompress === \"function\") {\n return promisify(zlibObject.brotliDecompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliDecompressSync;\n }\n return null;\n};\n\nexport const isBufferType = (buffer: Buffer, type?: string): boolean | null => {\n const encodingType = type ? type : \"utf8\";\n let result = false;\n if (Buffer.isEncoding(encodingType)) {\n const newBuffer = Buffer.from(buffer.toString(encodingType), encodingType);\n result = newBuffer.toJSON().data.toString() === buffer.toJSON().data.toString();\n }\n\n return result;\n};\n\nexport const findBufferEncodingType = (buffer: Buffer): string | null => {\n let bufferType = null;\n for (const type of bufferEncodingTypes) {\n if (Buffer.isEncoding(type) && isBufferType(buffer, type)) {\n bufferType = type;\n break;\n }\n }\n return bufferType;\n};\n\nexport const isSupportedContentEncoding = (\n encodingMethod: string,\n): contentEncodingMethod | null => {\n let encodingType = null;\n switch (encodingMethod) {\n case \"gzip\":\n encodingType = contentEncodingMethod.GZIP;\n break;\n case \"br\":\n encodingType = contentEncodingMethod.BR;\n break;\n case \"deflate\":\n encodingType = contentEncodingMethod.DEFLATE;\n break;\n default:\n }\n return encodingType;\n};\n\n// mutiple content-encoding is not supported\n// for mutiple content-encoding, this method will return any empty array\nexport const getContentEncodingFromHeaders = (\n response: http.ServerResponse,\n): contentEncodingMethod[] | null => {\n const headers: contentEncodingMethod[] = [];\n const contentEncodingHeaders = response.getHeader(\"Content-Encoding\");\n if (!contentEncodingHeaders) return null;\n if (typeof contentEncodingHeaders === \"string\") {\n const supportedContentEncoding = isSupportedContentEncoding(contentEncodingHeaders);\n if (supportedContentEncoding) {\n headers.push(supportedContentEncoding);\n }\n }\n return headers;\n};\n\nexport const insertBrowserSdkLoaderByIndex = (\n index: number,\n html: string,\n snippet: string,\n): string | null => {\n if (index < 0) return null;\n let newHtml = null;\n const subStart = html.substring(0, index);\n const subEnd = html.substring(index);\n newHtml = subStart + '<script type=\"text/javascript\">' + snippet + \"</script>\" + subEnd;\n return newHtml;\n};\n\nexport const isContentTypeHeaderHtml = (response: http.ServerResponse): boolean => {\n let isHtml = false;\n const contentType = response.getHeader(\"Content-Type\");\n if (contentType) {\n if (typeof contentType === \"string\") {\n isHtml = contentType.indexOf(\"html\") >= 0;\n } else {\n isHtml = contentType.toString().indexOf(\"html\") >= 0;\n }\n }\n return isHtml;\n};\n"]}
1
+ {"version":3,"file":"browserSdkLoaderHelper.js","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoaderHelper.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,sEAAsE;AAEtE,mDAA6B;AAC7B,yCAAsC;AAGtC,iDAAiD;AACjD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,4CAAmB,CAAA;IACnB,kCAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AAED,mCAAmC;AACtB,QAAA,mBAAmB,GAAG;IACjC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;CACP,CAAC;AAEF,kEAAkE;AAC3D,MAAM,iBAAiB,GAAG,GAAY,EAAE;IAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,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K,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,QAAQ,GAAG,iCAAiC,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,CAAC;IAC9F,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,6BAA6B,iCAUxC;AAEK,MAAM,uBAAuB,GAAG,CAAC,QAA6B,EAAW,EAAE;IAChF,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACvD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\nimport * as zlib from \"zlib\";\nimport { promisify } from \"node:util\";\nimport type http from \"node:http\";\n\n// currently support the following encoding types\nexport enum contentEncodingMethod {\n GZIP = \"gzip\",\n DEFLATE = \"deflate\",\n BR = \"br\",\n}\n\n// current supported encoding types\nexport const bufferEncodingTypes = [\n \"utf8\",\n \"utf16le\",\n \"latin1\",\n \"base64\",\n \"hex\",\n \"ascii\",\n \"binary\",\n \"ucs2\",\n];\n\n// for node version under 10, Brotli compression is not supported.\nexport const isBrotliSupported = (): boolean => {\n const majVer = process.versions.node.split(\".\")[0];\n return parseInt(majVer) >= 10;\n};\n\nexport const gzipAsync = promisify(zlib.gzip);\nexport const gunzipAsync = promisify(zlib.gunzip);\nexport const deflateAsync = promisify(zlib.deflate);\nexport const inflateAsync = promisify(zlib.inflate);\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompress === \"function\") {\n return promisify(zlibObject.brotliCompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliCompressSync;\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompress === \"function\") {\n return promisify(zlibObject.brotliDecompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliDecompressSync;\n }\n return null;\n};\n\nexport const isBufferType = (buffer: Buffer, type?: string): boolean | null => {\n const encodingType = type ? type : \"utf8\";\n let result = false;\n if (Buffer.isEncoding(encodingType)) {\n const newBuffer = Buffer.from(buffer.toString(encodingType), encodingType);\n result = newBuffer.toJSON().data.toString() === buffer.toJSON().data.toString();\n }\n\n return result;\n};\n\nexport const findBufferEncodingType = (buffer: Buffer): string | null => {\n let bufferType = null;\n for (const type of bufferEncodingTypes) {\n if (Buffer.isEncoding(type) && isBufferType(buffer, type)) {\n bufferType = type;\n break;\n }\n }\n return bufferType;\n};\n\nexport const isSupportedContentEncoding = (\n encodingMethod: string,\n): contentEncodingMethod | null => {\n let encodingType = null;\n switch (encodingMethod) {\n case \"gzip\":\n encodingType = contentEncodingMethod.GZIP;\n break;\n case \"br\":\n encodingType = contentEncodingMethod.BR;\n break;\n case \"deflate\":\n encodingType = contentEncodingMethod.DEFLATE;\n break;\n default:\n }\n return encodingType;\n};\n\n// mutiple content-encoding is not supported\n// for mutiple content-encoding, this method will return any empty array\nexport const getContentEncodingFromHeaders = (\n response: http.ServerResponse,\n): contentEncodingMethod[] | null => {\n const headers: contentEncodingMethod[] = [];\n const contentEncodingHeaders = response.getHeader(\"Content-Encoding\");\n if (!contentEncodingHeaders) return null;\n if (typeof contentEncodingHeaders === \"string\") {\n const supportedContentEncoding = isSupportedContentEncoding(contentEncodingHeaders);\n if (supportedContentEncoding) {\n headers.push(supportedContentEncoding);\n }\n }\n return headers;\n};\n\nexport const insertBrowserSdkLoaderByIndex = (\n index: number,\n html: string,\n snippet: string,\n): string | null => {\n if (index < 0) return null;\n const subStart = html.substring(0, index);\n const subEnd = html.substring(index);\n const newHtml = subStart + '<script type=\"text/javascript\">' + snippet + \"</script>\" + subEnd;\n return newHtml;\n};\n\nexport const isContentTypeHeaderHtml = (response: http.ServerResponse): boolean => {\n let isHtml = false;\n const contentType = response.getHeader(\"Content-Type\");\n if (contentType) {\n if (typeof contentType === \"string\") {\n isHtml = contentType.indexOf(\"html\") >= 0;\n } else {\n isHtml = contentType.toString().indexOf(\"html\") >= 0;\n }\n }\n return isHtml;\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  import { NodeSDK } from "@opentelemetry/sdk-node";
2
- import type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, BrowserSdkLoaderOptions } from "./types.js";
3
- export type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, BrowserSdkLoaderOptions };
2
+ import type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, ConsoleInstrumentationOptions, BrowserSdkLoaderOptions } from "./types.js";
3
+ export type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, ConsoleInstrumentationOptions, BrowserSdkLoaderOptions, };
4
4
  /**
5
5
  * Initialize Azure Monitor Distro
6
6
  * @param options - Azure Monitor OpenTelemetry Options
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMlD,OAAO,KAAK,EAGV,gCAAgC,EAChC,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAwBpB,YAAY,EAAE,gCAAgC,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,CAAC;AA4BlG;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gCAAgC,GAAG,IAAI,CA0GhF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAMpD;AAED;;;GAGG;AAEH,wBAAgB,eAAe,IAAI,OAAO,GAAG,SAAS,CAErD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMlD,OAAO,KAAK,EAGV,gCAAgC,EAChC,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAgBpB,YAAY,EACV,gCAAgC,EAChC,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,GACxB,CAAC;AAoCF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gCAAgC,GAAG,IAAI,CA6FhF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED;;;GAGG;AAEH,wBAAgB,eAAe,IAAI,OAAO,GAAG,SAAS,CAErD"}
@@ -17,22 +17,22 @@ const browserSdkLoader_js_1 = require("./browserSdkLoader/browserSdkLoader.js");
17
17
  const utils_js_1 = require("./metrics/quickpulse/utils.js");
18
18
  const statsbeat_js_1 = require("./utils/statsbeat.js");
19
19
  const opentelemetryInstrumentationPatcher_js_1 = require("./utils/opentelemetryInstrumentationPatcher.js");
20
- const azureSdkTracingBridge_js_1 = require("./utils/azureSdkTracingBridge.js");
21
20
  const common_js_1 = require("./utils/common.js");
22
21
  const logUtils_js_1 = require("./utils/logUtils.js");
23
22
  const index_js_3 = require("./shared/logging/index.js");
24
23
  const types_js_2 = require("./types.js");
25
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
26
- /**
27
- * Semantic attribute for cloud resource ID, defined by \@opentelemetry/resource-detector-azure
28
- * @internal
29
- */
30
- const CLOUD_RESOURCE_ID_ATTRIBUTE = "cloud.resource_id";
31
24
  process.env["AZURE_MONITOR_DISTRO_VERSION"] = types_js_1.AZURE_MONITOR_OPENTELEMETRY_VERSION;
32
25
  let sdk;
33
26
  let browserSdkLoader;
34
- // Track the global console patch because NodeSDK does not disable instrumentations.
35
- let consoleInstrumentation;
27
+ // NodeSDK shuts down providers, but leaves instrumentation hooks enabled.
28
+ let instrumentations = [];
29
+ const instrumentationCache = new Map();
30
+ function disableInstrumentations() {
31
+ for (const instrumentation of instrumentations) {
32
+ instrumentation.disable();
33
+ }
34
+ instrumentations = [];
35
+ }
36
36
  /**
37
37
  * Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.
38
38
  */
@@ -56,6 +56,7 @@ function sendAttachWarning() {
56
56
  */
57
57
  function useAzureMonitor(options) {
58
58
  const config = new config_js_1.InternalConfig(options);
59
+ disableInstrumentations();
59
60
  (0, opentelemetryInstrumentationPatcher_js_1.patchOpenTelemetryInstrumentationEnable)();
60
61
  // Omit disabled log instrumentations from Statsbeat.
61
62
  const logInstrumentationsEnabled = !(0, logUtils_js_1.isLogCollectionDisabled)();
@@ -70,18 +71,15 @@ function useAzureMonitor(options) {
70
71
  winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,
71
72
  console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,
72
73
  };
73
- // Check if the AKS resource detector successfully populated specific resource attributes
74
- // (k8s.cluster.name or cloud.resource_id) beyond the basic cloud.platform/cloud.provider
75
- // Derive from config.resource.attributes which already includes the AKS detector results
76
- const resourceAttributes = config.resource.attributes;
77
- const aksResourceDetected = semantic_conventions_1.SEMRESATTRS_K8S_CLUSTER_NAME in resourceAttributes ||
78
- CLOUD_RESOURCE_ID_ATTRIBUTE in resourceAttributes;
74
+ // Only report this feature when the AKS resource detector itself was able to populate the AKS
75
+ // cluster attributes, which requires the customer to have configured access to the
76
+ // aks-cluster-metadata ConfigMap (RBAC + env var or mounted file).
79
77
  const statsbeatFeatures = {
80
78
  browserSdkLoader: config.browserSdkLoaderOptions.enabled,
81
79
  aadHandling: !!config.azureMonitorExporterOptions?.credential,
82
80
  diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,
83
81
  customerSdkStats: process.env[types_js_1.APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === "true",
84
- aksResourceDetectorPopulation: aksResourceDetected,
82
+ aksResourceDetectorPopulation: config.aksResourceDetectorPopulated,
85
83
  };
86
84
  (0, statsbeat_js_1.getInstance)().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);
87
85
  if (config.browserSdkLoaderOptions.enabled) {
@@ -91,9 +89,6 @@ function useAzureMonitor(options) {
91
89
  api_1.metrics.disable();
92
90
  api_1.trace.disable();
93
91
  api_logs_1.logs.disable();
94
- // Restore any console patch from the previous initialization.
95
- consoleInstrumentation?.disable();
96
- consoleInstrumentation = undefined;
97
92
  // Clear the entire OpenTelemetry API global state to avoid version conflicts.
98
93
  // The disable() calls above remove individual providers but leave the `version` field
99
94
  // on the global object intact. If a different version of @opentelemetry/api was loaded
@@ -105,12 +100,9 @@ function useAzureMonitor(options) {
105
100
  Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);
106
101
  // Create internal handlers
107
102
  const metricHandler = new index_js_1.MetricHandler(config);
108
- const traceHandler = new handler_js_1.TraceHandler(config, metricHandler);
109
- const logHandler = new index_js_2.LogHandler(config, metricHandler);
110
- const instrumentations = traceHandler
111
- .getInstrumentations()
112
- .concat(logHandler.getInstrumentations());
113
- consoleInstrumentation = logHandler.getConsoleInstrumentation();
103
+ const traceHandler = new handler_js_1.TraceHandler(config, metricHandler, instrumentationCache);
104
+ const logHandler = new index_js_2.LogHandler(config, metricHandler, instrumentationCache);
105
+ instrumentations = traceHandler.getInstrumentations().concat(logHandler.getInstrumentations());
114
106
  const resourceDetectorsList = (0, common_js_1.parseResourceDetectorsFromEnvVar)();
115
107
  // Add extra SpanProcessors, and logRecordProcessors from user configuration
116
108
  const spanProcessors = options?.spanProcessors || [];
@@ -146,9 +138,6 @@ function useAzureMonitor(options) {
146
138
  (0, utils_js_1.setSdkPrefix)();
147
139
  sendAttachWarning();
148
140
  sdk.start();
149
- // Eagerly install the Azure SDK tracing bridge in case @azure/core-tracing
150
- // was loaded before useAzureMonitor() (the RITM hook misses it otherwise).
151
- (0, azureSdkTracingBridge_js_1.ensureAzureSdkTracingBridge)();
152
141
  }
153
142
  /**
154
143
  * Shutdown Azure Monitor Open Telemetry Distro
@@ -156,9 +145,7 @@ function useAzureMonitor(options) {
156
145
  */
157
146
  function shutdownAzureMonitor() {
158
147
  browserSdkLoader?.dispose();
159
- // NodeSDK.shutdown() does not restore the global console.
160
- consoleInstrumentation?.disable();
161
- consoleInstrumentation = undefined;
148
+ disableInstrumentations();
162
149
  return sdk?.shutdown();
163
150
  }
164
151
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,k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AAO,EAAE,aAAa,IAAI,EAAE,CAAC;KAClC,CAAC;IAEF,MAAM,KAAK,GAAkB,aAAa,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAE1E,+BAA+B;IAC/B,MAAM,SAAS,GAAkC;QAC/C,mBAAmB,EAAE,IAAI;QACzB,aAAa,EAAE,aAAa;QAC5B,KAAK;QACL,gBAAgB,EAAE,gBAAgB;QAClC,mBAAmB,EAAE;YACnB,UAAU,CAAC,0BAA0B,EAAE;YACvC,GAAG,mBAAmB;YACtB,UAAU,CAAC,0BAA0B,EAAE;SACxC;QACD,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,YAAY,CAAC,UAAU,EAAE;QAClC,cAAc,EAAE;YACd,YAAY,CAAC,4BAA4B,EAAE;YAC3C,GAAG,cAAc;YACjB,YAAY,CAAC,qBAAqB,EAAE;SACrC;QACD,iBAAiB,EAAE,qBAAqB;KACzC,CAAC;IACF,GAAG,GAAG,IAAI,kBAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,IAAA,uBAAY,GAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;IACpB,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,2EAA2E;IAC3E,2EAA2E;IAC3E,IAAA,sDAA2B,GAAE,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB;IAClC,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,sBAAsB,EAAE,OAAO,EAAE,CAAC;IAClC,sBAAsB,GAAG,SAAS,CAAC;IACnC,OAAO,GAAG,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,gDAAgD;AAChD,SAAgB,eAAe;IAC7B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport type { NodeSDKConfiguration } from \"@opentelemetry/sdk-node\";\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\nimport type { MetricReader, ViewOptions } from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"./shared/config.js\";\nimport { MetricHandler } from \"./metrics/index.js\";\nimport { TraceHandler } from \"./traces/handler.js\";\nimport { LogHandler } from \"./logs/index.js\";\nimport type {\n StatsbeatFeatures,\n StatsbeatInstrumentations,\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n BrowserSdkLoaderOptions,\n} from \"./types.js\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n APPLICATIONINSIGHTS_SDKSTATS_DISABLED,\n} from \"./types.js\";\nimport { BrowserSdkLoader } from \"./browserSdkLoader/browserSdkLoader.js\";\nimport { setSdkPrefix } from \"./metrics/quickpulse/utils.js\";\nimport type { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport type { LogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport { getInstance } from \"./utils/statsbeat.js\";\nimport { patchOpenTelemetryInstrumentationEnable } from \"./utils/opentelemetryInstrumentationPatcher.js\";\nimport { ensureAzureSdkTracingBridge } from \"./utils/azureSdkTracingBridge.js\";\nimport { isFunctionApp, parseResourceDetectorsFromEnvVar } from \"./utils/common.js\";\nimport { isLogCollectionDisabled } from \"./utils/logUtils.js\";\nimport { Logger } from \"./shared/logging/index.js\";\nimport { AZURE_MONITOR_AUTO_ATTACH } from \"./types.js\";\nimport { SEMRESATTRS_K8S_CLUSTER_NAME } from \"@opentelemetry/semantic-conventions\";\n\n/**\n * Semantic attribute for cloud resource ID, defined by \\@opentelemetry/resource-detector-azure\n * @internal\n */\nconst CLOUD_RESOURCE_ID_ATTRIBUTE = \"cloud.resource_id\";\n\nexport type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, BrowserSdkLoaderOptions };\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet sdk: NodeSDK;\nlet browserSdkLoader: BrowserSdkLoader | undefined;\n// Track the global console patch because NodeSDK does not disable instrumentations.\nlet consoleInstrumentation: Instrumentation | undefined;\n\n/**\n * Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.\n */\nfunction sendAttachWarning(): void {\n if (process.env[AZURE_MONITOR_AUTO_ATTACH] === \"true\" && !isFunctionApp()) {\n // TODO: When AKS attach is public, update this message with disablement instructions for AKS\n const message =\n \"Distro detected that automatic instrumentation may have occurred. Only use autoinstrumentation if you \" +\n \"are not using manual instrumentation of OpenTelemetry in your code, such as with \" +\n \"@azure/monitor-opentelemetry or @azure/monitor-opentelemetry-exporter. For App Service resources, disable \" +\n \"autoinstrumentation in the Application Insights experience on your App Service resource or by setting \" +\n \"the ApplicationInsightsAgent_EXTENSION_VERSION app setting to 'disabled'.\";\n // Surface in the log stream\n console.warn(message);\n // Also log via diagnostic logging\n Logger.getInstance().warn(message);\n }\n}\n\n/**\n * Initialize Azure Monitor Distro\n * @param options - Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions): void {\n const config = new InternalConfig(options);\n patchOpenTelemetryInstrumentationEnable();\n // Omit disabled log instrumentations from Statsbeat.\n const logInstrumentationsEnabled = !isLogCollectionDisabled();\n const statsbeatInstrumentations: StatsbeatInstrumentations = {\n // Instrumentations\n azureSdk: config.instrumentationOptions?.azureSdk?.enabled,\n mongoDb: config.instrumentationOptions?.mongoDb?.enabled,\n mySql: config.instrumentationOptions?.mySql?.enabled,\n postgreSql: config.instrumentationOptions?.postgreSql?.enabled,\n redis: config.instrumentationOptions?.redis?.enabled,\n bunyan: logInstrumentationsEnabled && config.instrumentationOptions?.bunyan?.enabled,\n winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,\n console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,\n };\n // Check if the AKS resource detector successfully populated specific resource attributes\n // (k8s.cluster.name or cloud.resource_id) beyond the basic cloud.platform/cloud.provider\n // Derive from config.resource.attributes which already includes the AKS detector results\n const resourceAttributes = config.resource.attributes;\n const aksResourceDetected =\n SEMRESATTRS_K8S_CLUSTER_NAME in resourceAttributes ||\n CLOUD_RESOURCE_ID_ATTRIBUTE in resourceAttributes;\n const statsbeatFeatures: StatsbeatFeatures = {\n browserSdkLoader: config.browserSdkLoaderOptions.enabled,\n aadHandling: !!config.azureMonitorExporterOptions?.credential,\n diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,\n customerSdkStats: process.env[APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === \"true\",\n aksResourceDetectorPopulation: aksResourceDetected,\n };\n getInstance().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);\n\n if (config.browserSdkLoaderOptions.enabled) {\n browserSdkLoader = new BrowserSdkLoader(config);\n }\n // Remove global providers in OpenTelemetry, these would be overridden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n // Restore any console patch from the previous initialization.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n\n // Clear the entire OpenTelemetry API global state to avoid version conflicts.\n // The disable() calls above remove individual providers but leave the `version` field\n // on the global object intact. If a different version of @opentelemetry/api was loaded\n // first (e.g. by a VS Code extension host or another extension), the stale version\n // causes registerGlobal() in sdk.start() to fail with \"All API registration versions\n // must match\", resulting in Noop providers. Deleting the global object forces\n // registerGlobal() to create a fresh one with the correct version.\n const globalOpentelemetryApiKey = Symbol.for(\"opentelemetry.js.api.1\");\n Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);\n\n // Create internal handlers\n const metricHandler = new MetricHandler(config);\n const traceHandler = new TraceHandler(config, metricHandler);\n const logHandler = new LogHandler(config, metricHandler);\n\n const instrumentations = traceHandler\n .getInstrumentations()\n .concat(logHandler.getInstrumentations());\n consoleInstrumentation = logHandler.getConsoleInstrumentation();\n\n const resourceDetectorsList = parseResourceDetectorsFromEnvVar();\n\n // Add extra SpanProcessors, and logRecordProcessors from user configuration\n const spanProcessors: SpanProcessor[] = options?.spanProcessors || [];\n const logRecordProcessors: LogRecordProcessor[] = options?.logRecordProcessors || [];\n const customViews: ViewOptions[] = options?.views || [];\n\n // Prepare metric readers - always include Azure Monitor\n const metricReaders: MetricReader[] = [\n metricHandler.getMetricReader(),\n ...(options?.metricReaders || []),\n ];\n\n const views: ViewOptions[] = metricHandler.getViews().concat(customViews);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n metricReaders: metricReaders,\n views,\n instrumentations: instrumentations,\n logRecordProcessors: [\n logHandler.getAzureLogRecordProcessor(),\n ...logRecordProcessors,\n logHandler.getBatchLogRecordProcessor(),\n ],\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessors: [\n traceHandler.getAzureMonitorSpanProcessor(),\n ...spanProcessors,\n traceHandler.getBatchSpanProcessor(),\n ],\n resourceDetectors: resourceDetectorsList,\n };\n sdk = new NodeSDK(sdkConfig);\n setSdkPrefix();\n sendAttachWarning();\n sdk.start();\n\n // Eagerly install the Azure SDK tracing bridge in case @azure/core-tracing\n // was loaded before useAzureMonitor() (the RITM hook misses it otherwise).\n ensureAzureSdkTracingBridge();\n}\n\n/**\n * Shutdown Azure Monitor Open Telemetry Distro\n * @see https://github.com/open-telemetry/opentelemetry-js/blob/0229434cb5a3179f63c021105f36270ae7897929/experimental/packages/opentelemetry-sdk-node/src/sdk.ts#L398\n */\nexport function shutdownAzureMonitor(): Promise<void> {\n browserSdkLoader?.dispose();\n // NodeSDK.shutdown() does not restore the global console.\n consoleInstrumentation?.disable();\n consoleInstrumentation = undefined;\n return sdk?.shutdown();\n}\n\n/**\n * Get the internal SDK instance for testing purposes\n * @internal\n */\n// eslint-disable-next-line no-underscore-dangle\nexport function _getSdkInstance(): NodeSDK | undefined {\n return sdk;\n}\n"]}
1
+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AAO,EAAE,aAAa,IAAI,EAAE,CAAC;KAClC,CAAC;IAEF,MAAM,KAAK,GAAkB,aAAa,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAE1E,+BAA+B;IAC/B,MAAM,SAAS,GAAkC;QAC/C,mBAAmB,EAAE,IAAI;QACzB,aAAa,EAAE,aAAa;QAC5B,KAAK;QACL,gBAAgB,EAAE,gBAAgB;QAClC,mBAAmB,EAAE;YACnB,UAAU,CAAC,0BAA0B,EAAE;YACvC,GAAG,mBAAmB;YACtB,UAAU,CAAC,0BAA0B,EAAE;SACxC;QACD,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,YAAY,CAAC,UAAU,EAAE;QAClC,cAAc,EAAE;YACd,YAAY,CAAC,4BAA4B,EAAE;YAC3C,GAAG,cAAc;YACjB,YAAY,CAAC,qBAAqB,EAAE;SACrC;QACD,iBAAiB,EAAE,qBAAqB;KACzC,CAAC;IACF,GAAG,GAAG,IAAI,kBAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,IAAA,uBAAY,GAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;IACpB,GAAG,CAAC,KAAK,EAAE,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB;IAClC,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAC5B,uBAAuB,EAAE,CAAC;IAC1B,OAAO,GAAG,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,gDAAgD;AAChD,SAAgB,eAAe;IAC7B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport type { NodeSDKConfiguration } from \"@opentelemetry/sdk-node\";\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\nimport type { MetricReader, ViewOptions } from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"./shared/config.js\";\nimport { MetricHandler } from \"./metrics/index.js\";\nimport { TraceHandler } from \"./traces/handler.js\";\nimport { LogHandler } from \"./logs/index.js\";\nimport type {\n StatsbeatFeatures,\n StatsbeatInstrumentations,\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n ConsoleInstrumentationOptions,\n BrowserSdkLoaderOptions,\n} from \"./types.js\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n APPLICATIONINSIGHTS_SDKSTATS_DISABLED,\n} from \"./types.js\";\nimport { BrowserSdkLoader } from \"./browserSdkLoader/browserSdkLoader.js\";\nimport { setSdkPrefix } from \"./metrics/quickpulse/utils.js\";\nimport type { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport type { LogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport { getInstance } from \"./utils/statsbeat.js\";\nimport { patchOpenTelemetryInstrumentationEnable } from \"./utils/opentelemetryInstrumentationPatcher.js\";\nimport { isFunctionApp, parseResourceDetectorsFromEnvVar } from \"./utils/common.js\";\nimport { isLogCollectionDisabled } from \"./utils/logUtils.js\";\nimport { Logger } from \"./shared/logging/index.js\";\nimport { AZURE_MONITOR_AUTO_ATTACH } from \"./types.js\";\n\nexport type {\n AzureMonitorOpenTelemetryOptions,\n InstrumentationOptions,\n ConsoleInstrumentationOptions,\n BrowserSdkLoaderOptions,\n};\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet sdk: NodeSDK;\nlet browserSdkLoader: BrowserSdkLoader | undefined;\n// NodeSDK shuts down providers, but leaves instrumentation hooks enabled.\nlet instrumentations: Instrumentation[] = [];\nconst instrumentationCache = new Map<string, Instrumentation>();\n\nfunction disableInstrumentations(): void {\n for (const instrumentation of instrumentations) {\n instrumentation.disable();\n }\n instrumentations = [];\n}\n\n/**\n * Check if auto-attach (autoinstrumentation) is enabled and warn about double instrumentation.\n */\nfunction sendAttachWarning(): void {\n if (process.env[AZURE_MONITOR_AUTO_ATTACH] === \"true\" && !isFunctionApp()) {\n // TODO: When AKS attach is public, update this message with disablement instructions for AKS\n const message =\n \"Distro detected that automatic instrumentation may have occurred. Only use autoinstrumentation if you \" +\n \"are not using manual instrumentation of OpenTelemetry in your code, such as with \" +\n \"@azure/monitor-opentelemetry or @azure/monitor-opentelemetry-exporter. For App Service resources, disable \" +\n \"autoinstrumentation in the Application Insights experience on your App Service resource or by setting \" +\n \"the ApplicationInsightsAgent_EXTENSION_VERSION app setting to 'disabled'.\";\n // Surface in the log stream\n console.warn(message);\n // Also log via diagnostic logging\n Logger.getInstance().warn(message);\n }\n}\n\n/**\n * Initialize Azure Monitor Distro\n * @param options - Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions): void {\n const config = new InternalConfig(options);\n disableInstrumentations();\n patchOpenTelemetryInstrumentationEnable();\n // Omit disabled log instrumentations from Statsbeat.\n const logInstrumentationsEnabled = !isLogCollectionDisabled();\n const statsbeatInstrumentations: StatsbeatInstrumentations = {\n // Instrumentations\n azureSdk: config.instrumentationOptions?.azureSdk?.enabled,\n mongoDb: config.instrumentationOptions?.mongoDb?.enabled,\n mySql: config.instrumentationOptions?.mySql?.enabled,\n postgreSql: config.instrumentationOptions?.postgreSql?.enabled,\n redis: config.instrumentationOptions?.redis?.enabled,\n bunyan: logInstrumentationsEnabled && config.instrumentationOptions?.bunyan?.enabled,\n winston: logInstrumentationsEnabled && config.instrumentationOptions?.winston?.enabled,\n console: logInstrumentationsEnabled && config.instrumentationOptions?.console?.enabled,\n };\n // Only report this feature when the AKS resource detector itself was able to populate the AKS\n // cluster attributes, which requires the customer to have configured access to the\n // aks-cluster-metadata ConfigMap (RBAC + env var or mounted file).\n const statsbeatFeatures: StatsbeatFeatures = {\n browserSdkLoader: config.browserSdkLoaderOptions.enabled,\n aadHandling: !!config.azureMonitorExporterOptions?.credential,\n diskRetry: !config.azureMonitorExporterOptions?.disableOfflineStorage,\n customerSdkStats: process.env[APPLICATIONINSIGHTS_SDKSTATS_DISABLED]?.toLowerCase() === \"true\",\n aksResourceDetectorPopulation: config.aksResourceDetectorPopulated,\n };\n getInstance().setStatsbeatFeatures(statsbeatInstrumentations, statsbeatFeatures);\n\n if (config.browserSdkLoaderOptions.enabled) {\n browserSdkLoader = new BrowserSdkLoader(config);\n }\n // Remove global providers in OpenTelemetry, these would be overridden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n\n // Clear the entire OpenTelemetry API global state to avoid version conflicts.\n // The disable() calls above remove individual providers but leave the `version` field\n // on the global object intact. If a different version of @opentelemetry/api was loaded\n // first (e.g. by a VS Code extension host or another extension), the stale version\n // causes registerGlobal() in sdk.start() to fail with \"All API registration versions\n // must match\", resulting in Noop providers. Deleting the global object forces\n // registerGlobal() to create a fresh one with the correct version.\n const globalOpentelemetryApiKey = Symbol.for(\"opentelemetry.js.api.1\");\n Reflect.deleteProperty(globalThis, globalOpentelemetryApiKey);\n\n // Create internal handlers\n const metricHandler = new MetricHandler(config);\n const traceHandler = new TraceHandler(config, metricHandler, instrumentationCache);\n const logHandler = new LogHandler(config, metricHandler, instrumentationCache);\n\n instrumentations = traceHandler.getInstrumentations().concat(logHandler.getInstrumentations());\n\n const resourceDetectorsList = parseResourceDetectorsFromEnvVar();\n\n // Add extra SpanProcessors, and logRecordProcessors from user configuration\n const spanProcessors: SpanProcessor[] = options?.spanProcessors || [];\n const logRecordProcessors: LogRecordProcessor[] = options?.logRecordProcessors || [];\n const customViews: ViewOptions[] = options?.views || [];\n\n // Prepare metric readers - always include Azure Monitor\n const metricReaders: MetricReader[] = [\n metricHandler.getMetricReader(),\n ...(options?.metricReaders || []),\n ];\n\n const views: ViewOptions[] = metricHandler.getViews().concat(customViews);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n metricReaders: metricReaders,\n views,\n instrumentations: instrumentations,\n logRecordProcessors: [\n logHandler.getAzureLogRecordProcessor(),\n ...logRecordProcessors,\n logHandler.getBatchLogRecordProcessor(),\n ],\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessors: [\n traceHandler.getAzureMonitorSpanProcessor(),\n ...spanProcessors,\n traceHandler.getBatchSpanProcessor(),\n ],\n resourceDetectors: resourceDetectorsList,\n };\n sdk = new NodeSDK(sdkConfig);\n setSdkPrefix();\n sendAttachWarning();\n sdk.start();\n}\n\n/**\n * Shutdown Azure Monitor Open Telemetry Distro\n * @see https://github.com/open-telemetry/opentelemetry-js/blob/0229434cb5a3179f63c021105f36270ae7897929/experimental/packages/opentelemetry-sdk-node/src/sdk.ts#L398\n */\nexport function shutdownAzureMonitor(): Promise<void> {\n browserSdkLoader?.dispose();\n disableInstrumentations();\n return sdk?.shutdown();\n}\n\n/**\n * Get the internal SDK instance for testing purposes\n * @internal\n */\n// eslint-disable-next-line no-underscore-dangle\nexport function _getSdkInstance(): NodeSDK | undefined {\n return sdk;\n}\n"]}
@@ -7,6 +7,7 @@ import { AzureLogRecordProcessor } from "./logRecordProcessor.js";
7
7
  * Azure Monitor OpenTelemetry Log Handler
8
8
  */
9
9
  export declare class LogHandler {
10
+ private readonly instrumentationCache?;
10
11
  private _azureExporter;
11
12
  private _azureLogRecordProcessor;
12
13
  private _azureBatchLogRecordProcessor;
@@ -19,7 +20,7 @@ export declare class LogHandler {
19
20
  * @param _config - Distro configuration.
20
21
  * @param _metricHandler - MetricHandler.
21
22
  */
22
- constructor(config: InternalConfig, metricHandler: MetricHandler);
23
+ constructor(config: InternalConfig, metricHandler: MetricHandler, instrumentationCache?: Map<string, Instrumentation> | undefined);
23
24
  getAzureLogRecordProcessor(): AzureLogRecordProcessor;
24
25
  getBatchLogRecordProcessor(): BatchLogRecordProcessor;
25
26
  getInstrumentations(): Instrumentation[];
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAIlE;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,cAAc,CAA0B;IAChD,OAAO,CAAC,wBAAwB,CAA0B;IAC1D,OAAO,CAAC,6BAA6B,CAA+B;IACpE,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,uBAAuB,CAA8B;IAE7D;;;;OAIG;gBACS,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa;IAYzD,0BAA0B,IAAI,uBAAuB;IAIrD,0BAA0B,IAAI,uBAAuB;IAIrD,mBAAmB,IAAI,eAAe,EAAE;IAI/C,6EAA6E;IACtE,yBAAyB,IAAI,eAAe,GAAG,SAAS;IAI/D;;OAEG;IACH,OAAO,CAAC,2BAA2B;CAmCpC"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAKlE;;GAEG;AACH,qBAAa,UAAU;IAiBnB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IAhBxC,OAAO,CAAC,cAAc,CAA0B;IAChD,OAAO,CAAC,wBAAwB,CAA0B;IAC1D,OAAO,CAAC,6BAA6B,CAA+B;IACpE,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,uBAAuB,CAA8B;IAE7D;;;;OAIG;gBAED,MAAM,EAAE,cAAc,EACtB,aAAa,EAAE,aAAa,EACX,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,YAAA;IAa/D,0BAA0B,IAAI,uBAAuB;IAIrD,0BAA0B,IAAI,uBAAuB;IAIrD,mBAAmB,IAAI,eAAe,EAAE;IAI/C,6EAA6E;IACtE,yBAAyB,IAAI,eAAe,GAAG,SAAS;IAI/D;;OAEG;IACH,OAAO,CAAC,2BAA2B;CAgDpC"}
@@ -10,10 +10,12 @@ const instrumentation_winston_1 = require("@opentelemetry/instrumentation-winsto
10
10
  const logRecordProcessor_js_1 = require("./logRecordProcessor.js");
11
11
  const batchLogRecordProcessor_js_1 = require("./batchLogRecordProcessor.js");
12
12
  const logUtils_js_1 = require("../utils/logUtils.js");
13
+ const instrumentation_js_1 = require("../utils/instrumentation.js");
13
14
  /**
14
15
  * Azure Monitor OpenTelemetry Log Handler
15
16
  */
16
17
  class LogHandler {
18
+ instrumentationCache;
17
19
  _azureExporter;
18
20
  _azureLogRecordProcessor;
19
21
  _azureBatchLogRecordProcessor;
@@ -26,7 +28,8 @@ class LogHandler {
26
28
  * @param _config - Distro configuration.
27
29
  * @param _metricHandler - MetricHandler.
28
30
  */
29
- constructor(config, metricHandler) {
31
+ constructor(config, metricHandler, instrumentationCache) {
32
+ this.instrumentationCache = instrumentationCache;
30
33
  this._config = config;
31
34
  this._metricHandler = metricHandler;
32
35
  this._azureExporter = new monitor_opentelemetry_exporter_1.AzureMonitorLogExporter(config.azureMonitorExporterOptions);
@@ -60,23 +63,26 @@ class LogHandler {
60
63
  const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;
61
64
  const logSeverity = logLevelEnv ? (0, logUtils_js_1.logLevelToSeverityNumber)(logLevelEnv) : undefined;
62
65
  if (this._config.instrumentationOptions.bunyan?.enabled) {
63
- this._instrumentations.push(new instrumentation_bunyan_1.BunyanInstrumentation({
66
+ this._instrumentations.push((0, instrumentation_js_1.configureInstrumentation)(this.instrumentationCache, "bunyan", {
64
67
  ...this._config.instrumentationOptions.bunyan,
65
68
  logSeverity,
66
- }));
69
+ }, (options) => new instrumentation_bunyan_1.BunyanInstrumentation(options)));
67
70
  }
68
71
  if (this._config.instrumentationOptions.winston?.enabled) {
69
- this._instrumentations.push(new instrumentation_winston_1.WinstonInstrumentation({
72
+ this._instrumentations.push((0, instrumentation_js_1.configureInstrumentation)(this.instrumentationCache, "winston", {
70
73
  ...this._config.instrumentationOptions.winston,
71
74
  logSeverity,
72
- }));
75
+ }, (options) => new instrumentation_winston_1.WinstonInstrumentation(options)));
73
76
  }
74
- if (this._config.instrumentationOptions.console?.enabled) {
77
+ const consoleOptions = this._config.instrumentationOptions.console;
78
+ if (consoleOptions?.enabled) {
75
79
  // Defer patching until registration so construction preserves the original methods.
80
+ // Console patches globals rather than module hooks and caches its logger,
81
+ // so each SDK lifetime needs a fresh instance.
76
82
  const consoleInstrumentation = new instrumentation_console_1.ConsoleInstrumentation({
77
- ...this._config.instrumentationOptions.console,
83
+ ...consoleOptions,
78
84
  enabled: false,
79
- logSeverity,
85
+ logSeverity: consoleOptions.logSeverity ?? logSeverity,
80
86
  });
81
87
  this._consoleInstrumentation = consoleInstrumentation;
82
88
  this._instrumentations.push(consoleInstrumentation);
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":";AAAA,uCAAuC;A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AAG,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC;QAClF,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,IAAA,sCAAwB,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAEpF,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACxD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,8CAAqB,CAAC;gBACxB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM;gBAC7C,WAAW;aACZ,CAAC,CACH,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YACzD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,gDAAsB,CAAC;gBACzB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO;gBAC9C,WAAW;aACZ,CAAC,CACH,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YACzD,oFAAoF;YACpF,MAAM,sBAAsB,GAAG,IAAI,gDAAsB,CAAC;gBACxD,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO;gBAC9C,OAAO,EAAE,KAAK;gBACd,WAAW;aACZ,CAAC,CAAC;YACH,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAjFD,gCAiFC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzureMonitorLogExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BunyanInstrumentation } from \"@opentelemetry/instrumentation-bunyan\";\nimport { ConsoleInstrumentation } from \"@opentelemetry/instrumentation-console\";\nimport { WinstonInstrumentation } from \"@opentelemetry/instrumentation-winston\";\nimport type { BatchLogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport type { InternalConfig } from \"../shared/config.js\";\nimport type { MetricHandler } from \"../metrics/handler.js\";\nimport { AzureLogRecordProcessor } from \"./logRecordProcessor.js\";\nimport { AzureBatchLogRecordProcessor } from \"./batchLogRecordProcessor.js\";\nimport { isLogCollectionDisabled, logLevelToSeverityNumber } from \"../utils/logUtils.js\";\n\n/**\n * Azure Monitor OpenTelemetry Log Handler\n */\nexport class LogHandler {\n private _azureExporter: AzureMonitorLogExporter;\n private _azureLogRecordProcessor: AzureLogRecordProcessor;\n private _azureBatchLogRecordProcessor: AzureBatchLogRecordProcessor;\n private _metricHandler: MetricHandler;\n private _config: InternalConfig;\n private _instrumentations: Instrumentation[];\n private _consoleInstrumentation: Instrumentation | undefined;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Distro configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);\n this._azureBatchLogRecordProcessor = new AzureBatchLogRecordProcessor(this._azureExporter, {\n enableTraceBasedSamplingForLogs: this._config.enableTraceBasedSamplingForLogs,\n });\n this._azureLogRecordProcessor = new AzureLogRecordProcessor(this._metricHandler);\n this._instrumentations = [];\n this._initializeInstrumentations();\n }\n\n public getAzureLogRecordProcessor(): AzureLogRecordProcessor {\n return this._azureLogRecordProcessor;\n }\n\n public getBatchLogRecordProcessor(): BatchLogRecordProcessor {\n return this._azureBatchLogRecordProcessor;\n }\n\n public getInstrumentations(): Instrumentation[] {\n return this._instrumentations;\n }\n\n /** Returns the console instrumentation for explicit lifecycle management. */\n public getConsoleInstrumentation(): Instrumentation | undefined {\n return this._consoleInstrumentation;\n }\n\n /**\n * Start auto collection of telemetry\n */\n private _initializeInstrumentations(): void {\n if (isLogCollectionDisabled()) {\n return;\n }\n\n const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;\n const logSeverity = logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined;\n\n if (this._config.instrumentationOptions.bunyan?.enabled) {\n this._instrumentations.push(\n new BunyanInstrumentation({\n ...this._config.instrumentationOptions.bunyan,\n logSeverity,\n }),\n );\n }\n if (this._config.instrumentationOptions.winston?.enabled) {\n this._instrumentations.push(\n new WinstonInstrumentation({\n ...this._config.instrumentationOptions.winston,\n logSeverity,\n }),\n );\n }\n if (this._config.instrumentationOptions.console?.enabled) {\n // Defer patching until registration so construction preserves the original methods.\n const consoleInstrumentation = new ConsoleInstrumentation({\n ...this._config.instrumentationOptions.console,\n enabled: false,\n logSeverity,\n });\n this._consoleInstrumentation = consoleInstrumentation;\n this._instrumentations.push(consoleInstrumentation);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,0FAAgF;AAEhF,kFAA8E;AAC9E,oFAAgF;AAChF,oFAAgF;AAIhF,mEAAkE;AAClE,6EAA4E;AAC5E,sDAAyF;AACzF,oEAAuE;AAEvE;;GAEG;AACH,MAAa,UAAU;IAiBF;IAhBX,cAAc,CAA0B;IACxC,wBAAwB,CAA0B;IAClD,6BAA6B,CAA+B;IAC5D,cAAc,CAAgB;IAC9B,OAAO,CAAiB;IACxB,iBAAiB,CAAoB;IACrC,uBAAuB,CAA8B;IAE7D;;;;OAIG;IACH,YACE,MAAsB,EACtB,aAA4B,EACX,oBAAmD;QAAnD,yBAAoB,GAApB,oBAAoB,CAA+B;QAEpE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QAC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AAE,EAAE,CAAC,IAAI,8CAAqB,CAAC,OAAO,CAAC,CAChD,CACF,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YACzD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAA,6CAAwB,EACtB,IAAI,CAAC,oBAAoB,EACzB,SAAS,EACT;gBACE,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO;gBAC9C,WAAW;aACZ,EACD,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,gDAAsB,CAAC,OAAO,CAAC,CACjD,CACF,CAAC;QACJ,CAAC;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC;QACnE,IAAI,cAAc,EAAE,OAAO,EAAE,CAAC;YAC5B,oFAAoF;YACpF,0EAA0E;YAC1E,+CAA+C;YAC/C,MAAM,sBAAsB,GAAG,IAAI,gDAAsB,CAAC;gBACxD,GAAG,cAAc;gBACjB,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,WAAW;aACvD,CAAC,CAAC;YACH,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAlGD,gCAkGC","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;AA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 @@ class PerformanceCounterMetrics {
38
38
  processTimeGaugeCallback;
39
39
  exceptionCountGauge;
40
40
  exceptionCountGaugeCallback;
41
- lastExceptionRate = { count: 0, time: 0 };
41
+ lastExceptionRate;
42
42
  totalCount = 0;
43
43
  intervalExecutionTime = 0;
44
44
  lastRequestRate;
@@ -46,6 +46,9 @@ class PerformanceCounterMetrics {
46
46
  lastHrtime;
47
47
  lastCpus;
48
48
  lastCpusProcess;
49
+ lastAppCpuUsageNormalized;
50
+ lastHrtimeNormalized;
51
+ lastCpusProcessNormalized;
49
52
  totalExceptionCount = 0;
50
53
  /**
51
54
  * Creates performance counter instruments.
@@ -58,11 +61,15 @@ class PerformanceCounterMetrics {
58
61
  this.lastCpusProcess = node_os_1.default.cpus();
59
62
  this.lastAppCpuUsage = node_process_1.default.cpuUsage();
60
63
  this.lastHrtime = node_process_1.default.hrtime();
64
+ this.lastCpusProcessNormalized = node_os_1.default.cpus();
65
+ this.lastAppCpuUsageNormalized = node_process_1.default.cpuUsage();
66
+ this.lastHrtimeNormalized = node_process_1.default.hrtime();
61
67
  this.lastRequestRate = {
62
68
  count: this.totalCount,
63
69
  time: +new Date(),
64
70
  executionInterval: this.intervalExecutionTime,
65
71
  };
72
+ this.lastExceptionRate = { count: this.totalExceptionCount, time: +new Date() };
66
73
  this.azureExporter = new monitor_opentelemetry_exporter_1.AzureMonitorMetricExporter(this.internalConfig.azureMonitorExporterOptions);
67
74
  const metricReaderOptions = {
68
75
  exporter: this.azureExporter,
@@ -74,7 +81,6 @@ class PerformanceCounterMetrics {
74
81
  };
75
82
  this.meterProvider = new sdk_metrics_1.MeterProvider(meterProviderConfig);
76
83
  this.meter = this.meterProvider.getMeter("AzureMonitorPerformanceCountersMeter");
77
- this.lastRequestRate = { count: 0, time: 0, executionInterval: 0 };
78
84
  // Create Instruments
79
85
  this.requestDurationHistogram = this.meter.createHistogram(types_js_1.PerformanceCounterMetricNames.REQUEST_DURATION, { valueType: api_1.ValueType.DOUBLE });
80
86
  this.requestRateGauge = this.meter.createObservableGauge(types_js_1.PerformanceCounterMetricNames.REQUEST_RATE, {
@@ -248,33 +254,31 @@ class PerformanceCounterMetrics {
248
254
  const cpus = node_os_1.default.cpus();
249
255
  if (cpus &&
250
256
  cpus.length &&
251
- this.lastCpusProcess &&
252
- cpus.length === this.lastCpusProcess.length) {
257
+ this.lastCpusProcessNormalized &&
258
+ cpus.length === this.lastCpusProcessNormalized.length) {
253
259
  // Calculate % of total cpu time (user + system) this App Process used (Only supported by node v6.1.0+)
254
260
  let appCpuPercent = undefined;
255
261
  const appCpuUsage = node_process_1.default.cpuUsage();
256
262
  const hrtime = node_process_1.default.hrtime();
257
263
  const totalApp = appCpuUsage.user -
258
- this.lastAppCpuUsage.user +
259
- (appCpuUsage.system - this.lastAppCpuUsage.system) || 0;
260
- if (typeof this.lastHrtime !== "undefined" && this.lastHrtime.length === 2) {
261
- const elapsedTime = (hrtime[0] - this.lastHrtime[0]) * 1e6 + (hrtime[1] - this.lastHrtime[1]) / 1e3 || 0; // convert to microseconds
264
+ this.lastAppCpuUsageNormalized.user +
265
+ (appCpuUsage.system - this.lastAppCpuUsageNormalized.system) || 0;
266
+ if (typeof this.lastHrtimeNormalized !== "undefined" &&
267
+ this.lastHrtimeNormalized.length === 2) {
268
+ const elapsedTime = (hrtime[0] - this.lastHrtimeNormalized[0]) * 1e6 +
269
+ (hrtime[1] - this.lastHrtimeNormalized[1]) / 1e3 || 0; // convert to microseconds
262
270
  appCpuPercent = (100 * totalApp) / (elapsedTime * cpus.length);
263
271
  }
264
272
  // Set previous
265
- this.lastAppCpuUsage = appCpuUsage;
266
- this.lastHrtime = hrtime;
267
- const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);
268
- let value = 0;
269
- if (appCpuPercent !== undefined) {
270
- value = appCpuPercent;
271
- }
272
- else {
273
- value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
274
- }
273
+ this.lastAppCpuUsageNormalized = appCpuUsage;
274
+ this.lastHrtimeNormalized = hrtime;
275
+ const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcessNormalized);
276
+ const value = appCpuPercent !== undefined
277
+ ? appCpuPercent
278
+ : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
275
279
  observableResult.observe(value);
276
280
  }
277
- this.lastCpusProcess = cpus;
281
+ this.lastCpusProcessNormalized = cpus;
278
282
  }
279
283
  getProcessTime(observableResult) {
280
284
  // this reports total ms spent in each category since the OS was booted, to calculate percent it is necessary
@@ -300,13 +304,9 @@ class PerformanceCounterMetrics {
300
304
  this.lastAppCpuUsage = appCpuUsage;
301
305
  this.lastHrtime = hrtime;
302
306
  const cpuTotals = this.getTotalCombinedCpu(cpus, this.lastCpusProcess);
303
- let value = 0;
304
- if (appCpuPercent !== undefined) {
305
- value = appCpuPercent;
306
- }
307
- else {
308
- value = (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
309
- }
307
+ const value = appCpuPercent !== undefined
308
+ ? appCpuPercent
309
+ : (cpuTotals.totalUser / cpuTotals.combinedTotal) * 100;
310
310
  observableResult.observe(value);
311
311
  }
312
312
  this.lastCpusProcess = cpus;