@azure/monitor-opentelemetry-exporter 1.0.0-beta.19 → 1.0.0-beta.21

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 (44) hide show
  1. package/README.md +2 -0
  2. package/dist/index.js +58 -48
  3. package/dist-esm/src/export/base.js.map +1 -1
  4. package/dist-esm/src/export/log.js.map +1 -1
  5. package/dist-esm/src/export/metric.js.map +1 -1
  6. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +3 -3
  7. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
  8. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +2 -2
  9. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
  10. package/dist-esm/src/export/statsbeat/statsbeatExporter.js +1 -0
  11. package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
  12. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js +1 -1
  13. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js.map +1 -1
  14. package/dist-esm/src/export/trace.js.map +1 -1
  15. package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
  16. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  17. package/dist-esm/src/generated/models/index.js.map +1 -1
  18. package/dist-esm/src/platform/nodejs/baseSender.js +7 -2
  19. package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -1
  20. package/dist-esm/src/platform/nodejs/context/context.js +2 -4
  21. package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
  22. package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
  23. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +2 -2
  24. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
  25. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js +15 -8
  26. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js.map +1 -1
  27. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  28. package/dist-esm/src/sampling.js.map +1 -1
  29. package/dist-esm/src/utils/breezeUtils.js +12 -16
  30. package/dist-esm/src/utils/breezeUtils.js.map +1 -1
  31. package/dist-esm/src/utils/common.js +5 -1
  32. package/dist-esm/src/utils/common.js.map +1 -1
  33. package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
  34. package/dist-esm/src/utils/constants/applicationinsights.js +2 -2
  35. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  36. package/dist-esm/src/utils/eventhub.js.map +1 -1
  37. package/dist-esm/src/utils/logUtils.js +2 -3
  38. package/dist-esm/src/utils/logUtils.js.map +1 -1
  39. package/dist-esm/src/utils/metricUtils.js +1 -1
  40. package/dist-esm/src/utils/metricUtils.js.map +1 -1
  41. package/dist-esm/src/utils/spanUtils.js +7 -6
  42. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  43. package/package.json +21 -22
  44. package/types/monitor-opentelemetry-exporter.d.ts +3 -0
package/README.md CHANGED
@@ -16,6 +16,8 @@ This exporter package assumes your application is [already instrumented](https:/
16
16
 
17
17
  See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
18
18
 
19
+ > *Warning:* This SDK only works for Node.js environments. Use the [Application Insights JavaScript SDK](https://github.com/microsoft/ApplicationInsights-JS) for browser environments.
20
+
19
21
  ### Prerequisites
20
22
 
21
23
  - An [Azure subscription](https://azure.microsoft.com/free/)
package/dist/index.js CHANGED
@@ -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.19";
63
+ const packageVersion = "1.0.0-beta.21";
64
64
  var DependencyTypes;
65
65
  (function (DependencyTypes) {
66
66
  DependencyTypes["InProc"] = "InProc";
@@ -537,9 +537,9 @@ class FileAccessControl {
537
537
  return [
538
538
  directory,
539
539
  "/grant",
540
- "*S-1-5-32-544:(OI)(CI)F",
540
+ "*S-1-5-32-544:(OI)(CI)F", // Full permission for Administrators
541
541
  "/grant",
542
- `${identity}:(OI)(CI)F`,
542
+ `${identity}:(OI)(CI)F`, // Full permission for current user
543
543
  "/inheritance:r",
544
544
  ]; // Remove all inherited permissions
545
545
  }
@@ -563,17 +563,23 @@ const mkdirAsync = util.promisify(fs__namespace.mkdir);
563
563
  * @internal
564
564
  */
565
565
  const getShallowDirectorySize = async (directory) => {
566
- // Get the directory listing
567
- const files = await readdirAsync$1(directory);
568
566
  let totalSize = 0;
569
- // Query all file sizes
570
- for (const file of files) {
571
- const fileStats = await statAsync$1(path__namespace.join(directory, file));
572
- if (fileStats.isFile()) {
573
- totalSize += fileStats.size;
567
+ try {
568
+ // Get the directory listing
569
+ const files = await readdirAsync$1(directory);
570
+ // Query all file sizes
571
+ for (const file of files) {
572
+ const fileStats = await statAsync$1(path__namespace.join(directory, file));
573
+ if (fileStats.isFile()) {
574
+ totalSize += fileStats.size;
575
+ }
574
576
  }
577
+ return totalSize;
578
+ }
579
+ catch (err) {
580
+ api.diag.error(`Error getting directory size: ${err}`);
581
+ return 0;
575
582
  }
576
- return totalSize;
577
583
  };
578
584
  /**
579
585
  * Validate directory exists.
@@ -1808,7 +1814,7 @@ class ApplicationInsightsClient extends coreClient__namespace.ServiceClient {
1808
1814
  const defaults = {
1809
1815
  requestContentType: "application/json; charset=utf-8",
1810
1816
  };
1811
- const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.19`;
1817
+ const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.21`;
1812
1818
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1813
1819
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1814
1820
  : `${packageDetails}`;
@@ -1982,7 +1988,7 @@ class StatsbeatMetrics {
1982
1988
  const method = "GET";
1983
1989
  const options = {
1984
1990
  url: `${AIMS_URI}?${AIMS_API_VERSION}&${AIMS_FORMAT}`,
1985
- timeout: 5000,
1991
+ timeout: 5000, // 5 seconds
1986
1992
  method: method,
1987
1993
  allowInsecureConnection: true,
1988
1994
  };
@@ -2086,7 +2092,7 @@ function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
2086
2092
  const envelope = {
2087
2093
  name: envelopeName,
2088
2094
  time: time,
2089
- sampleRate: 100,
2095
+ sampleRate: 100, // Metrics are never sampled
2090
2096
  instrumentationKey: instrumentationKey,
2091
2097
  tags: tags,
2092
2098
  version: 1,
@@ -2123,6 +2129,7 @@ class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
2123
2129
  instrumentationKey: this.instrumentationKey,
2124
2130
  trackStatsbeat: this.trackStatsbeat,
2125
2131
  exporterOptions: options,
2132
+ isStatsbeatSender: true,
2126
2133
  });
2127
2134
  }
2128
2135
  /**
@@ -2190,8 +2197,8 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2190
2197
  this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
2191
2198
  this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
2192
2199
  this.commonProperties = {
2193
- os: super.os,
2194
- rp: super.resourceProvider,
2200
+ os: this.os,
2201
+ rp: this.resourceProvider,
2195
2202
  cikey: this.cikey,
2196
2203
  runtimeVersion: this.runtimeVersion,
2197
2204
  language: this.language,
@@ -2441,8 +2448,8 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
2441
2448
  this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(StatsbeatCounter.FEATURE);
2442
2449
  this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(StatsbeatCounter.ATTACH);
2443
2450
  this.commonProperties = {
2444
- os: super.os,
2445
- rp: super.resourceProvider,
2451
+ os: this.os,
2452
+ rp: this.resourceProvider,
2446
2453
  cikey: this.cikey,
2447
2454
  runtimeVersion: this.runtimeVersion,
2448
2455
  language: this.language,
@@ -2450,7 +2457,7 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
2450
2457
  attach: this.attach,
2451
2458
  };
2452
2459
  this.attachProperties = {
2453
- rpId: super.resourceIdentifier,
2460
+ rpId: this.resourceIdentifier,
2454
2461
  };
2455
2462
  this.isInitialized = true;
2456
2463
  this.initialize();
@@ -2523,24 +2530,20 @@ function isRetriable(statusCode) {
2523
2530
  statusCode === 504 // Gateway Timeout
2524
2531
  );
2525
2532
  }
2526
- /**
2527
- * Convert milliseconds to Breeze expected time.
2528
- * @internal
2529
- */
2530
- function msToTimeSpan(ms) {
2531
- let totalms = ms;
2532
- if (Number.isNaN(totalms) || totalms < 0 || !Number.isFinite(ms)) {
2533
+ // Convert ms to c# time span format DD.HH:MM:SS.MMMMMM
2534
+ function msToTimeSpan(totalms) {
2535
+ if (isNaN(totalms) || totalms < 0) {
2533
2536
  totalms = 0;
2534
2537
  }
2535
- let sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, "");
2536
- let min = `${Math.floor(totalms / (1000 * 60)) % 60}`;
2537
- let hour = `${Math.floor(totalms / (1000 * 60 * 60)) % 24}`;
2538
- const days = Math.floor(totalms / (1000 * 60 * 60 * 24));
2539
- sec = sec.indexOf(".") < 2 ? `0${sec}` : sec;
2540
- min = min.length < 2 ? `0${min}` : min;
2541
- hour = hour.length < 2 ? `0${hour}` : hour;
2542
- const daysText = days > 0 ? `${days}.` : "";
2543
- return `${daysText + hour}:${min}:${sec}`;
2538
+ var sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, "");
2539
+ var min = "" + (Math.floor(totalms / (1000 * 60)) % 60);
2540
+ var hour = "" + (Math.floor(totalms / (1000 * 60 * 60)) % 24);
2541
+ var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
2542
+ sec = sec.indexOf(".") < 2 ? "0" + sec : sec;
2543
+ min = min.length < 2 ? "0" + min : min;
2544
+ hour = hour.length < 2 ? "0" + hour : hour;
2545
+ var daysText = days > 0 ? days + "." : "";
2546
+ return daysText + hour + ":" + min + ":" + sec;
2544
2547
  }
2545
2548
 
2546
2549
  // Copyright (c) Microsoft Corporation.
@@ -2568,6 +2571,7 @@ class BaseSender {
2568
2571
  });
2569
2572
  }
2570
2573
  this.retryTimer = null;
2574
+ this.isStatsbeatSender = options.isStatsbeatSender || false;
2571
2575
  }
2572
2576
  /**
2573
2577
  * Export envelopes
@@ -2684,11 +2688,15 @@ class BaseSender {
2684
2688
  if (restError.statusCode) {
2685
2689
  (_h = this.networkStatsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
2686
2690
  }
2687
- api.diag.error("Retrying due to transient client side error. Error message:", restError.message);
2691
+ if (!this.isStatsbeatSender) {
2692
+ api.diag.error("Retrying due to transient client side error. Error message:", restError.message);
2693
+ }
2688
2694
  return this.persist(envelopes);
2689
2695
  }
2690
2696
  (_j = this.networkStatsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
2691
- api.diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
2697
+ if (!this.isStatsbeatSender) {
2698
+ api.diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
2699
+ }
2692
2700
  return { code: core.ExportResultCode.FAILED, error: restError };
2693
2701
  }
2694
2702
  }
@@ -2828,11 +2836,9 @@ class Context {
2828
2836
  [Context.nodeVersion] = node.split(".");
2829
2837
  Context.opentelemetryVersion = core.SDK_INFO[semanticConventions.SemanticResourceAttributes.TELEMETRY_SDK_VERSION];
2830
2838
  Context.sdkVersion = packageVersion;
2831
- const prefix = process.env["AZURE_MONITOR_AGENT_PREFIX"]
2832
- ? process.env["AZURE_MONITOR_AGENT_PREFIX"]
2833
- : "";
2839
+ const prefix = process.env["AZURE_MONITOR_PREFIX"] ? process.env["AZURE_MONITOR_PREFIX"] : "";
2834
2840
  const version = process.env["AZURE_MONITOR_DISTRO_VERSION"]
2835
- ? `dst${process.env["AZURE_MONITOR_DISTRO_VERSION"]}`
2841
+ ? `ext${process.env["AZURE_MONITOR_DISTRO_VERSION"]}`
2836
2842
  : `ext${Context.sdkVersion}`;
2837
2843
  const internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;
2838
2844
  this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;
@@ -2854,6 +2860,9 @@ function getInstance() {
2854
2860
 
2855
2861
  // Copyright (c) Microsoft Corporation.
2856
2862
  // Licensed under the MIT license.
2863
+ function hrTimeToDate(hrTime) {
2864
+ return new Date(core.hrTimeToNanoseconds(hrTime) / 1000000);
2865
+ }
2857
2866
  function createTagsFromResource(resource) {
2858
2867
  const context = getInstance();
2859
2868
  const tags = Object.assign({}, context.tags);
@@ -3031,7 +3040,7 @@ function createResourceMetricEnvelope(resource, instrumentationKey) {
3031
3040
  const envelope = {
3032
3041
  name: "Microsoft.ApplicationInsights.Metric",
3033
3042
  time: new Date(),
3034
- sampleRate: 100,
3043
+ sampleRate: 100, // Metrics are never sampled
3035
3044
  instrumentationKey: instrumentationKey,
3036
3045
  version: 1,
3037
3046
  data: {
@@ -3199,10 +3208,11 @@ function createPropertiesFromSpan(span) {
3199
3208
  return [properties, measurements];
3200
3209
  }
3201
3210
  function createDependencyData(span) {
3211
+ var _a;
3202
3212
  const remoteDependencyData = {
3203
- name: span.name,
3213
+ name: span.name, // Default
3204
3214
  id: `${span.spanContext().spanId}`,
3205
- success: span.status.code !== api.SpanStatusCode.ERROR,
3215
+ success: ((_a = span.status) === null || _a === void 0 ? void 0 : _a.code) !== api.SpanStatusCode.ERROR,
3206
3216
  resultCode: "0",
3207
3217
  type: "Dependency",
3208
3218
  duration: msToTimeSpan(core.hrTimeToMilliseconds(span.duration)),
@@ -3344,7 +3354,7 @@ function readableSpanToEnvelope(span, ikey) {
3344
3354
  let name;
3345
3355
  let baseType;
3346
3356
  let baseData;
3347
- const time = new Date(core.hrTimeToMilliseconds(span.startTime));
3357
+ const time = hrTimeToDate(span.startTime);
3348
3358
  const instrumentationKey = ikey;
3349
3359
  const tags = createTagsFromSpan(span);
3350
3360
  const [properties, measurements] = createPropertiesFromSpan(span);
@@ -3405,7 +3415,7 @@ function spanEventsToEnvelopes(span, ikey) {
3405
3415
  span.events.forEach((event) => {
3406
3416
  var _a;
3407
3417
  let baseType;
3408
- const time = new Date(core.hrTimeToMilliseconds(event.time));
3418
+ const time = hrTimeToDate(event.time);
3409
3419
  let name = "";
3410
3420
  let baseData;
3411
3421
  const properties = createPropertiesFromSpanAttributes(event.attributes);
@@ -3624,7 +3634,7 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
3624
3634
  * @internal
3625
3635
  */
3626
3636
  function logToEnvelope(log, ikey) {
3627
- const time = log.hrTime ? new Date(core.hrTimeToMilliseconds(log.hrTime)) : new Date();
3637
+ const time = hrTimeToDate(log.hrTime);
3628
3638
  const sampleRate = 100;
3629
3639
  const instrumentationKey = ikey;
3630
3640
  const tags = createTagsFromLog(log);
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/export/base.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAgB,wBAAwB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AI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;SAC1B;QACD,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,mBAAmB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAEvF,IAAI,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport {\n DEFAULT_BREEZE_ENDPOINT,\n ENV_CONNECTION_STRING,\n ENV_DISABLE_STATSBEAT,\n} from \"../Declarations/Constants\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport abstract class AzureMonitorBaseExporter {\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected instrumentationKey: string = \"\";\n /**\n * Ingestion Endpoint URL\n */\n protected endpointUrl: string = \"\";\n /**\n *Flag to determine if exporter will generate Statsbeat data\n */\n protected trackStatsbeat: boolean = false;\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected aadAudience: string | undefined;\n private isStatsbeatExporter: boolean;\n\n /**\n * Exporter internal configuration\n */\n private readonly options: AzureMonitorExporterOptions;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureMonitorExporterOptions - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {\n this.options = options;\n this.instrumentationKey = \"\";\n this.endpointUrl = DEFAULT_BREEZE_ENDPOINT;\n const connectionString = this.options.connectionString || process.env[ENV_CONNECTION_STRING];\n this.isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this.instrumentationKey =\n parsedConnectionString.instrumentationkey || this.instrumentationKey;\n this.endpointUrl = parsedConnectionString.ingestionendpoint?.trim() || this.endpointUrl;\n this.aadAudience = parsedConnectionString.aadaudience;\n }\n\n // Instrumentation key is required\n if (!this.instrumentationKey) {\n const message =\n \"No instrumentation key or connection string was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n if (!ConnectionStringParser.validateInstrumentationKey(this.instrumentationKey)) {\n const message = \"Invalid instrumentation key was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n this.trackStatsbeat = !this.isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];\n\n diag.debug(\"AzureMonitorExporter was successfully setup\");\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/export/base.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAgB,wBAAwB;IA4B5C;;;OAGG;IACH,YAAY,UAAuC,EAAE,EAAE,mBAA6B;;QA/BpF;;WAEG;QACO,uBAAkB,GAAW,EAAE,CAAC;QAC1C;;WAEG;QACO,gBAAW,GAAW,EAAE,CAAC;QACnC;;WAEG;QACO,mBAAc,GAAY,KAAK,CAAC;QAqBxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,uBAAuB,CAAC;QAC3C,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC7F,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC;QAE7E,IAAI,gBAAgB,EAAE,CAAC;YACrB,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAC9E,IAAI,CAAC,kBAAkB;gBACrB,sBAAsB,CAAC,kBAAkB,IAAI,IAAI,CAAC,kBAAkB,CAAC;YACvE,IAAI,CAAC,WAAW,GAAG,CAAA,MAAA,sBAAsB,CAAC,iBAAiB,0CAAE,IAAI,EAAE,KAAI,IAAI,CAAC,WAAW,CAAC;YACxF,IAAI,CAAC,WAAW,GAAG,sBAAsB,CAAC,WAAW,CAAC;QACxD,CAAC;QAED,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC7B,MAAM,OAAO,GACX,wFAAwF,CAAC;YAC3F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAChF,MAAM,OAAO,GAAG,wEAAwE,CAAC;YACzF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,mBAAmB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAEvF,IAAI,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport {\n DEFAULT_BREEZE_ENDPOINT,\n ENV_CONNECTION_STRING,\n ENV_DISABLE_STATSBEAT,\n} from \"../Declarations/Constants\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport abstract class AzureMonitorBaseExporter {\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected instrumentationKey: string = \"\";\n /**\n * Ingestion Endpoint URL\n */\n protected endpointUrl: string = \"\";\n /**\n *Flag to determine if exporter will generate Statsbeat data\n */\n protected trackStatsbeat: boolean = false;\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected aadAudience: string | undefined;\n\n /**\n * Flag to determine if the Exporter is a Statsbeat Exporter\n */\n private isStatsbeatExporter: boolean;\n\n /**\n * Exporter internal configuration\n */\n private readonly options: AzureMonitorExporterOptions;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureMonitorExporterOptions - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {\n this.options = options;\n this.instrumentationKey = \"\";\n this.endpointUrl = DEFAULT_BREEZE_ENDPOINT;\n const connectionString = this.options.connectionString || process.env[ENV_CONNECTION_STRING];\n this.isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this.instrumentationKey =\n parsedConnectionString.instrumentationkey || this.instrumentationKey;\n this.endpointUrl = parsedConnectionString.ingestionendpoint?.trim() || this.endpointUrl;\n this.aadAudience = parsedConnectionString.aadaudience;\n }\n\n // Instrumentation key is required\n if (!this.instrumentationKey) {\n const message =\n \"No instrumentation key or connection string was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n if (!ConnectionStringParser.validateInstrumentationKey(this.instrumentationKey)) {\n const message = \"Invalid instrumentation key was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n this.trackStatsbeat = !this.isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];\n\n diag.debug(\"AzureMonitorExporter was successfully setup\");\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/export/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,wBAAwB;IAOnE;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAZjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,OAAO;YACxB,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CACjB,IAAyB,EACzB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;YACzD,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;SACR;QACD,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,MAAM,sCAAsC,CAAC,CAAC;QAE1E,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC7D,IAAI,QAAQ,EAAE;gBACZ,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;QACH,0DAA0D;QAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YAC/D,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { logToEnvelope } from \"../utils/logUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\n\nimport type { ReadableLogRecord, LogRecordExporter } from \"@opentelemetry/sdk-logs\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Log Exporter.\n */\nexport class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements LogRecordExporter {\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private readonly _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorLogExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n aadAudience: this.aadAudience,\n });\n diag.debug(\"AzureMonitorLogExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry logs.\n * @param logs - Logs to export.\n * @param resultCallback - Result callback.\n */\n public async export(\n logs: ReadableLogRecord[],\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = [];\n logs.forEach((log) => {\n const envelope = logToEnvelope(log, this.instrumentationKey);\n if (envelope) {\n envelopes.push(envelope);\n }\n });\n // Supress tracing until OpenTelemetry Logs SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorLogExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorLogExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/export/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,aAAa,EAA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AA0D;QAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YAC/D,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { logToEnvelope } from \"../utils/logUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\n\nimport type { ReadableLogRecord, LogRecordExporter } from \"@opentelemetry/sdk-logs\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Log Exporter.\n */\nexport class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements LogRecordExporter {\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private readonly _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorLogExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n aadAudience: this.aadAudience,\n });\n diag.debug(\"AzureMonitorLogExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry logs.\n * @param logs - Logs to export.\n * @param resultCallback - Result callback.\n */\n public async export(\n logs: ReadableLogRecord[],\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = [];\n logs.forEach((log) => {\n const envelope = logToEnvelope(log, this.instrumentationKey);\n if (envelope) {\n envelopes.push(envelope);\n }\n });\n // Supress tracing until OpenTelemetry Logs SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorLogExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorLogExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,cAAc,GAGf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,0BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAZjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,OAAO,GAA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K,cAAc,CAAC,eAAe;YACjD,cAAc,KAAK,cAAc,CAAC,0BAA0B,EAC5D;YACA,OAAO,sBAAsB,CAAC,UAAU,CAAC;SAC1C;QACD,OAAO,sBAAsB,CAAC,KAAK,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport {\n AggregationTemporality,\n InstrumentType,\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { resourceMetricsToEnvelope } from \"../utils/metricUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Exporter.\n */\nexport class AzureMonitorMetricExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorMetricExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n aadAudience: this.aadAudience,\n });\n diag.debug(\"AzureMonitorMetricExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry resource metrics.\n * @param metrics - Resource metrics to export.\n * @param resultCallback - Result callback.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);\n // Supress tracing until OpenTelemetry Metrics SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorMetricExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorMetricExporter shutting down\");\n return this._sender.shutdown();\n }\n\n /**\n * Select aggregation temporality\n */\n public selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {\n if (\n instrumentType === InstrumentType.UP_DOWN_COUNTER ||\n instrumentType === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER\n ) {\n return AggregationTemporality.CUMULATIVE;\n }\n return AggregationTemporality.DELTA;\n }\n\n /**\n * Force flush\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
1
+ {"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,cAAc,GAGf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,0BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK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I,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,4BAA4B,CAAC,cAA8B;QAChE,IACE,cAAc,KAAK,cAAc,CAAC,eAAe;YACjD,cAAc,KAAK,cAAc,CAAC,0BAA0B,EAC5D,CAAC;YACD,OAAO,sBAAsB,CAAC,UAAU,CAAC;QAC3C,CAAC;QACD,OAAO,sBAAsB,CAAC,KAAK,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport {\n AggregationTemporality,\n InstrumentType,\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { resourceMetricsToEnvelope } from \"../utils/metricUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Exporter.\n */\nexport class AzureMonitorMetricExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorMetricExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n aadAudience: this.aadAudience,\n });\n diag.debug(\"AzureMonitorMetricExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry resource metrics.\n * @param metrics - Resource metrics to export.\n * @param resultCallback - Result callback.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);\n // Supress tracing until OpenTelemetry Metrics SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorMetricExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorMetricExporter shutting down\");\n return this._sender.shutdown();\n }\n\n /**\n * Select aggregation temporality\n */\n public selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {\n if (\n instrumentType === InstrumentType.UP_DOWN_COUNTER ||\n instrumentType === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER\n ) {\n return AggregationTemporality.CUMULATIVE;\n }\n return AggregationTemporality.DELTA;\n }\n\n /**\n * Force flush\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
@@ -52,8 +52,8 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
52
52
  this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(StatsbeatCounter.FEATURE);
53
53
  this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(StatsbeatCounter.ATTACH);
54
54
  this.commonProperties = {
55
- os: super.os,
56
- rp: super.resourceProvider,
55
+ os: this.os,
56
+ rp: this.resourceProvider,
57
57
  cikey: this.cikey,
58
58
  runtimeVersion: this.runtimeVersion,
59
59
  language: this.language,
@@ -61,7 +61,7 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
61
61
  attach: this.attach,
62
62
  };
63
63
  this.attachProperties = {
64
- rpId: super.resourceIdentifier,
64
+ rpId: this.resourceIdentifier,
65
65
  };
66
66
  this.isInitialized = true;
67
67
  this.initialize();
@@ -1 +1 @@
1
- {"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAGlB,oBAAoB,GAErB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,IAAI,QAAQ,GAAwC,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,4BAA6B,SAAQ,gBAAgB;IA8BzD,YAAY,OAAyB;QACnC,KAAK,EAAE,CAAC;QA9BF,qCAAgC,GAAG,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC;QAChF,gCAA2B,GAAW,QAAQ,CAAC,CAAC,QAAQ;QAMxD,WAAM,GAAW,QAAQ,CAAC;QAK1B,YAAO,GAAW,CAAC,CAAC;QACpB,oBAAe,GAAW,CAAC,CAAC;QAc7B,kBAAa,GAAY,KAAK,CAAC;QAIpC,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvE,MAAM,cAAc,GAAgC;YAClD,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;SACxC,CAAC;QAEF,IAAI,IAAI,CAAC,gCAAg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servableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n if (this.AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this.feature = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this.instrumentation = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n\n this.commonProperties = {\n os: super.os,\n rp: super.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: super.resourceIdentifier,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n private async initialize() {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.featureCallback.bind(this), [\n this.featureStatsbeatGauge,\n ]);\n\n // Export Feature/Attach Statsbeat once upon app initialization\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n },\n );\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private featureCallback(observableResult: BatchObservableResult) {\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private attachCallback(observableResult: ObservableResult) {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
1
+ {"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;A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E,CAAC,oBAAO,UAAU,EAAG,CAAC;QAC7E,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,UAAU,mCACL,IAAI,CAAC,gBAAgB,KACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,IAAI,EAAE,oBAAoB,CAAC,OAAO,GACnC,CAAC;YACF,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,oBAAO,UAAU,EAAG,CAAC;QAC7E,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,gBAAkC;QACvD,MAAM,UAAU,mCAAQ,IAAI,CAAC,gBAAgB,GAAK,IAAI,CAAC,gBAAgB,CAAE,CAAC;QAC1E,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,CAAC;IAC5D,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n if (this.AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this.feature = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this.instrumentation = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n\n this.commonProperties = {\n os: this.os,\n rp: this.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: this.resourceIdentifier,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n private async initialize() {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.featureCallback.bind(this), [\n this.featureStatsbeatGauge,\n ]);\n\n // Export Feature/Attach Statsbeat once upon app initialization\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n },\n );\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private featureCallback(observableResult: BatchObservableResult) {\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private attachCallback(observableResult: ObservableResult) {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
@@ -40,8 +40,8 @@ export class NetworkStatsbeatMetrics extends StatsbeatMetrics {
40
40
  this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
41
41
  this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
42
42
  this.commonProperties = {
43
- os: super.os,
44
- rp: super.resourceProvider,
43
+ os: this.os,
44
+ rp: this.resourceProvider,
45
45
  cikey: this.cikey,
46
46
  runtimeVersion: this.runtimeVersion,
47
47
  language: this.language,
@@ -1 +1 @@
1
- {"version":3,"file":"networkStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAC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AAC,CAAC;YACzC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;gBAClC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;aACpB;YACD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;SAClD;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n Meter,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n NetworkStatsbeat,\n CommonStatsbeatProperties,\n NetworkStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nexport class NetworkStatsbeatMetrics extends StatsbeatMetrics {\n private commonProperties: CommonStatsbeatProperties;\n private networkProperties: NetworkStatsbeatProperties;\n private isInitialized: boolean = false;\n private statsCollectionShortInterval: number = 900000; // 15 minutes\n\n private networkStatsbeatCollection: Array<NetworkStatsbeat> = [];\n private networkStatsbeatMeter: Meter;\n private networkStatsbeatMeterProvider: MeterProvider;\n private networkAzureExporter: AzureMonitorStatsbeatExporter;\n private networkMetricReader: PeriodicExportingMetricReader;\n\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n // Observable Gauges\n private successCountGauge: ObservableGauge;\n private failureCountGauge: ObservableGauge;\n private retryCountGauge: ObservableGauge;\n private throttleCountGauge: ObservableGauge;\n private exceptionCountGauge: ObservableGauge;\n private averageDurationGauge: ObservableGauge;\n\n // Network attributes\n private connectionString: string;\n private endpointUrl: string;\n private host: string;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n this.networkStatsbeatMeterProvider = new MeterProvider();\n\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n this.networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Exports Network Statsbeat every 15 minutes\n const networkMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.networkAzureExporter,\n exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionShortInterval, // 15 minutes\n };\n\n this.networkMetricReader = new PeriodicExportingMetricReader(networkMetricReaderOptions);\n this.networkStatsbeatMeterProvider.addMetricReader(this.networkMetricReader);\n this.networkStatsbeatMeter = this.networkStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Network Statsbeat\",\n );\n\n this.endpointUrl = options.endpointUrl;\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.host = this.getShortHost(options.endpointUrl);\n this.cikey = options.instrumentationKey;\n\n this.successCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.SUCCESS_COUNT,\n );\n this.failureCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FAILURE_COUNT,\n );\n this.retryCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.RETRY_COUNT,\n );\n this.throttleCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.THROTTLE_COUNT,\n );\n this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.EXCEPTION_COUNT,\n );\n this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.AVERAGE_DURATION,\n );\n\n this.commonProperties = {\n os: super.os,\n rp: super.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.networkProperties = {\n endpoint: this.endpointUrl,\n host: this.host,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n public shutdown(): Promise<void> {\n return this.networkStatsbeatMeterProvider.shutdown();\n }\n\n private async initialize(): Promise<void> {\n try {\n await super.getResourceProvider();\n\n // Add network observable callbacks\n this.successCountGauge.addCallback(this.successCallback.bind(this));\n this.networkStatsbeatMeter.addBatchObservableCallback(this.failureCallback.bind(this), [\n this.failureCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.retryCallback.bind(this), [\n this.retryCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.throttleCallback.bind(this), [\n this.throttleCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.exceptionCallback.bind(this), [\n this.exceptionCountGauge,\n ]);\n this.averageDurationGauge.addCallback(this.durationCallback.bind(this));\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n // Observable gauge callbacks\n private successCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.commonProperties, ...this.networkProperties };\n observableResult.observe(counter.totalSuccesfulRequestCount, attributes);\n counter.totalSuccesfulRequestCount = 0;\n }\n\n private failureCallback(observableResult: BatchObservableResult) {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n\n /*\n Takes the failureCountGauge, value (of the counter), and attributes\n create a unqiue counter based on statusCode as well\n append statusCode to attributes so the newly created attributes are unique.\n */\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n // For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode\n for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {\n attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;\n observableResult.observe(this.failureCountGauge, counter.totalFailedRequestCount[i].count, {\n ...attributes,\n });\n counter.totalFailedRequestCount[i].count = 0;\n }\n }\n\n private retryCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.retryCount.length; i++) {\n attributes.statusCode = counter.retryCount[i].statusCode;\n observableResult.observe(this.retryCountGauge, counter.retryCount[i].count, {\n ...attributes,\n });\n counter.retryCount[i].count = 0;\n }\n }\n\n private throttleCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.throttleCount.length; i++) {\n attributes.statusCode = counter.throttleCount[i].statusCode;\n observableResult.observe(this.throttleCountGauge, counter.throttleCount[i].count, {\n ...attributes,\n });\n counter.throttleCount[i].count = 0;\n }\n }\n\n private exceptionCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, exceptionType: \"\" };\n\n for (let i = 0; i < counter.exceptionCount.length; i++) {\n attributes.exceptionType = counter.exceptionCount[i].exceptionType;\n observableResult.observe(this.exceptionCountGauge, counter.exceptionCount[i].count, {\n ...attributes,\n });\n counter.exceptionCount[i].count = 0;\n }\n }\n\n private durationCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties };\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n const currentCounter = this.networkStatsbeatCollection[i];\n currentCounter.time = Number(new Date());\n const intervalRequests =\n currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;\n currentCounter.averageRequestExecutionTime =\n (currentCounter.intervalRequestExecutionTime -\n currentCounter.lastIntervalRequestExecutionTime) /\n intervalRequests || 0;\n currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset\n\n currentCounter.lastRequestCount = currentCounter.totalRequestCount;\n currentCounter.lastTime = currentCounter.time;\n }\n observableResult.observe(counter.averageRequestExecutionTime, attributes);\n\n counter.averageRequestExecutionTime = 0;\n }\n\n // Public methods to increase counters\n public countSuccess(duration: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n counter.totalRequestCount++;\n counter.totalSuccesfulRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countFailure(duration: number, statusCode: number) {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.totalFailedRequestCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.totalFailedRequestCount.push({ statusCode: statusCode, count: 1 });\n }\n\n counter.totalRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countRetry(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.retryCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.retryCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countThrottle(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.throttleCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.throttleCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countException(exceptionType: Error): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentErrorCounter = counter.exceptionCount.find(\n (exceptionCounter) => exceptionType.name === exceptionCounter.exceptionType,\n );\n if (currentErrorCounter) {\n currentErrorCounter.count++;\n } else {\n counter.exceptionCount.push({ exceptionType: exceptionType.name, count: 1 });\n }\n }\n\n // Gets a networkStatsbeat counter if one exists for the given endpoint\n private getNetworkStatsbeatCounter(endpoint: string, host: string): NetworkStatsbeat {\n // Check if the counter is available\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n // Same object\n if (\n endpoint === this.networkStatsbeatCollection[i].endpoint &&\n host === this.networkStatsbeatCollection[i].host\n ) {\n return this.networkStatsbeatCollection[i];\n }\n }\n // Create a new counter if not found\n const newCounter = new NetworkStatsbeat(endpoint, host);\n this.networkStatsbeatCollection.push(newCounter);\n return newCounter;\n }\n\n private getShortHost(originalHost: string): string {\n let shortHost = originalHost;\n try {\n const hostRegex = new RegExp(/^https?:\\/\\/(?:www\\.)?([^\\/.-]+)/);\n const res = hostRegex.exec(originalHost);\n if (res !== null && res.length > 1) {\n shortHost = res[1];\n }\n shortHost = shortHost.replace(\".in.applicationinsights.azure.com\", \"\");\n } catch (error) {\n diag.debug(\"Failed to get the short host name.\");\n }\n return shortHost;\n }\n}\n"]}
1
+ {"version":3,"file":"networkStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,K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AM,UAAU,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxD,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,YAAY,CAAC,YAAoB;QACvC,IAAI,SAAS,GAAG,YAAY,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,kCAAkC,CAAC,CAAC;YACjE,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACzC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YACrB,CAAC;YACD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;QACzE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n Meter,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n NetworkStatsbeat,\n CommonStatsbeatProperties,\n NetworkStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nexport class NetworkStatsbeatMetrics extends StatsbeatMetrics {\n private commonProperties: CommonStatsbeatProperties;\n private networkProperties: NetworkStatsbeatProperties;\n private isInitialized: boolean = false;\n private statsCollectionShortInterval: number = 900000; // 15 minutes\n\n private networkStatsbeatCollection: Array<NetworkStatsbeat> = [];\n private networkStatsbeatMeter: Meter;\n private networkStatsbeatMeterProvider: MeterProvider;\n private networkAzureExporter: AzureMonitorStatsbeatExporter;\n private networkMetricReader: PeriodicExportingMetricReader;\n\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n // Observable Gauges\n private successCountGauge: ObservableGauge;\n private failureCountGauge: ObservableGauge;\n private retryCountGauge: ObservableGauge;\n private throttleCountGauge: ObservableGauge;\n private exceptionCountGauge: ObservableGauge;\n private averageDurationGauge: ObservableGauge;\n\n // Network attributes\n private connectionString: string;\n private endpointUrl: string;\n private host: string;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n this.networkStatsbeatMeterProvider = new MeterProvider();\n\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n this.networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Exports Network Statsbeat every 15 minutes\n const networkMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.networkAzureExporter,\n exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionShortInterval, // 15 minutes\n };\n\n this.networkMetricReader = new PeriodicExportingMetricReader(networkMetricReaderOptions);\n this.networkStatsbeatMeterProvider.addMetricReader(this.networkMetricReader);\n this.networkStatsbeatMeter = this.networkStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Network Statsbeat\",\n );\n\n this.endpointUrl = options.endpointUrl;\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.host = this.getShortHost(options.endpointUrl);\n this.cikey = options.instrumentationKey;\n\n this.successCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.SUCCESS_COUNT,\n );\n this.failureCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FAILURE_COUNT,\n );\n this.retryCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.RETRY_COUNT,\n );\n this.throttleCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.THROTTLE_COUNT,\n );\n this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.EXCEPTION_COUNT,\n );\n this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.AVERAGE_DURATION,\n );\n\n this.commonProperties = {\n os: this.os,\n rp: this.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.networkProperties = {\n endpoint: this.endpointUrl,\n host: this.host,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n public shutdown(): Promise<void> {\n return this.networkStatsbeatMeterProvider.shutdown();\n }\n\n private async initialize(): Promise<void> {\n try {\n await super.getResourceProvider();\n\n // Add network observable callbacks\n this.successCountGauge.addCallback(this.successCallback.bind(this));\n this.networkStatsbeatMeter.addBatchObservableCallback(this.failureCallback.bind(this), [\n this.failureCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.retryCallback.bind(this), [\n this.retryCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.throttleCallback.bind(this), [\n this.throttleCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.exceptionCallback.bind(this), [\n this.exceptionCountGauge,\n ]);\n this.averageDurationGauge.addCallback(this.durationCallback.bind(this));\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n // Observable gauge callbacks\n private successCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.commonProperties, ...this.networkProperties };\n observableResult.observe(counter.totalSuccesfulRequestCount, attributes);\n counter.totalSuccesfulRequestCount = 0;\n }\n\n private failureCallback(observableResult: BatchObservableResult) {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n\n /*\n Takes the failureCountGauge, value (of the counter), and attributes\n create a unqiue counter based on statusCode as well\n append statusCode to attributes so the newly created attributes are unique.\n */\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n // For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode\n for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {\n attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;\n observableResult.observe(this.failureCountGauge, counter.totalFailedRequestCount[i].count, {\n ...attributes,\n });\n counter.totalFailedRequestCount[i].count = 0;\n }\n }\n\n private retryCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.retryCount.length; i++) {\n attributes.statusCode = counter.retryCount[i].statusCode;\n observableResult.observe(this.retryCountGauge, counter.retryCount[i].count, {\n ...attributes,\n });\n counter.retryCount[i].count = 0;\n }\n }\n\n private throttleCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.throttleCount.length; i++) {\n attributes.statusCode = counter.throttleCount[i].statusCode;\n observableResult.observe(this.throttleCountGauge, counter.throttleCount[i].count, {\n ...attributes,\n });\n counter.throttleCount[i].count = 0;\n }\n }\n\n private exceptionCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, exceptionType: \"\" };\n\n for (let i = 0; i < counter.exceptionCount.length; i++) {\n attributes.exceptionType = counter.exceptionCount[i].exceptionType;\n observableResult.observe(this.exceptionCountGauge, counter.exceptionCount[i].count, {\n ...attributes,\n });\n counter.exceptionCount[i].count = 0;\n }\n }\n\n private durationCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties };\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n const currentCounter = this.networkStatsbeatCollection[i];\n currentCounter.time = Number(new Date());\n const intervalRequests =\n currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;\n currentCounter.averageRequestExecutionTime =\n (currentCounter.intervalRequestExecutionTime -\n currentCounter.lastIntervalRequestExecutionTime) /\n intervalRequests || 0;\n currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset\n\n currentCounter.lastRequestCount = currentCounter.totalRequestCount;\n currentCounter.lastTime = currentCounter.time;\n }\n observableResult.observe(counter.averageRequestExecutionTime, attributes);\n\n counter.averageRequestExecutionTime = 0;\n }\n\n // Public methods to increase counters\n public countSuccess(duration: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n counter.totalRequestCount++;\n counter.totalSuccesfulRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countFailure(duration: number, statusCode: number) {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.totalFailedRequestCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.totalFailedRequestCount.push({ statusCode: statusCode, count: 1 });\n }\n\n counter.totalRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countRetry(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.retryCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.retryCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countThrottle(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.throttleCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.throttleCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countException(exceptionType: Error): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentErrorCounter = counter.exceptionCount.find(\n (exceptionCounter) => exceptionType.name === exceptionCounter.exceptionType,\n );\n if (currentErrorCounter) {\n currentErrorCounter.count++;\n } else {\n counter.exceptionCount.push({ exceptionType: exceptionType.name, count: 1 });\n }\n }\n\n // Gets a networkStatsbeat counter if one exists for the given endpoint\n private getNetworkStatsbeatCounter(endpoint: string, host: string): NetworkStatsbeat {\n // Check if the counter is available\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n // Same object\n if (\n endpoint === this.networkStatsbeatCollection[i].endpoint &&\n host === this.networkStatsbeatCollection[i].host\n ) {\n return this.networkStatsbeatCollection[i];\n }\n }\n // Create a new counter if not found\n const newCounter = new NetworkStatsbeat(endpoint, host);\n this.networkStatsbeatCollection.push(newCounter);\n return newCounter;\n }\n\n private getShortHost(originalHost: string): string {\n let shortHost = originalHost;\n try {\n const hostRegex = new RegExp(/^https?:\\/\\/(?:www\\.)?([^\\/.-]+)/);\n const res = hostRegex.exec(originalHost);\n if (res !== null && res.length > 1) {\n shortHost = res[1];\n }\n shortHost = shortHost.replace(\".in.applicationinsights.azure.com\", \"\");\n } catch (error) {\n diag.debug(\"Failed to get the short host name.\");\n }\n return shortHost;\n }\n}\n"]}
@@ -24,6 +24,7 @@ export class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
24
24
  instrumentationKey: this.instrumentationKey,
25
25
  trackStatsbeat: this.trackStatsbeat,
26
26
  exporterOptions: options,
27
+ isStatsbeatSender: true,
27
28
  });
28
29
  }
29
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"statsbeatExporter.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatExporter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,6BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IACH,YAAY,OAAoC;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAXvB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAS1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAAwB,EACxB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;SACR;QAED,MAAM,SAAS,GAAe,yBAAyB,CACrD,OAAO,EACP,IAAI,CAAC,kBAAkB,EACvB,IAAI,CACL,CAAC;QACF,6DAA6D;QAC7D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YACzD,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context } from \"@opentelemetry/api\";\nimport { PushMetricExporter, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\nimport { resourceMetricsToEnvelope } from \"../../utils/metricUtils\";\nimport { AzureMonitorBaseExporter } from \"../base\";\nimport { HttpSender } from \"../../platform\";\n\n/**\n * Azure Monitor Statsbeat Exporter\n */\nexport class AzureMonitorStatsbeatExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if the Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorStatsbeatExporter class.\n * @param options - Exporter configuration\n */\n constructor(options: AzureMonitorExporterOptions) {\n super(options, true);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n });\n }\n\n /**\n * Export Statsbeat metrics.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(\n metrics,\n this.instrumentationKey,\n true, // isStatsbeat flag passed to create a Statsbeat envelope.\n );\n // Supress tracing until OpenTelemetry Metrics SDK support it\n context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorStatsbeatExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n return this._sender.shutdown();\n }\n\n /**\n * Force flush.\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
1
+ {"version":3,"file":"statsbeatExporter.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatExporter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,6BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IACH,YAAY,OAAoC;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAXvB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAS1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,OAAO;YACxB,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAAwB,EACxB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAe,yBAAyB,CACrD,OAAO,EACP,IAAI,CAAC,kBAAkB,EACvB,IAAI,CACL,CAAC;QACF,6DAA6D;QAC7D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YACzD,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context } from \"@opentelemetry/api\";\nimport { PushMetricExporter, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\nimport { resourceMetricsToEnvelope } from \"../../utils/metricUtils\";\nimport { AzureMonitorBaseExporter } from \"../base\";\nimport { HttpSender } from \"../../platform\";\n\n/**\n * Azure Monitor Statsbeat Exporter\n */\nexport class AzureMonitorStatsbeatExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if the Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorStatsbeatExporter class.\n * @param options - Exporter configuration\n */\n constructor(options: AzureMonitorExporterOptions) {\n super(options, true);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n isStatsbeatSender: true,\n });\n }\n\n /**\n * Export Statsbeat metrics.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(\n metrics,\n this.instrumentationKey,\n true, // isStatsbeat flag passed to create a Statsbeat envelope.\n );\n // Supress tracing until OpenTelemetry Metrics SDK support it\n context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorStatsbeatExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n return this._sender.shutdown();\n }\n\n /**\n * Force flush.\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
@@ -51,7 +51,7 @@ export class StatsbeatMetrics {
51
51
  const method = "GET";
52
52
  const options = {
53
53
  url: `${AIMS_URI}?${AIMS_API_VERSION}&${AIMS_FORMAT}`,
54
- timeout: 5000,
54
+ timeout: 5000, // 5 seconds
55
55
  method: method,
56
56
  allowInsecureConnection: true,
57
57
  };