@azure/monitor-opentelemetry-exporter 1.0.0-beta.25 → 1.0.0-beta.27

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 (74) hide show
  1. package/dist/index.js +205 -42
  2. package/dist-esm/src/Declarations/Constants.js +7 -2
  3. package/dist-esm/src/Declarations/Constants.js.map +1 -1
  4. package/dist-esm/src/Declarations/Contracts/Constants.js +1 -1
  5. package/dist-esm/src/Declarations/Contracts/Constants.js.map +1 -1
  6. package/dist-esm/src/Declarations/Contracts/index.js +1 -1
  7. package/dist-esm/src/Declarations/Contracts/index.js.map +1 -1
  8. package/dist-esm/src/config.js.map +1 -1
  9. package/dist-esm/src/export/base.js +3 -3
  10. package/dist-esm/src/export/base.js.map +1 -1
  11. package/dist-esm/src/export/log.js +2 -1
  12. package/dist-esm/src/export/log.js.map +1 -1
  13. package/dist-esm/src/export/metric.js +2 -1
  14. package/dist-esm/src/export/metric.js.map +1 -1
  15. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +1 -1
  16. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
  17. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +38 -1
  18. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
  19. package/dist-esm/src/export/statsbeat/statsbeatExporter.js +2 -2
  20. package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
  21. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js +1 -1
  22. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js.map +1 -1
  23. package/dist-esm/src/export/statsbeat/types.js +15 -1
  24. package/dist-esm/src/export/statsbeat/types.js.map +1 -1
  25. package/dist-esm/src/export/trace.js +2 -1
  26. package/dist-esm/src/export/trace.js.map +1 -1
  27. package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
  28. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  29. package/dist-esm/src/index.js +1 -1
  30. package/dist-esm/src/index.js.map +1 -1
  31. package/dist-esm/src/platform/index.js +1 -1
  32. package/dist-esm/src/platform/index.js.map +1 -1
  33. package/dist-esm/src/platform/nodejs/baseSender.js +19 -5
  34. package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -1
  35. package/dist-esm/src/platform/nodejs/constants.js +1 -1
  36. package/dist-esm/src/platform/nodejs/constants.js.map +1 -1
  37. package/dist-esm/src/platform/nodejs/context/context.js +1 -1
  38. package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
  39. package/dist-esm/src/platform/nodejs/context/index.js +1 -1
  40. package/dist-esm/src/platform/nodejs/context/index.js.map +1 -1
  41. package/dist-esm/src/platform/nodejs/httpSender.js +1 -1
  42. package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
  43. package/dist-esm/src/platform/nodejs/index.js +1 -1
  44. package/dist-esm/src/platform/nodejs/index.js.map +1 -1
  45. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +1 -1
  46. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
  47. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js +1 -1
  48. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js.map +1 -1
  49. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +1 -2
  50. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  51. package/dist-esm/src/platform/nodejs/persist/index.js +1 -1
  52. package/dist-esm/src/platform/nodejs/persist/index.js.map +1 -1
  53. package/dist-esm/src/sampling.js.map +1 -1
  54. package/dist-esm/src/types.js +12 -1
  55. package/dist-esm/src/types.js.map +1 -1
  56. package/dist-esm/src/utils/breezeUtils.js +1 -1
  57. package/dist-esm/src/utils/breezeUtils.js.map +1 -1
  58. package/dist-esm/src/utils/common.js +28 -1
  59. package/dist-esm/src/utils/common.js.map +1 -1
  60. package/dist-esm/src/utils/connectionStringParser.js +1 -1
  61. package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
  62. package/dist-esm/src/utils/constants/applicationinsights.js +2 -2
  63. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  64. package/dist-esm/src/utils/constants/span/azAttributes.js +1 -1
  65. package/dist-esm/src/utils/constants/span/azAttributes.js.map +1 -1
  66. package/dist-esm/src/utils/eventhub.js +1 -1
  67. package/dist-esm/src/utils/eventhub.js.map +1 -1
  68. package/dist-esm/src/utils/logUtils.js +13 -3
  69. package/dist-esm/src/utils/logUtils.js.map +1 -1
  70. package/dist-esm/src/utils/metricUtils.js +1 -1
  71. package/dist-esm/src/utils/metricUtils.js.map +1 -1
  72. package/dist-esm/src/utils/spanUtils.js +51 -6
  73. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  74. package/package.json +30 -31
package/dist/index.js CHANGED
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
6
6
  var api = require('@opentelemetry/api');
7
7
  var core = require('@opentelemetry/core');
8
- var url = require('url');
9
8
  var semanticConventions = require('@opentelemetry/semantic-conventions');
10
9
  var os$1 = require('os');
10
+ var url = require('url');
11
11
  var coreRestPipeline = require('@azure/core-rest-pipeline');
12
12
  var sdkMetrics = require('@opentelemetry/sdk-metrics');
13
13
  var fs = require('fs');
@@ -40,7 +40,7 @@ var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_proce
40
40
  var coreClient__namespace = /*#__PURE__*/_interopNamespaceDefault(coreClient);
41
41
 
42
42
  // Copyright (c) Microsoft Corporation.
43
- // Licensed under the MIT license.
43
+ // Licensed under the MIT License.
44
44
  /**
45
45
  * AI MS Links.
46
46
  * @internal
@@ -60,7 +60,7 @@ const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
60
60
  * AzureMonitorTraceExporter version.
61
61
  * @internal
62
62
  */
63
- const packageVersion = "1.0.0-beta.25";
63
+ const packageVersion = "1.0.0-beta.27";
64
64
  var DependencyTypes;
65
65
  (function (DependencyTypes) {
66
66
  DependencyTypes["InProc"] = "InProc";
@@ -170,7 +170,7 @@ class ApplicationInsightsSampler {
170
170
  }
171
171
 
172
172
  // Copyright (c) Microsoft Corporation.
173
- // Licensed under the MIT license.
173
+ // Licensed under the MIT License.
174
174
  /**
175
175
  * Azure service API version.
176
176
  */
@@ -205,7 +205,12 @@ const ENV_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";
205
205
  * Disable Statsbeat environment variable name.
206
206
  * @internal
207
207
  */
208
- const ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT";
208
+ const ENV_DISABLE_STATSBEAT = "APPLICATIONINSIGHTS_STATSBEAT_DISABLED";
209
+ /**
210
+ * Legacy disable Statsbeat environment variable name.
211
+ * @internal
212
+ */
213
+ const LEGACY_ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT";
209
214
  /**
210
215
  * QuickPulse metric counter names.
211
216
  * @internal
@@ -261,7 +266,7 @@ var PerformanceCounter;
261
266
  });
262
267
 
263
268
  // Copyright (c) Microsoft Corporation.
264
- // Licensed under the MIT license.
269
+ // Licensed under the MIT License.
265
270
  /**
266
271
  * ConnectionString parser.
267
272
  * @internal
@@ -337,7 +342,7 @@ ConnectionStringParser.FIELDS_SEPARATOR = ";";
337
342
  ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR = "=";
338
343
 
339
344
  // Copyright (c) Microsoft Corporation.
340
- // Licensed under the MIT license.
345
+ // Licensed under the MIT License.
341
346
  /**
342
347
  * Azure Monitor OpenTelemetry Trace Exporter.
343
348
  */
@@ -383,13 +388,13 @@ class AzureMonitorBaseExporter {
383
388
  api.diag.error(message);
384
389
  throw new Error(message);
385
390
  }
386
- this.trackStatsbeat = !this.isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];
391
+ this.trackStatsbeat = !this.isStatsbeatExporter && !process.env[LEGACY_ENV_DISABLE_STATSBEAT];
387
392
  api.diag.debug("AzureMonitorExporter was successfully setup");
388
393
  }
389
394
  }
390
395
 
391
396
  // Copyright (c) Microsoft Corporation.
392
- // Licensed under the MIT license.
397
+ // Licensed under the MIT License.
393
398
  class FileAccessControl {
394
399
  // Check if file access control could be enabled
395
400
  static checkFileProtection() {
@@ -556,7 +561,7 @@ FileAccessControl.OS_PROVIDES_FILE_PROTECTION = false;
556
561
  FileAccessControl.USE_ICACLS = os__namespace.type() === "Windows_NT";
557
562
 
558
563
  // Copyright (c) Microsoft Corporation.
559
- // Licensed under the MIT license.
564
+ // Licensed under the MIT License.
560
565
  const readdirAsync$1 = util.promisify(fs__namespace.readdir);
561
566
  const statAsync$1 = util.promisify(fs__namespace.stat);
562
567
  const lstatAsync = util.promisify(fs__namespace.lstat);
@@ -612,7 +617,7 @@ const confirmDirExists = async (directory) => {
612
617
  };
613
618
 
614
619
  // Copyright (c) Microsoft Corporation.
615
- // Licensed under the MIT license.
620
+ // Licensed under the MIT License.
616
621
  const statAsync = util.promisify(fs__namespace.stat);
617
622
  const readdirAsync = util.promisify(fs__namespace.readdir);
618
623
  const readFileAsync = util.promisify(fs__namespace.readFile);
@@ -679,7 +684,6 @@ class FileSystemPersist {
679
684
  try {
680
685
  const buffer = await this._getFirstFileOnDisk();
681
686
  if (buffer) {
682
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
683
687
  return JSON.parse(buffer.toString("utf8"));
684
688
  }
685
689
  }
@@ -1826,7 +1830,7 @@ class ApplicationInsightsClient extends coreClient__namespace.ServiceClient {
1826
1830
  const defaults = {
1827
1831
  requestContentType: "application/json; charset=utf-8",
1828
1832
  };
1829
- const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.25`;
1833
+ const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.27`;
1830
1834
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1831
1835
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1832
1836
  : `${packageDetails}`;
@@ -1887,13 +1891,15 @@ const trackOperationSpec = {
1887
1891
  };
1888
1892
 
1889
1893
  // Copyright (c) Microsoft Corporation.
1890
- // Licensed under the MIT license.
1894
+ // Licensed under the MIT License.
1891
1895
  class NetworkStatsbeat {
1892
1896
  constructor(endpoint, host) {
1893
1897
  this.endpoint = endpoint;
1894
1898
  this.host = host;
1895
1899
  this.totalRequestCount = 0;
1896
1900
  this.totalSuccesfulRequestCount = 0;
1901
+ this.totalReadFailureCount = 0;
1902
+ this.totalWriteFailureCount = 0;
1897
1903
  this.totalFailedRequestCount = [];
1898
1904
  this.retryCount = [];
1899
1905
  this.exceptionCount = [];
@@ -1922,6 +1928,8 @@ var StatsbeatCounter;
1922
1928
  StatsbeatCounter["THROTTLE_COUNT"] = "Throttle_Count";
1923
1929
  StatsbeatCounter["EXCEPTION_COUNT"] = "Exception_Count";
1924
1930
  StatsbeatCounter["AVERAGE_DURATION"] = "Request_Duration";
1931
+ StatsbeatCounter["READ_FAILURE_COUNT"] = "Read_Failure_Count";
1932
+ StatsbeatCounter["WRITE_FAILURE_COUNT"] = "Write_Failure_Count";
1925
1933
  StatsbeatCounter["ATTACH"] = "Attach";
1926
1934
  StatsbeatCounter["FEATURE"] = "Feature";
1927
1935
  })(StatsbeatCounter || (StatsbeatCounter = {}));
@@ -1949,9 +1957,19 @@ var StatsbeatFeatureType;
1949
1957
  StatsbeatFeatureType[StatsbeatFeatureType["FEATURE"] = 0] = "FEATURE";
1950
1958
  StatsbeatFeatureType[StatsbeatFeatureType["INSTRUMENTATION"] = 1] = "INSTRUMENTATION";
1951
1959
  })(StatsbeatFeatureType || (StatsbeatFeatureType = {}));
1960
+ /**
1961
+ * Status codes indicating that we should shutdown statsbeat
1962
+ * @internal
1963
+ */
1964
+ function isStatsbeatShutdownStatus(statusCode) {
1965
+ return (statusCode === 401 || // Unauthorized
1966
+ statusCode === 403 || // Forbidden
1967
+ statusCode === 503 // Server Unavailable
1968
+ );
1969
+ }
1952
1970
 
1953
1971
  // Copyright (c) Microsoft Corporation.
1954
- // Licensed under the MIT license.
1972
+ // Licensed under the MIT License.
1955
1973
  // eslint-disable-next-line @typescript-eslint/no-require-imports
1956
1974
  const os = require("os");
1957
1975
  class StatsbeatMetrics {
@@ -2050,7 +2068,7 @@ class StatsbeatMetrics {
2050
2068
  }
2051
2069
 
2052
2070
  // Copyright (c) Microsoft Corporation.
2053
- // Licensed under the MIT license.
2071
+ // Licensed under the MIT License.
2054
2072
  /**
2055
2073
  * Performance Counter OpenTelemetry compliant names.
2056
2074
  * @internal
@@ -2077,9 +2095,20 @@ var BreezePerformanceCounterNames;
2077
2095
  BreezePerformanceCounterNames["REQUEST_RATE"] = "\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec";
2078
2096
  BreezePerformanceCounterNames["REQUEST_DURATION"] = "\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Request Execution Time";
2079
2097
  })(BreezePerformanceCounterNames || (BreezePerformanceCounterNames = {}));
2098
+ /**
2099
+ * Property Max Lengths
2100
+ * @internal
2101
+ */
2102
+ var MaxPropertyLengths;
2103
+ (function (MaxPropertyLengths) {
2104
+ MaxPropertyLengths[MaxPropertyLengths["NINE_BIT"] = 512] = "NINE_BIT";
2105
+ MaxPropertyLengths[MaxPropertyLengths["TEN_BIT"] = 1024] = "TEN_BIT";
2106
+ MaxPropertyLengths[MaxPropertyLengths["THIRTEEN_BIT"] = 8192] = "THIRTEEN_BIT";
2107
+ MaxPropertyLengths[MaxPropertyLengths["FIFTEEN_BIT"] = 32768] = "FIFTEEN_BIT";
2108
+ })(MaxPropertyLengths || (MaxPropertyLengths = {}));
2080
2109
 
2081
2110
  // Copyright (c) Microsoft Corporation.
2082
- // Licensed under the MIT license.
2111
+ // Licensed under the MIT License.
2083
2112
  const breezePerformanceCountersMap = new Map([
2084
2113
  [OTelPerformanceCounterNames.PRIVATE_BYTES, BreezePerformanceCounterNames.PRIVATE_BYTES],
2085
2114
  [OTelPerformanceCounterNames.AVAILABLE_BYTES, BreezePerformanceCounterNames.AVAILABLE_BYTES],
@@ -2163,7 +2192,7 @@ function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
2163
2192
  }
2164
2193
 
2165
2194
  // Copyright (c) Microsoft Corporation.
2166
- // Licensed under the MIT license.
2195
+ // Licensed under the MIT License.
2167
2196
  /**
2168
2197
  * Azure Monitor Statsbeat Exporter
2169
2198
  */
@@ -2189,7 +2218,7 @@ class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
2189
2218
  /**
2190
2219
  * Export Statsbeat metrics.
2191
2220
  */
2192
- // eslint-disable-next-line @typescript-eslint/require-await
2221
+ // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-misused-promises
2193
2222
  async export(metrics, resultCallback) {
2194
2223
  if (this._isShutdown) {
2195
2224
  setTimeout(() => resultCallback({ code: core.ExportResultCode.FAILED }), 0);
@@ -2217,10 +2246,11 @@ class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
2217
2246
  }
2218
2247
 
2219
2248
  // Copyright (c) Microsoft Corporation.
2220
- // Licensed under the MIT license.
2249
+ // Licensed under the MIT License.
2221
2250
  class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2222
2251
  constructor(options) {
2223
2252
  super();
2253
+ this.disableNonEssentialStatsbeat = !!process.env[ENV_DISABLE_STATSBEAT];
2224
2254
  this.isInitialized = false;
2225
2255
  this.statsCollectionShortInterval = 900000; // 15 minutes
2226
2256
  this.networkStatsbeatCollection = [];
@@ -2251,6 +2281,10 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2251
2281
  this.throttleCountGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.THROTTLE_COUNT);
2252
2282
  this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
2253
2283
  this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
2284
+ if (!this.disableNonEssentialStatsbeat) {
2285
+ this.readFailureGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.READ_FAILURE_COUNT);
2286
+ this.writeFailureGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.WRITE_FAILURE_COUNT);
2287
+ }
2254
2288
  this.commonProperties = {
2255
2289
  os: this.os,
2256
2290
  rp: this.resourceProvider,
@@ -2271,6 +2305,7 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2271
2305
  return this.networkStatsbeatMeterProvider.shutdown();
2272
2306
  }
2273
2307
  async initialize() {
2308
+ var _a, _b;
2274
2309
  try {
2275
2310
  await super.getResourceProvider();
2276
2311
  // Add network observable callbacks
@@ -2287,6 +2322,10 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2287
2322
  this.networkStatsbeatMeter.addBatchObservableCallback(this.exceptionCallback.bind(this), [
2288
2323
  this.exceptionCountGauge,
2289
2324
  ]);
2325
+ if (!this.disableNonEssentialStatsbeat) {
2326
+ (_a = this.readFailureGauge) === null || _a === void 0 ? void 0 : _a.addCallback(this.readFailureCallback.bind(this));
2327
+ (_b = this.writeFailureGauge) === null || _b === void 0 ? void 0 : _b.addCallback(this.writeFailureCallback.bind(this));
2328
+ }
2290
2329
  this.averageDurationGauge.addCallback(this.durationCallback.bind(this));
2291
2330
  }
2292
2331
  catch (error) {
@@ -2360,6 +2399,18 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2360
2399
  observableResult.observe(counter.averageRequestExecutionTime, attributes);
2361
2400
  counter.averageRequestExecutionTime = 0;
2362
2401
  }
2402
+ readFailureCallback(observableResult) {
2403
+ const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
2404
+ const attributes = Object.assign(Object.assign({}, this.commonProperties), this.networkProperties);
2405
+ observableResult.observe(counter.totalReadFailureCount, attributes);
2406
+ counter.totalReadFailureCount = 0;
2407
+ }
2408
+ writeFailureCallback(observableResult) {
2409
+ const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
2410
+ const attributes = Object.assign(Object.assign({}, this.commonProperties), this.networkProperties);
2411
+ observableResult.observe(counter.totalWriteFailureCount, attributes);
2412
+ counter.totalWriteFailureCount = 0;
2413
+ }
2363
2414
  // Public methods to increase counters
2364
2415
  countSuccess(duration) {
2365
2416
  if (!this.isInitialized) {
@@ -2411,6 +2462,20 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2411
2462
  counter.throttleCount.push({ statusCode: statusCode, count: 1 });
2412
2463
  }
2413
2464
  }
2465
+ countReadFailure() {
2466
+ if (!this.isInitialized || this.disableNonEssentialStatsbeat) {
2467
+ return;
2468
+ }
2469
+ const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
2470
+ counter.totalReadFailureCount++;
2471
+ }
2472
+ countWriteFailure() {
2473
+ if (!this.isInitialized || this.disableNonEssentialStatsbeat) {
2474
+ return;
2475
+ }
2476
+ const counter = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);
2477
+ counter.totalWriteFailureCount++;
2478
+ }
2414
2479
  countException(exceptionType) {
2415
2480
  if (!this.isInitialized) {
2416
2481
  return;
@@ -2457,7 +2522,7 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2457
2522
  }
2458
2523
 
2459
2524
  // Copyright (c) Microsoft Corporation.
2460
- // Licensed under the MIT license.
2525
+ // Licensed under the MIT License.
2461
2526
  let instance$1 = null;
2462
2527
  /**
2463
2528
  * Long Interval Statsbeat Metrics
@@ -2570,7 +2635,7 @@ function getInstance$1(options) {
2570
2635
  }
2571
2636
 
2572
2637
  // Copyright (c) Microsoft Corporation.
2573
- // Licensed under the MIT license.
2638
+ // Licensed under the MIT License.
2574
2639
  /**
2575
2640
  * Breeze retriable status codes.
2576
2641
  * @internal
@@ -2605,7 +2670,7 @@ function msToTimeSpan(totalms) {
2605
2670
  }
2606
2671
 
2607
2672
  // Copyright (c) Microsoft Corporation.
2608
- // Licensed under the MIT license.
2673
+ // Licensed under the MIT License.
2609
2674
  const DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60000;
2610
2675
  /**
2611
2676
  * Base sender class
@@ -2703,6 +2768,7 @@ class BaseSender {
2703
2768
  }
2704
2769
  }
2705
2770
  else {
2771
+ // Handles all other status codes or client exceptions for Statsbeat
2706
2772
  this.incrementStatsbeatFailure();
2707
2773
  }
2708
2774
  return {
@@ -2735,15 +2801,24 @@ class BaseSender {
2735
2801
  return { code: core.ExportResultCode.FAILED, error: redirectError };
2736
2802
  }
2737
2803
  }
2738
- else if (restError.statusCode && isRetriable(restError.statusCode)) {
2804
+ else if (restError.statusCode &&
2805
+ isRetriable(restError.statusCode) &&
2806
+ !this.isStatsbeatSender) {
2739
2807
  (_g = this.networkStatsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
2740
2808
  return this.persist(envelopes);
2741
2809
  }
2742
2810
  else if (restError.statusCode === 400 &&
2743
2811
  restError.message.includes("Invalid instrumentation key")) {
2744
- const invalidInstrumentationKeyError = new Error("Invalid instrumentation key");
2812
+ // Invalid instrumentation key, shutdown statsbeat, fail silently
2745
2813
  this.shutdownStatsbeat();
2746
- return { code: core.ExportResultCode.FAILED, error: invalidInstrumentationKeyError };
2814
+ return { code: core.ExportResultCode.SUCCESS };
2815
+ }
2816
+ else if (restError.statusCode &&
2817
+ this.isStatsbeatSender &&
2818
+ isStatsbeatShutdownStatus(restError.statusCode)) {
2819
+ // If the status code is a shutdown status code for statsbeat, shutdown statsbeat and fail silently
2820
+ this.incrementStatsbeatFailure();
2821
+ return { code: core.ExportResultCode.SUCCESS };
2747
2822
  }
2748
2823
  if (this.isNetworkError(restError)) {
2749
2824
  if (restError.statusCode) {
@@ -2765,6 +2840,7 @@ class BaseSender {
2765
2840
  * Persist envelopes to disk
2766
2841
  */
2767
2842
  async persist(envelopes) {
2843
+ var _a;
2768
2844
  try {
2769
2845
  const success = await this.persister.push(envelopes);
2770
2846
  return success
@@ -2775,6 +2851,7 @@ class BaseSender {
2775
2851
  };
2776
2852
  }
2777
2853
  catch (ex) {
2854
+ (_a = this.networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countWriteFailure();
2778
2855
  return { code: core.ExportResultCode.FAILED, error: ex };
2779
2856
  }
2780
2857
  }
@@ -2798,6 +2875,7 @@ class BaseSender {
2798
2875
  this.statsbeatFailureCount = 0;
2799
2876
  }
2800
2877
  async sendFirstPersistedFile() {
2878
+ var _a;
2801
2879
  try {
2802
2880
  const envelopes = (await this.persister.shift());
2803
2881
  if (envelopes) {
@@ -2805,6 +2883,7 @@ class BaseSender {
2805
2883
  }
2806
2884
  }
2807
2885
  catch (err) {
2886
+ (_a = this.networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countReadFailure();
2808
2887
  api.diag.warn(`Failed to fetch persisted file`, err);
2809
2888
  }
2810
2889
  }
@@ -2817,7 +2896,7 @@ class BaseSender {
2817
2896
  }
2818
2897
 
2819
2898
  // Copyright (c) Microsoft Corporation.
2820
- // Licensed under the MIT license.
2899
+ // Licensed under the MIT License.
2821
2900
  const applicationInsightsResource = "https://monitor.azure.com//.default";
2822
2901
  /**
2823
2902
  * Exporter HTTP sender class
@@ -2878,7 +2957,7 @@ class HttpSender extends BaseSender {
2878
2957
  }
2879
2958
 
2880
2959
  // Copyright (c) Microsoft Corporation.
2881
- // Licensed under the MIT license.
2960
+ // Licensed under the MIT License.
2882
2961
  let instance = null;
2883
2962
  /**
2884
2963
  * Azure Telemetry context.
@@ -2921,7 +3000,7 @@ function getInstance() {
2921
3000
  }
2922
3001
 
2923
3002
  // Copyright (c) Microsoft Corporation.
2924
- // Licensed under the MIT license.
3003
+ // Licensed under the MIT License.
2925
3004
  function hrTimeToDate(hrTime) {
2926
3005
  return new Date(core.hrTimeToNanoseconds(hrTime) / 1000000);
2927
3006
  }
@@ -3121,13 +3200,40 @@ function createResourceMetricEnvelope(resource, instrumentationKey) {
3121
3200
  }
3122
3201
  return;
3123
3202
  }
3203
+ function serializeAttribute(value) {
3204
+ if (typeof value === "object") {
3205
+ if (value instanceof Error) {
3206
+ try {
3207
+ return JSON.stringify(value, Object.getOwnPropertyNames(value));
3208
+ }
3209
+ catch (err) {
3210
+ // Failed to serialize, return string cast
3211
+ return String(value);
3212
+ }
3213
+ }
3214
+ else if (value instanceof Uint8Array) {
3215
+ return String(value);
3216
+ }
3217
+ else {
3218
+ try {
3219
+ return JSON.stringify(value);
3220
+ }
3221
+ catch (err) {
3222
+ // Failed to serialize, return string cast
3223
+ return String(value);
3224
+ }
3225
+ }
3226
+ }
3227
+ // Return scalar and undefined values
3228
+ return String(value);
3229
+ }
3124
3230
  function shouldCreateResourceMetric() {
3125
3231
  var _a;
3126
3232
  return !(((_a = process.env.ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "true");
3127
3233
  }
3128
3234
 
3129
3235
  // Copyright (c) Microsoft Corporation.
3130
- // Licensed under the MIT license.
3236
+ // Licensed under the MIT License.
3131
3237
  /**
3132
3238
  * Azure SDK namespace.
3133
3239
  * @internal
@@ -3145,7 +3251,7 @@ const MicrosoftEventHub = "Microsoft.EventHub";
3145
3251
  const MessageBusDestination = "message_bus.destination";
3146
3252
 
3147
3253
  // Copyright (c) Microsoft Corporation.
3148
- // Licensed under the MIT license.
3254
+ // Licensed under the MIT License.
3149
3255
  /**
3150
3256
  * Average span.links[].attributes.enqueuedTime
3151
3257
  */
@@ -3192,7 +3298,7 @@ const parseEventHubSpan = (span, baseData) => {
3192
3298
  };
3193
3299
 
3194
3300
  // Copyright (c) Microsoft Corporation.
3195
- // Licensed under the MIT license.
3301
+ // Licensed under the MIT License.
3196
3302
  function createTagsFromSpan(span) {
3197
3303
  const tags = createTagsFromResource(span.resource);
3198
3304
  tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;
@@ -3221,8 +3327,8 @@ function createTagsFromSpan(span) {
3221
3327
  }
3222
3328
  else if (httpUrl) {
3223
3329
  try {
3224
- const url$1 = new url.URL(String(httpUrl));
3225
- tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url$1.pathname}`;
3330
+ const url = new URL(String(httpUrl));
3331
+ tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;
3226
3332
  }
3227
3333
  catch (_a) {
3228
3334
  /* no-op */
@@ -3270,7 +3376,7 @@ function createPropertiesFromSpanAttributes(attributes) {
3270
3376
  key === semanticConventions.SEMATTRS_EXCEPTION_TYPE ||
3271
3377
  key === semanticConventions.SEMATTRS_EXCEPTION_MESSAGE ||
3272
3378
  key === semanticConventions.SEMATTRS_EXCEPTION_STACKTRACE)) {
3273
- properties[key] = attributes[key];
3379
+ properties[key] = serializeAttribute(attributes[key]);
3274
3380
  }
3275
3381
  }
3276
3382
  }
@@ -3313,7 +3419,7 @@ function createDependencyData(span) {
3313
3419
  const httpUrl = span.attributes[semanticConventions.SEMATTRS_HTTP_URL];
3314
3420
  if (httpUrl) {
3315
3421
  try {
3316
- const dependencyUrl = new url.URL(String(httpUrl));
3422
+ const dependencyUrl = new URL(String(httpUrl));
3317
3423
  remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`;
3318
3424
  }
3319
3425
  catch (_b) {
@@ -3477,6 +3583,30 @@ function readableSpanToEnvelope(span, ikey) {
3477
3583
  parseEventHubSpan(span, baseData);
3478
3584
  }
3479
3585
  }
3586
+ // Truncate properties
3587
+ if (baseData.id) {
3588
+ baseData.id = baseData.id.substring(0, MaxPropertyLengths.NINE_BIT);
3589
+ }
3590
+ if (baseData.name) {
3591
+ baseData.name = baseData.name.substring(0, MaxPropertyLengths.TEN_BIT);
3592
+ }
3593
+ if (baseData.resultCode) {
3594
+ baseData.resultCode = String(baseData.resultCode).substring(0, MaxPropertyLengths.TEN_BIT);
3595
+ }
3596
+ if (baseData.data) {
3597
+ baseData.data = String(baseData.data).substring(0, MaxPropertyLengths.THIRTEEN_BIT);
3598
+ }
3599
+ if (baseData.type) {
3600
+ baseData.type = String(baseData.type).substring(0, MaxPropertyLengths.TEN_BIT);
3601
+ }
3602
+ if (baseData.target) {
3603
+ baseData.target = String(baseData.target).substring(0, MaxPropertyLengths.TEN_BIT);
3604
+ }
3605
+ if (baseData.properties) {
3606
+ for (const key of Object.keys(baseData.properties)) {
3607
+ baseData.properties[key] = baseData.properties[key].substring(0, MaxPropertyLengths.THIRTEEN_BIT);
3608
+ }
3609
+ }
3480
3610
  return {
3481
3611
  name,
3482
3612
  sampleRate,
@@ -3513,7 +3643,19 @@ function spanEventsToEnvelopes(span, ikey) {
3513
3643
  }
3514
3644
  // Only generate exception telemetry for incoming requests
3515
3645
  if (event.name === "exception") {
3516
- if (span.kind === api.SpanKind.SERVER) {
3646
+ let isValidParent = false;
3647
+ const parentSpanContext = span.parentSpanId
3648
+ ? span.spanContext()
3649
+ : undefined;
3650
+ if (parentSpanContext) {
3651
+ isValidParent =
3652
+ api.isValidTraceId(parentSpanContext.traceId) && api.isValidSpanId(parentSpanContext.spanId);
3653
+ }
3654
+ /*
3655
+ * Only generate exception telemetry for children of a remote span,
3656
+ * internal spans, and top level spans. This is to avoid unresolvable exceptions from outgoing calls.
3657
+ */
3658
+ if (!isValidParent || (parentSpanContext === null || parentSpanContext === void 0 ? void 0 : parentSpanContext.isRemote) || span.kind === api.SpanKind.INTERNAL) {
3517
3659
  name = "Microsoft.ApplicationInsights.Exception";
3518
3660
  baseType = "ExceptionData";
3519
3661
  let typeName = "";
@@ -3567,6 +3709,15 @@ function spanEventsToEnvelopes(span, ikey) {
3567
3709
  if (span.attributes[AzureMonitorSampleRate]) {
3568
3710
  sampleRate = Number(span.attributes[AzureMonitorSampleRate]);
3569
3711
  }
3712
+ // Truncate properties
3713
+ if (baseData.message) {
3714
+ baseData.message = String(baseData.message).substring(0, MaxPropertyLengths.FIFTEEN_BIT);
3715
+ }
3716
+ if (baseData.properties) {
3717
+ for (const key of Object.keys(baseData.properties)) {
3718
+ baseData.properties[key] = baseData.properties[key].substring(0, MaxPropertyLengths.THIRTEEN_BIT);
3719
+ }
3720
+ }
3570
3721
  const env = {
3571
3722
  name: name,
3572
3723
  time: time,
@@ -3586,7 +3737,7 @@ function spanEventsToEnvelopes(span, ikey) {
3586
3737
  }
3587
3738
 
3588
3739
  // Copyright (c) Microsoft Corporation.
3589
- // Licensed under the MIT license.
3740
+ // Licensed under the MIT License.
3590
3741
  /**
3591
3742
  * Azure Monitor OpenTelemetry Trace Exporter.
3592
3743
  */
@@ -3616,6 +3767,7 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
3616
3767
  * @param spans - Spans to export.
3617
3768
  * @param resultCallback - Result callback.
3618
3769
  */
3770
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
3619
3771
  async export(spans, resultCallback) {
3620
3772
  if (this.isShutdown) {
3621
3773
  api.diag.info("Exporter shut down. Failed to export spans.");
@@ -3652,7 +3804,7 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
3652
3804
  }
3653
3805
 
3654
3806
  // Copyright (c) Microsoft Corporation.
3655
- // Licensed under the MIT license.
3807
+ // Licensed under the MIT License.
3656
3808
  /**
3657
3809
  * Azure Monitor OpenTelemetry Metric Exporter.
3658
3810
  */
@@ -3681,6 +3833,7 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
3681
3833
  * @param metrics - Resource metrics to export.
3682
3834
  * @param resultCallback - Result callback.
3683
3835
  */
3836
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
3684
3837
  async export(metrics, resultCallback) {
3685
3838
  if (this._isShutdown) {
3686
3839
  api.diag.info("Exporter shut down. Failed to export spans.");
@@ -3721,7 +3874,7 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
3721
3874
  }
3722
3875
 
3723
3876
  // Copyright (c) Microsoft Corporation.
3724
- // Licensed under the MIT license.
3877
+ // Licensed under the MIT License.
3725
3878
  /**
3726
3879
  * Log to Azure envelope parsing.
3727
3880
  * @internal
@@ -3779,6 +3932,15 @@ function logToEnvelope(log, ikey) {
3779
3932
  return;
3780
3933
  }
3781
3934
  }
3935
+ // Truncate properties
3936
+ if (baseData.message) {
3937
+ baseData.message = String(baseData.message).substring(0, MaxPropertyLengths.FIFTEEN_BIT);
3938
+ }
3939
+ if (properties) {
3940
+ for (const key of Object.keys(properties)) {
3941
+ properties[key] = String(properties[key]).substring(0, MaxPropertyLengths.THIRTEEN_BIT);
3942
+ }
3943
+ }
3782
3944
  return {
3783
3945
  name,
3784
3946
  sampleRate,
@@ -3814,7 +3976,7 @@ function createPropertiesFromLog(log) {
3814
3976
  key === semanticConventions.SEMATTRS_EXCEPTION_TYPE ||
3815
3977
  key === semanticConventions.SEMATTRS_EXCEPTION_MESSAGE ||
3816
3978
  key === semanticConventions.SEMATTRS_EXCEPTION_STACKTRACE)) {
3817
- properties[key] = log.attributes[key];
3979
+ properties[key] = serializeAttribute(log.attributes[key]);
3818
3980
  }
3819
3981
  }
3820
3982
  }
@@ -3905,7 +4067,7 @@ function getLegacyApplicationInsightsBaseData(log) {
3905
4067
  }
3906
4068
 
3907
4069
  // Copyright (c) Microsoft Corporation.
3908
- // Licensed under the MIT license.
4070
+ // Licensed under the MIT License.
3909
4071
  /**
3910
4072
  * Azure Monitor OpenTelemetry Log Exporter.
3911
4073
  */
@@ -3934,6 +4096,7 @@ class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
3934
4096
  * @param logs - Logs to export.
3935
4097
  * @param resultCallback - Result callback.
3936
4098
  */
4099
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
3937
4100
  async export(logs, resultCallback) {
3938
4101
  if (this._isShutdown) {
3939
4102
  api.diag.info("Exporter shut down. Failed to export spans.");
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
2
+ // Licensed under the MIT License.
3
3
  /**
4
4
  * Azure service API version.
5
5
  */
@@ -44,7 +44,12 @@ export const ENV_INSTRUMENTATION_KEY = "APPINSIGHTS_INSTRUMENTATIONKEY";
44
44
  * Disable Statsbeat environment variable name.
45
45
  * @internal
46
46
  */
47
- export const ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT";
47
+ export const ENV_DISABLE_STATSBEAT = "APPLICATIONINSIGHTS_STATSBEAT_DISABLED";
48
+ /**
49
+ * Legacy disable Statsbeat environment variable name.
50
+ * @internal
51
+ */
52
+ export const LEGACY_ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT";
48
53
  /**
49
54
  * Disable OpenTelemetry Resource Metric.
50
55
  * @internal