@azure/monitor-opentelemetry-exporter 1.0.0-beta.10 → 1.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,9 +28,10 @@ Add the exporter to your existing OpenTelemetry tracer provider (`NodeTracerProv
28
28
 
29
29
  ```js
30
30
  const { AzureMonitorTraceExporter } = require("@azure/monitor-opentelemetry-exporter");
31
- const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
32
31
  const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");
33
-
32
+ const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
33
+ const { Resource } = require("@opentelemetry/resources");
34
+ const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
34
35
 
35
36
  const provider = new NodeTracerProvider({
36
37
  resource: new Resource({
@@ -60,9 +61,9 @@ Add the exporter to your existing OpenTelemetry tracer provider (`NodeTracerProv
60
61
 
61
62
  ```js
62
63
  const { MeterProvider, PeriodicExportingMetricReader } = require("@opentelemetry/sdk-metrics");
64
+ const { AzureMonitorMetricExporter } = require("@azure/monitor-opentelemetry-exporter");
63
65
  const { Resource } = require("@opentelemetry/resources");
64
66
  const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
65
- const { AzureMonitorMetricExporter } = require("@azure/monitor-opentelemetry-exporter");
66
67
 
67
68
  // Add the exporter into the MetricReader and register it with the MeterProvider
68
69
  const provider = new MeterProvider();
@@ -75,7 +76,6 @@ const metricReaderOptions = {
75
76
  };
76
77
  const metricReader = new PeriodicExportingMetricReader(metricReaderOptions);
77
78
  provider.addMetricReader(metricReader);
78
- );
79
79
  ```
80
80
 
81
81
  ### Logs
@@ -88,8 +88,8 @@ You can enable sampling to limit the amount of telemetry records you receive. In
88
88
 
89
89
  ```js
90
90
  const { ApplicationInsightsSampler } = require("@azure/monitor-opentelemetry-exporter");
91
- const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
92
91
  const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");
92
+ const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
93
93
 
94
94
  // Sampler expects a sample rate of between 0 and 1 inclusive
95
95
  // A rate of 0.75 means approximately 75 % of your traces will be sent
@@ -118,7 +118,7 @@ For more information on the OpenTelemetry project, please review the [**OpenTele
118
118
  You can enable debug logging by changing the logging level of your provider.
119
119
 
120
120
  ```js
121
- const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api");
121
+ const { DiagConsoleLogger, DiagLogLevel, diag } = require("@opentelemetry/api");
122
122
  const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
123
123
 
124
124
  const provider = new NodeTracerProvider();
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@ 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 coreRestPipeline = require('@azure/core-rest-pipeline');
9
8
  var sdkMetrics = require('@opentelemetry/sdk-metrics');
9
+ var coreRestPipeline = require('@azure/core-rest-pipeline');
10
10
  var os$1 = require('os');
11
11
  var semanticConventions = require('@opentelemetry/semantic-conventions');
12
12
  var url = require('url');
@@ -66,7 +66,7 @@ const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
66
66
  * AzureMonitorTraceExporter version.
67
67
  * @internal
68
68
  */
69
- const packageVersion = "1.0.0-beta.10";
69
+ const packageVersion = "1.0.0-beta.11";
70
70
  var DependencyTypes;
71
71
  (function (DependencyTypes) {
72
72
  DependencyTypes["InProc"] = "InProc";
@@ -1756,7 +1756,7 @@ class ApplicationInsightsClient extends coreClient__namespace.ServiceClient {
1756
1756
  const defaults = {
1757
1757
  requestContentType: "application/json; charset=utf-8"
1758
1758
  };
1759
- const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.9`;
1759
+ const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.11`;
1760
1760
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1761
1761
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1762
1762
  : `${packageDetails}`;
@@ -1893,7 +1893,7 @@ class HttpSender {
1893
1893
  }
1894
1894
 
1895
1895
  // Copyright (c) Microsoft Corporation.
1896
- let instance = null;
1896
+ let instance$1 = null;
1897
1897
  /**
1898
1898
  * Azure Telemetry context.
1899
1899
  * @internal
@@ -1922,11 +1922,11 @@ Context.nodeVersion = "";
1922
1922
  * Singleton Context instance.
1923
1923
  * @internal
1924
1924
  */
1925
- function getInstance() {
1926
- if (!instance) {
1927
- instance = new Context();
1925
+ function getInstance$1() {
1926
+ if (!instance$1) {
1927
+ instance$1 = new Context();
1928
1928
  }
1929
- return instance;
1929
+ return instance$1;
1930
1930
  }
1931
1931
 
1932
1932
  // Copyright (c) Microsoft Corporation.
@@ -2001,6 +2001,8 @@ var StatsbeatCounter;
2001
2001
  StatsbeatCounter["THROTTLE_COUNT"] = "Throttle Count";
2002
2002
  StatsbeatCounter["EXCEPTION_COUNT"] = "Exception Count";
2003
2003
  StatsbeatCounter["AVERAGE_DURATION"] = "Request Duration";
2004
+ StatsbeatCounter["ATTACH"] = "Attach";
2005
+ StatsbeatCounter["FEATURE"] = "Feature";
2004
2006
  })(StatsbeatCounter || (StatsbeatCounter = {}));
2005
2007
  const AIMS_URI = "http://169.254.169.254/metadata/instance/compute";
2006
2008
  const AIMS_API_VERSION = "api-version=2017-12-01";
@@ -2018,60 +2020,23 @@ const EU_ENDPOINTS = [
2018
2020
  "swedencentral",
2019
2021
  "switzerlandnorth",
2020
2022
  "switzerlandwest",
2023
+ "uksouth",
2024
+ "ukwest",
2021
2025
  ];
2026
+ var StatsbeatFeatureType;
2027
+ (function (StatsbeatFeatureType) {
2028
+ StatsbeatFeatureType["FEATURE"] = "Feature";
2029
+ StatsbeatFeatureType["INSTRUMENTATION"] = "Instrumentation";
2030
+ })(StatsbeatFeatureType || (StatsbeatFeatureType = {}));
2022
2031
 
2023
2032
  // Copyright (c) Microsoft Corporation.
2024
2033
  const os = require("os");
2025
2034
  class StatsbeatMetrics {
2026
- constructor(options) {
2027
- this._isInitialized = false;
2028
- this._networkStatsbeatCollection = [];
2029
- this._statsCollectionShortInterval = 900000; // 15 minutes
2030
- // Custom dimensions
2035
+ constructor() {
2031
2036
  this._resourceProvider = StatsbeatResourceProvider.unknown;
2037
+ this._vmInfo = {};
2032
2038
  this._os = os.type();
2033
- this._attach = "sdk";
2034
- this._connectionString = this._getConnectionString(options.endpointUrl);
2035
- this._meterProvider = new sdkMetrics.MeterProvider();
2036
- const exporterConfig = {
2037
- connectionString: this._connectionString,
2038
- };
2039
- this._azureExporter = new _AzureMonitorStatsbeatExporter(exporterConfig);
2040
- const metricReaderOptions = {
2041
- exporter: this._azureExporter,
2042
- exportIntervalMillis: options.collectionInterval || this._statsCollectionShortInterval, // 15 minutes
2043
- };
2044
- // Exports Network Statsbeat every 15 minutes
2045
- this._metricReader = new sdkMetrics.PeriodicExportingMetricReader(metricReaderOptions);
2046
- this._meterProvider.addMetricReader(this._metricReader);
2047
- this._meter = this._meterProvider.getMeter("Azure Monitor NetworkStatsbeat");
2048
- this._endpointUrl = options.endpointUrl;
2049
- this._runtimeVersion = process.version;
2050
- this._language = STATSBEAT_LANGUAGE;
2051
- this._version = packageVersion;
2052
- this._host = this._getShortHost(options.endpointUrl);
2053
- this._cikey = options.instrumentationKey;
2054
- this._successCountGauge = this._meter.createObservableGauge(StatsbeatCounter.SUCCESS_COUNT);
2055
- this._failureCountGauge = this._meter.createObservableGauge(StatsbeatCounter.FAILURE_COUNT);
2056
- this._retryCountGauge = this._meter.createObservableGauge(StatsbeatCounter.RETRY_COUNT);
2057
- this._throttleCountGauge = this._meter.createObservableGauge(StatsbeatCounter.THROTTLE_COUNT);
2058
- this._exceptionCountGauge = this._meter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
2059
- this._averageDurationGauge = this._meter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
2060
- this._commonProperties = {
2061
- os: this._os,
2062
- rp: this._resourceProvider,
2063
- cikey: this._cikey,
2064
- runtimeVersion: this._runtimeVersion,
2065
- language: this._language,
2066
- version: this._version,
2067
- attach: this._attach,
2068
- };
2069
- this._networkProperties = {
2070
- endpoint: this._endpointUrl,
2071
- host: this._host,
2072
- };
2073
- this._isInitialized = true;
2074
- this._initialize();
2039
+ this._resourceIdentifier = "";
2075
2040
  }
2076
2041
  async _getResourceProvider() {
2077
2042
  // Check resource provider
@@ -2086,6 +2051,11 @@ class StatsbeatMetrics {
2086
2051
  }
2087
2052
  else if (await this.getAzureComputeMetadata()) {
2088
2053
  this._resourceProvider = StatsbeatResourceProvider.vm;
2054
+ this._resourceIdentifier = this._vmInfo.id + "/" + this._vmInfo.subscriptionId;
2055
+ // Overrride OS as VM info have higher precedence
2056
+ if (this._vmInfo.osType) {
2057
+ this._os = this._vmInfo.osType;
2058
+ }
2089
2059
  }
2090
2060
  else {
2091
2061
  this._resourceProvider = StatsbeatResourceProvider.unknown;
@@ -2105,6 +2075,23 @@ class StatsbeatMetrics {
2105
2075
  .sendRequest(request)
2106
2076
  .then((res) => {
2107
2077
  if (res.status === 200) {
2078
+ // Success; VM
2079
+ this._vmInfo.isVM = true;
2080
+ let virtualMachineData = "";
2081
+ res.on("data", (data) => {
2082
+ virtualMachineData += data;
2083
+ });
2084
+ res.on("end", () => {
2085
+ try {
2086
+ let data = JSON.parse(virtualMachineData);
2087
+ this._vmInfo.id = data["vmId"] || "";
2088
+ this._vmInfo.subscriptionId = data["subscriptionId"] || "";
2089
+ this._vmInfo.osType = data["osType"] || "";
2090
+ }
2091
+ catch (error) {
2092
+ api.diag.debug("Failed to parse JSON: ", error);
2093
+ }
2094
+ });
2108
2095
  return true;
2109
2096
  }
2110
2097
  else {
@@ -2116,27 +2103,88 @@ class StatsbeatMetrics {
2116
2103
  });
2117
2104
  return false;
2118
2105
  }
2106
+ _getConnectionString(endpointUrl) {
2107
+ let currentEndpoint = endpointUrl;
2108
+ for (let i = 0; i < EU_ENDPOINTS.length; i++) {
2109
+ if (currentEndpoint.includes(EU_ENDPOINTS[i])) {
2110
+ return EU_CONNECTION_STRING;
2111
+ }
2112
+ }
2113
+ return NON_EU_CONNECTION_STRING;
2114
+ }
2115
+ }
2116
+
2117
+ // Copyright (c) Microsoft Corporation.
2118
+ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
2119
+ constructor(options) {
2120
+ super();
2121
+ this._isInitialized = false;
2122
+ this._statsCollectionShortInterval = 900000; // 15 minutes
2123
+ this._networkStatsbeatCollection = [];
2124
+ this._attach = "sdk";
2125
+ this._connectionString = super._getConnectionString(options.endpointUrl);
2126
+ this._networkStatsbeatMeterProvider = new sdkMetrics.MeterProvider();
2127
+ const exporterConfig = {
2128
+ connectionString: this._connectionString,
2129
+ };
2130
+ this._networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);
2131
+ // Exports Network Statsbeat every 15 minutes
2132
+ const networkMetricReaderOptions = {
2133
+ exporter: this._networkAzureExporter,
2134
+ exportIntervalMillis: options.networkCollectionInterval || this._statsCollectionShortInterval, // 15 minutes
2135
+ };
2136
+ this._networkMetricReader = new sdkMetrics.PeriodicExportingMetricReader(networkMetricReaderOptions);
2137
+ this._networkStatsbeatMeterProvider.addMetricReader(this._networkMetricReader);
2138
+ this._networkStatsbeatMeter = this._networkStatsbeatMeterProvider.getMeter("Azure Monitor Network Statsbeat");
2139
+ this._endpointUrl = options.endpointUrl;
2140
+ this._runtimeVersion = process.version;
2141
+ this._language = STATSBEAT_LANGUAGE;
2142
+ this._version = packageVersion;
2143
+ this._host = this._getShortHost(options.endpointUrl);
2144
+ this._cikey = options.instrumentationKey;
2145
+ this._successCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.SUCCESS_COUNT);
2146
+ this._failureCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.FAILURE_COUNT);
2147
+ this._retryCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.RETRY_COUNT);
2148
+ this._throttleCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.THROTTLE_COUNT);
2149
+ this._exceptionCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
2150
+ this._averageDurationGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
2151
+ this._commonProperties = {
2152
+ os: super._os,
2153
+ rp: super._resourceProvider,
2154
+ cikey: this._cikey,
2155
+ runtimeVersion: this._runtimeVersion,
2156
+ language: this._language,
2157
+ version: this._version,
2158
+ attach: this._attach,
2159
+ };
2160
+ this._networkProperties = {
2161
+ endpoint: this._endpointUrl,
2162
+ host: this._host,
2163
+ };
2164
+ this._isInitialized = true;
2165
+ this._initialize();
2166
+ }
2119
2167
  isInitialized() {
2120
2168
  return this._isInitialized;
2121
2169
  }
2122
2170
  shutdown() {
2123
- this._meterProvider.shutdown();
2171
+ this._networkStatsbeatMeterProvider.shutdown();
2124
2172
  }
2125
2173
  async _initialize() {
2126
2174
  try {
2127
- await this._getResourceProvider();
2128
- // Add observable callbacks
2175
+ await super._getResourceProvider();
2176
+ // Add network observable callbacks
2129
2177
  this._successCountGauge.addCallback(this._successCallback.bind(this));
2130
- this._meter.addBatchObservableCallback(this._failureCallback.bind(this), [
2178
+ this._networkStatsbeatMeter.addBatchObservableCallback(this._failureCallback.bind(this), [
2131
2179
  this._failureCountGauge,
2132
2180
  ]);
2133
- this._meter.addBatchObservableCallback(this._retryCallback.bind(this), [
2181
+ this._networkStatsbeatMeter.addBatchObservableCallback(this._retryCallback.bind(this), [
2134
2182
  this._retryCountGauge,
2135
2183
  ]);
2136
- this._meter.addBatchObservableCallback(this._throttleCallback.bind(this), [
2184
+ this._networkStatsbeatMeter.addBatchObservableCallback(this._throttleCallback.bind(this), [
2137
2185
  this._throttleCountGauge,
2138
2186
  ]);
2139
- this._meter.addBatchObservableCallback(this._exceptionCallback.bind(this), [
2187
+ this._networkStatsbeatMeter.addBatchObservableCallback(this._exceptionCallback.bind(this), [
2140
2188
  this._exceptionCountGauge,
2141
2189
  ]);
2142
2190
  this._averageDurationGauge.addCallback(this._durationCallback.bind(this));
@@ -2299,21 +2347,123 @@ class StatsbeatMetrics {
2299
2347
  if (res != null && res.length > 1) {
2300
2348
  shortHost = res[1];
2301
2349
  }
2350
+ shortHost = shortHost.replace(".in.applicationinsights.azure.com", "");
2302
2351
  }
2303
2352
  catch (error) {
2304
2353
  api.diag.debug("Failed to get the short host name.");
2305
2354
  }
2306
2355
  return shortHost;
2307
2356
  }
2308
- _getConnectionString(endpointUrl) {
2309
- let currentEndpoint = endpointUrl;
2310
- for (let i = 0; i < EU_ENDPOINTS.length; i++) {
2311
- if (currentEndpoint.includes(EU_ENDPOINTS[i])) {
2312
- return EU_CONNECTION_STRING;
2357
+ }
2358
+
2359
+ // Copyright (c) Microsoft Corporation.
2360
+ let instance = null;
2361
+ /**
2362
+ * Long Interval Statsbeat Metrics
2363
+ * @internal
2364
+ */
2365
+ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
2366
+ constructor(options) {
2367
+ super();
2368
+ this._AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;
2369
+ this._statsCollectionLongInterval = 86400000; // 1 day
2370
+ this._isInitialized = false;
2371
+ this._attach = "sdk";
2372
+ this._feature = 0;
2373
+ this._instrumentation = 0;
2374
+ this._connectionString = super._getConnectionString(options.endpointUrl);
2375
+ const exporterConfig = {
2376
+ connectionString: this._connectionString,
2377
+ };
2378
+ if (this._AZURE_MONITOR_STATSBEAT_FEATURES) {
2379
+ try {
2380
+ this._feature = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).feature;
2381
+ this._instrumentation = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;
2382
+ }
2383
+ catch (error) {
2384
+ api.diag.error(`LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`);
2313
2385
  }
2314
2386
  }
2315
- return NON_EU_CONNECTION_STRING;
2387
+ this._longIntervalStatsbeatMeterProvider = new sdkMetrics.MeterProvider();
2388
+ this._longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);
2389
+ // Export Long Interval Statsbeats every day
2390
+ const longIntervalMetricReaderOptions = {
2391
+ exporter: this._longIntervalAzureExporter,
2392
+ exportIntervalMillis: Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this._statsCollectionLongInterval, // 1 day
2393
+ };
2394
+ this._longIntervalMetricReader = new sdkMetrics.PeriodicExportingMetricReader(longIntervalMetricReaderOptions);
2395
+ this._longIntervalStatsbeatMeterProvider.addMetricReader(this._longIntervalMetricReader);
2396
+ this._longIntervalStatsbeatMeter = this._longIntervalStatsbeatMeterProvider.getMeter("Azure Monitor Long Interval Statsbeat");
2397
+ // Assign Common Properties
2398
+ this._runtimeVersion = process.version;
2399
+ this._language = STATSBEAT_LANGUAGE;
2400
+ this._version = packageVersion;
2401
+ this._cikey = options.instrumentationKey;
2402
+ this._featureStatsbeatGauge = this._longIntervalStatsbeatMeter.createObservableGauge(StatsbeatCounter.FEATURE);
2403
+ this._attachStatsbeatGauge = this._longIntervalStatsbeatMeter.createObservableGauge(StatsbeatCounter.ATTACH);
2404
+ this._commonProperties = {
2405
+ os: super._os,
2406
+ rp: super._resourceProvider,
2407
+ cikey: this._cikey,
2408
+ runtimeVersion: this._runtimeVersion,
2409
+ language: this._language,
2410
+ version: this._version,
2411
+ attach: this._attach,
2412
+ };
2413
+ this._attachProperties = {
2414
+ rpId: super._resourceIdentifier,
2415
+ };
2416
+ this._isInitialized = true;
2417
+ this._initialize();
2418
+ }
2419
+ async _initialize() {
2420
+ try {
2421
+ await this._getResourceProvider();
2422
+ // Add long interval observable callbacks
2423
+ this._attachStatsbeatGauge.addCallback(this._attachCallback.bind(this));
2424
+ this._longIntervalStatsbeatMeter.addBatchObservableCallback(this._featureCallback.bind(this), [this._featureStatsbeatGauge]);
2425
+ // Export Feature/Attach Statsbeat once upon app initialization
2426
+ this._longIntervalAzureExporter.export((await this._longIntervalMetricReader.collect()).resourceMetrics, (result) => {
2427
+ if (result.code !== core.ExportResultCode.SUCCESS) {
2428
+ api.diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);
2429
+ }
2430
+ });
2431
+ }
2432
+ catch (error) {
2433
+ api.diag.debug("Call to get the resource provider failed.");
2434
+ }
2435
+ }
2436
+ _featureCallback(observableResult) {
2437
+ let attributes;
2438
+ if (this._instrumentation) {
2439
+ attributes = Object.assign(Object.assign({}, this._commonProperties), { feature: this._instrumentation, type: StatsbeatFeatureType.INSTRUMENTATION });
2440
+ observableResult.observe(this._featureStatsbeatGauge, 1, Object.assign({}, attributes));
2441
+ }
2442
+ if (this._feature) {
2443
+ attributes = Object.assign(Object.assign({}, this._commonProperties), { feature: this._feature, type: StatsbeatFeatureType.FEATURE });
2444
+ observableResult.observe(this._featureStatsbeatGauge, 1, Object.assign({}, attributes));
2445
+ }
2446
+ }
2447
+ _attachCallback(observableResult) {
2448
+ let attributes = Object.assign(Object.assign({}, this._commonProperties), this._attachProperties);
2449
+ observableResult.observe(1, attributes);
2316
2450
  }
2451
+ isInitialized() {
2452
+ return this._isInitialized;
2453
+ }
2454
+ shutdown() {
2455
+ this._longIntervalStatsbeatMeterProvider.shutdown();
2456
+ }
2457
+ }
2458
+ /**
2459
+ * Singleton LongIntervalStatsbeatMetrics instance.
2460
+ * @internal
2461
+ */
2462
+ function getInstance(options) {
2463
+ if (!instance) {
2464
+ instance = new LongIntervalStatsbeatMetrics(options);
2465
+ }
2466
+ return instance;
2317
2467
  }
2318
2468
 
2319
2469
  // Copyright (c) Microsoft Corporation.
@@ -2357,7 +2507,11 @@ class AzureMonitorBaseExporter {
2357
2507
  this._persister = new FileSystemPersist(this._instrumentationKey, this._options);
2358
2508
  if (!this._isStatsbeatExporter) {
2359
2509
  // Initialize statsbeatMetrics
2360
- this._statsbeatMetrics = new StatsbeatMetrics({
2510
+ this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
2511
+ instrumentationKey: this._instrumentationKey,
2512
+ endpointUrl: this._endpointUrl,
2513
+ });
2514
+ this._longIntervalStatsbeatMetrics = getInstance({
2361
2515
  instrumentationKey: this._instrumentationKey,
2362
2516
  endpointUrl: this._endpointUrl,
2363
2517
  });
@@ -2413,13 +2567,13 @@ class AzureMonitorBaseExporter {
2413
2567
  this._retryTimer.unref();
2414
2568
  }
2415
2569
  // If we are not exportings statsbeat and statsbeat is not disabled -- count success
2416
- (_a = this._statsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countSuccess(duration);
2570
+ (_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countSuccess(duration);
2417
2571
  return { code: core.ExportResultCode.SUCCESS };
2418
2572
  }
2419
2573
  else if (statusCode && isRetriable(statusCode)) {
2420
2574
  // Failed -- persist failed data
2421
2575
  if (statusCode === 429 || statusCode === 439) {
2422
- (_b = this._statsbeatMetrics) === null || _b === void 0 ? void 0 : _b.countThrottle(statusCode);
2576
+ (_b = this._networkStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.countThrottle(statusCode);
2423
2577
  }
2424
2578
  if (result) {
2425
2579
  api.diag.info(result);
@@ -2433,27 +2587,27 @@ class AzureMonitorBaseExporter {
2433
2587
  });
2434
2588
  }
2435
2589
  if (filteredEnvelopes.length > 0) {
2436
- (_c = this._statsbeatMetrics) === null || _c === void 0 ? void 0 : _c.countRetry(statusCode);
2590
+ (_c = this._networkStatsbeatMetrics) === null || _c === void 0 ? void 0 : _c.countRetry(statusCode);
2437
2591
  // calls resultCallback(ExportResult) based on result of persister.push
2438
2592
  return await this._persist(filteredEnvelopes);
2439
2593
  }
2440
2594
  // Failed -- not retriable
2441
- (_d = this._statsbeatMetrics) === null || _d === void 0 ? void 0 : _d.countFailure(duration, statusCode);
2595
+ (_d = this._networkStatsbeatMetrics) === null || _d === void 0 ? void 0 : _d.countFailure(duration, statusCode);
2442
2596
  return {
2443
2597
  code: core.ExportResultCode.FAILED,
2444
2598
  };
2445
2599
  }
2446
2600
  else {
2447
2601
  // calls resultCallback(ExportResult) based on result of persister.push
2448
- (_e = this._statsbeatMetrics) === null || _e === void 0 ? void 0 : _e.countRetry(statusCode);
2602
+ (_e = this._networkStatsbeatMetrics) === null || _e === void 0 ? void 0 : _e.countRetry(statusCode);
2449
2603
  return await this._persist(envelopes);
2450
2604
  }
2451
2605
  }
2452
2606
  else {
2453
2607
  // Failed -- not retriable
2454
- if (this._statsbeatMetrics) {
2608
+ if (this._networkStatsbeatMetrics) {
2455
2609
  if (statusCode) {
2456
- this._statsbeatMetrics.countFailure(duration, statusCode);
2610
+ this._networkStatsbeatMetrics.countFailure(duration, statusCode);
2457
2611
  }
2458
2612
  }
2459
2613
  else {
@@ -2485,34 +2639,35 @@ class AzureMonitorBaseExporter {
2485
2639
  }
2486
2640
  else {
2487
2641
  let redirectError = new Error("Circular redirect");
2488
- (_f = this._statsbeatMetrics) === null || _f === void 0 ? void 0 : _f.countException(redirectError);
2642
+ (_f = this._networkStatsbeatMetrics) === null || _f === void 0 ? void 0 : _f.countException(redirectError);
2489
2643
  return { code: core.ExportResultCode.FAILED, error: redirectError };
2490
2644
  }
2491
2645
  }
2492
2646
  else if (restError.statusCode && isRetriable(restError.statusCode)) {
2493
- (_g = this._statsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
2647
+ (_g = this._networkStatsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
2494
2648
  return await this._persist(envelopes);
2495
2649
  }
2496
2650
  if (this._isNetworkError(restError)) {
2497
2651
  if (restError.statusCode) {
2498
- (_h = this._statsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
2652
+ (_h = this._networkStatsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
2499
2653
  }
2500
2654
  api.diag.error("Retrying due to transient client side error. Error message:", restError.message);
2501
2655
  return await this._persist(envelopes);
2502
2656
  }
2503
- (_j = this._statsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
2657
+ (_j = this._networkStatsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
2504
2658
  api.diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
2505
2659
  return { code: core.ExportResultCode.FAILED, error: restError };
2506
2660
  }
2507
2661
  }
2508
2662
  // Disable collection of statsbeat metrics after max failures
2509
2663
  _incrementStatsbeatFailure() {
2510
- var _a;
2664
+ var _a, _b;
2511
2665
  this._statsbeatFailureCount++;
2512
2666
  if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {
2513
2667
  this._isStatsbeatExporter = false;
2514
- (_a = this._statsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
2515
- this._statsbeatMetrics = undefined;
2668
+ (_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
2669
+ (_b = this._longIntervalStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.shutdown();
2670
+ this._networkStatsbeatMetrics = undefined;
2516
2671
  this._statsbeatFailureCount = 0;
2517
2672
  }
2518
2673
  }
@@ -2537,7 +2692,7 @@ class AzureMonitorBaseExporter {
2537
2692
 
2538
2693
  // Copyright (c) Microsoft Corporation.
2539
2694
  function createTagsFromResource(resource) {
2540
- const context = getInstance();
2695
+ const context = getInstance$1();
2541
2696
  const tags = Object.assign({}, context.tags);
2542
2697
  if (resource && resource.attributes) {
2543
2698
  const serviceName = resource.attributes[semanticConventions.SemanticResourceAttributes.SERVICE_NAME];
@@ -3283,10 +3438,9 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
3283
3438
 
3284
3439
  // Copyright (c) Microsoft Corporation.
3285
3440
  /**
3286
- * @internal
3287
3441
  * Azure Monitor Statsbeat Exporter
3288
3442
  */
3289
- class _AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
3443
+ class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
3290
3444
  /**
3291
3445
  * Initializes a new instance of the AzureMonitorStatsbeatExporter class.
3292
3446
  * @param options - Exporter configuration
@@ -3331,6 +3485,6 @@ class _AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
3331
3485
  exports.ApplicationInsightsSampler = ApplicationInsightsSampler;
3332
3486
  exports.AzureMonitorBaseExporter = AzureMonitorBaseExporter;
3333
3487
  exports.AzureMonitorMetricExporter = AzureMonitorMetricExporter;
3488
+ exports.AzureMonitorStatsbeatExporter = AzureMonitorStatsbeatExporter;
3334
3489
  exports.AzureMonitorTraceExporter = AzureMonitorTraceExporter;
3335
- exports._AzureMonitorStatsbeatExporter = _AzureMonitorStatsbeatExporter;
3336
3490
  //# sourceMappingURL=index.js.map