@azure/monitor-opentelemetry-exporter 1.0.0-beta.13 → 1.0.0-beta.15
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 +0 -1
- package/dist/index.js +441 -418
- package/dist-esm/src/config.js.map +1 -1
- package/dist-esm/src/export/base.js +16 -201
- package/dist-esm/src/export/base.js.map +1 -1
- package/dist-esm/src/export/log.js +5 -3
- package/dist-esm/src/export/log.js.map +1 -1
- package/dist-esm/src/export/metric.js +12 -7
- package/dist-esm/src/export/metric.js.map +1 -1
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +1 -1
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +1 -1
- package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/statsbeatExporter.js +5 -3
- package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist-esm/src/export/trace.js +7 -5
- package/dist-esm/src/export/trace.js.map +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
- package/dist-esm/src/index.js +0 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/platform/nodejs/baseSender.js +197 -0
- package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -0
- package/dist-esm/src/platform/nodejs/httpSender.js +9 -10
- package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
- package/dist-esm/src/sampling.js +4 -0
- package/dist-esm/src/sampling.js.map +1 -1
- package/dist-esm/src/types.js.map +1 -1
- package/dist-esm/src/utils/common.js +7 -5
- package/dist-esm/src/utils/common.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +3 -3
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/logUtils.js +3 -0
- package/dist-esm/src/utils/logUtils.js.map +1 -1
- package/package.json +12 -12
- package/types/monitor-opentelemetry-exporter.d.ts +19 -97
package/dist/index.js
CHANGED
|
@@ -5,16 +5,16 @@ 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 sdkMetrics = require('@opentelemetry/sdk-metrics');
|
|
9
|
-
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
10
|
-
var os$1 = require('os');
|
|
11
|
-
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
12
8
|
var url = require('url');
|
|
13
|
-
var
|
|
9
|
+
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
10
|
+
var os$1 = require('os');
|
|
11
|
+
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
12
|
+
var sdkMetrics = require('@opentelemetry/sdk-metrics');
|
|
14
13
|
var fs = require('fs');
|
|
15
14
|
var path = require('path');
|
|
16
15
|
var child_process = require('child_process');
|
|
17
16
|
var util = require('util');
|
|
17
|
+
var coreClient = require('@azure/core-client');
|
|
18
18
|
|
|
19
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
20
|
|
|
@@ -36,14 +36,14 @@ function _interopNamespace(e) {
|
|
|
36
36
|
return Object.freeze(n);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
|
|
40
40
|
var os__namespace = /*#__PURE__*/_interopNamespace(os$1);
|
|
41
41
|
var os__default = /*#__PURE__*/_interopDefaultLegacy(os$1);
|
|
42
|
-
var
|
|
43
|
-
var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
|
|
42
|
+
var coreRestPipeline__namespace = /*#__PURE__*/_interopNamespace(coreRestPipeline);
|
|
44
43
|
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
45
44
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
46
45
|
var child_process__namespace = /*#__PURE__*/_interopNamespace(child_process);
|
|
46
|
+
var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
|
|
47
47
|
|
|
48
48
|
// Copyright (c) Microsoft Corporation.
|
|
49
49
|
// Licensed under the MIT license.
|
|
@@ -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.
|
|
69
|
+
const packageVersion = "1.0.0-beta.15";
|
|
70
70
|
var DependencyTypes;
|
|
71
71
|
(function (DependencyTypes) {
|
|
72
72
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -83,10 +83,10 @@ const ApplicationInsightsPageViewName = "Microsoft.ApplicationInsights.PageView"
|
|
|
83
83
|
const ApplicationInsightsAvailabilityName = "Microsoft.ApplicationInsights.Availability";
|
|
84
84
|
const ApplicationInsightsEventName = "Microsoft.ApplicationInsights.Event";
|
|
85
85
|
const ApplicationInsightsMessageBaseType = "MessageData";
|
|
86
|
-
const ApplicationInsightsExceptionBaseType = "
|
|
86
|
+
const ApplicationInsightsExceptionBaseType = "ExceptionData";
|
|
87
87
|
const ApplicationInsightsPageViewBaseType = "PageViewData";
|
|
88
88
|
const ApplicationInsightsAvailabilityBaseType = "AvailabilityData";
|
|
89
|
-
const ApplicationInsightsEventBaseType = "
|
|
89
|
+
const ApplicationInsightsEventBaseType = "EventData";
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* ApplicationInsightsSampler is responsible for the following:
|
|
@@ -95,6 +95,10 @@ const ApplicationInsightsEventBaseType = "TelemetryEventData";
|
|
|
95
95
|
* @param samplingRatio - 0 to 1 value.
|
|
96
96
|
*/
|
|
97
97
|
class ApplicationInsightsSampler {
|
|
98
|
+
/**
|
|
99
|
+
* Initializes a new instance of the ApplicationInsightsSampler class.
|
|
100
|
+
* @param samplingRatio Value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.
|
|
101
|
+
*/
|
|
98
102
|
constructor(samplingRatio = 1) {
|
|
99
103
|
this._samplingRatio = samplingRatio;
|
|
100
104
|
if (this._samplingRatio > 1) {
|
|
@@ -323,6 +327,51 @@ class ConnectionStringParser {
|
|
|
323
327
|
ConnectionStringParser.FIELDS_SEPARATOR = ";";
|
|
324
328
|
ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR = "=";
|
|
325
329
|
|
|
330
|
+
// Copyright (c) Microsoft Corporation.
|
|
331
|
+
/**
|
|
332
|
+
* Azure Monitor OpenTelemetry Trace Exporter.
|
|
333
|
+
*/
|
|
334
|
+
class AzureMonitorBaseExporter {
|
|
335
|
+
/**
|
|
336
|
+
* Initializes a new instance of the AzureMonitorBaseExporter class.
|
|
337
|
+
* @param AzureMonitorExporterOptions - Exporter configuration.
|
|
338
|
+
*/
|
|
339
|
+
constructor(options = {}, isStatsbeatExporter) {
|
|
340
|
+
var _a;
|
|
341
|
+
/**
|
|
342
|
+
* Instrumentation key to be used for exported envelopes
|
|
343
|
+
*/
|
|
344
|
+
this.instrumentationKey = "";
|
|
345
|
+
/**
|
|
346
|
+
* Ingestion Endpoint URL
|
|
347
|
+
*/
|
|
348
|
+
this.endpointUrl = "";
|
|
349
|
+
/**
|
|
350
|
+
*Flag to determine if exporter will generate Statsbeat data
|
|
351
|
+
*/
|
|
352
|
+
this.trackStatsbeat = false;
|
|
353
|
+
this._options = options;
|
|
354
|
+
this.instrumentationKey = "";
|
|
355
|
+
this.endpointUrl = DEFAULT_BREEZE_ENDPOINT;
|
|
356
|
+
const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];
|
|
357
|
+
this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;
|
|
358
|
+
if (connectionString) {
|
|
359
|
+
const parsedConnectionString = ConnectionStringParser.parse(connectionString);
|
|
360
|
+
this.instrumentationKey =
|
|
361
|
+
parsedConnectionString.instrumentationkey || this.instrumentationKey;
|
|
362
|
+
this.endpointUrl = ((_a = parsedConnectionString.ingestionendpoint) === null || _a === void 0 ? void 0 : _a.trim()) || this.endpointUrl;
|
|
363
|
+
}
|
|
364
|
+
// Instrumentation key is required
|
|
365
|
+
if (!this.instrumentationKey) {
|
|
366
|
+
const message = "No instrumentation key or connection string was provided to the Azure Monitor Exporter";
|
|
367
|
+
api.diag.error(message);
|
|
368
|
+
throw new Error(message);
|
|
369
|
+
}
|
|
370
|
+
this.trackStatsbeat = !this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];
|
|
371
|
+
api.diag.debug("AzureMonitorExporter was successfully setup");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
326
375
|
// Copyright (c) Microsoft Corporation.
|
|
327
376
|
class FileAccessControl {
|
|
328
377
|
// Check if file access control could be enabled
|
|
@@ -1743,7 +1792,7 @@ class ApplicationInsightsClient extends coreClient__namespace.ServiceClient {
|
|
|
1743
1792
|
const defaults = {
|
|
1744
1793
|
requestContentType: "application/json; charset=utf-8"
|
|
1745
1794
|
};
|
|
1746
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
1795
|
+
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.15`;
|
|
1747
1796
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
1748
1797
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
1749
1798
|
: `${packageDetails}`;
|
|
@@ -1819,149 +1868,6 @@ const trackOperationSpec = {
|
|
|
1819
1868
|
serializer
|
|
1820
1869
|
};
|
|
1821
1870
|
|
|
1822
|
-
// Copyright (c) Microsoft Corporation.
|
|
1823
|
-
const applicationInsightsResource = "https://monitor.azure.com//.default";
|
|
1824
|
-
/**
|
|
1825
|
-
* Exporter HTTP sender class
|
|
1826
|
-
* @internal
|
|
1827
|
-
*/
|
|
1828
|
-
class HttpSender {
|
|
1829
|
-
constructor(endpointUrl, options) {
|
|
1830
|
-
// Build endpoint using provided configuration or default values
|
|
1831
|
-
this._appInsightsClientOptions = Object.assign({ host: endpointUrl }, options);
|
|
1832
|
-
this._appInsightsClient = new ApplicationInsightsClient(this._appInsightsClientOptions);
|
|
1833
|
-
// Handle redirects in HTTP Sender
|
|
1834
|
-
this._appInsightsClient.pipeline.removePolicy({ name: coreRestPipeline.redirectPolicyName });
|
|
1835
|
-
if (options === null || options === void 0 ? void 0 : options.aadTokenCredential) {
|
|
1836
|
-
let scopes = [applicationInsightsResource];
|
|
1837
|
-
this._appInsightsClient.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
1838
|
-
credential: options === null || options === void 0 ? void 0 : options.aadTokenCredential,
|
|
1839
|
-
scopes: scopes,
|
|
1840
|
-
}));
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* Send Azure envelopes
|
|
1845
|
-
* @internal
|
|
1846
|
-
*/
|
|
1847
|
-
async send(envelopes) {
|
|
1848
|
-
var _a;
|
|
1849
|
-
let options = {};
|
|
1850
|
-
try {
|
|
1851
|
-
let response;
|
|
1852
|
-
function onResponse(rawResponse, flatResponse) {
|
|
1853
|
-
response = rawResponse;
|
|
1854
|
-
if (options.onResponse) {
|
|
1855
|
-
options.onResponse(rawResponse, flatResponse);
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
await this._appInsightsClient.track(envelopes, Object.assign(Object.assign({}, options), { onResponse }));
|
|
1859
|
-
return { statusCode: response === null || response === void 0 ? void 0 : response.status, result: (_a = response === null || response === void 0 ? void 0 : response.bodyAsText) !== null && _a !== void 0 ? _a : "" };
|
|
1860
|
-
}
|
|
1861
|
-
catch (e) {
|
|
1862
|
-
throw e;
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
/**
|
|
1866
|
-
* Shutdown sender
|
|
1867
|
-
* @internal
|
|
1868
|
-
*/
|
|
1869
|
-
async shutdown() {
|
|
1870
|
-
api.diag.info("HttpSender shutting down");
|
|
1871
|
-
}
|
|
1872
|
-
handlePermanentRedirect(location) {
|
|
1873
|
-
if (location) {
|
|
1874
|
-
const locUrl = new url__default["default"].URL(location);
|
|
1875
|
-
if (locUrl && locUrl.host) {
|
|
1876
|
-
this._appInsightsClient.host = "https://" + locUrl.host;
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
// Copyright (c) Microsoft Corporation.
|
|
1883
|
-
let instance$1 = null;
|
|
1884
|
-
/**
|
|
1885
|
-
* Azure Telemetry context.
|
|
1886
|
-
* @internal
|
|
1887
|
-
*/
|
|
1888
|
-
class Context {
|
|
1889
|
-
constructor() {
|
|
1890
|
-
this.tags = {};
|
|
1891
|
-
this._loadDeviceContext();
|
|
1892
|
-
this._loadInternalContext();
|
|
1893
|
-
}
|
|
1894
|
-
_loadDeviceContext() {
|
|
1895
|
-
this.tags[KnownContextTagKeys.AiDeviceOsVersion] = os__namespace && `${os__namespace.type()} ${os__namespace.release()}`;
|
|
1896
|
-
}
|
|
1897
|
-
_loadInternalContext() {
|
|
1898
|
-
const { node } = process.versions;
|
|
1899
|
-
[Context.nodeVersion] = node.split(".");
|
|
1900
|
-
Context.opentelemetryVersion = core.SDK_INFO[semanticConventions.SemanticResourceAttributes.TELEMETRY_SDK_VERSION];
|
|
1901
|
-
Context.sdkVersion = packageVersion;
|
|
1902
|
-
let prefix = process.env["AZURE_MONITOR_AGENT_PREFIX"]
|
|
1903
|
-
? process.env["AZURE_MONITOR_AGENT_PREFIX"]
|
|
1904
|
-
: "";
|
|
1905
|
-
let version = process.env["AZURE_MONITOR_DISTRO_VERSION"]
|
|
1906
|
-
? `dst${process.env["AZURE_MONITOR_DISTRO_VERSION"]}`
|
|
1907
|
-
: `ext${Context.sdkVersion}`;
|
|
1908
|
-
let internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;
|
|
1909
|
-
this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
Context.sdkVersion = null;
|
|
1913
|
-
Context.opentelemetryVersion = null;
|
|
1914
|
-
Context.nodeVersion = "";
|
|
1915
|
-
/**
|
|
1916
|
-
* Singleton Context instance
|
|
1917
|
-
* @internal
|
|
1918
|
-
*/
|
|
1919
|
-
function getInstance$1() {
|
|
1920
|
-
if (!instance$1) {
|
|
1921
|
-
instance$1 = new Context();
|
|
1922
|
-
}
|
|
1923
|
-
return instance$1;
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
// Copyright (c) Microsoft Corporation.
|
|
1927
|
-
// Licensed under the MIT license.
|
|
1928
|
-
/**
|
|
1929
|
-
* Breeze retriable status codes.
|
|
1930
|
-
* @internal
|
|
1931
|
-
*/
|
|
1932
|
-
function isRetriable(statusCode) {
|
|
1933
|
-
return (statusCode === 206 || // Partial Accept
|
|
1934
|
-
statusCode === 401 || // Unauthorized
|
|
1935
|
-
statusCode === 403 || // Forbidden
|
|
1936
|
-
statusCode === 408 || // Timeout
|
|
1937
|
-
statusCode === 429 || // Too many requests
|
|
1938
|
-
statusCode === 439 || // Daily quota exceeded (legacy)
|
|
1939
|
-
statusCode === 500 || // Server Error
|
|
1940
|
-
statusCode === 502 || // Bad Gateway
|
|
1941
|
-
statusCode === 503 || // Server Unavailable
|
|
1942
|
-
statusCode === 504 // Gateway Timeout
|
|
1943
|
-
);
|
|
1944
|
-
}
|
|
1945
|
-
/**
|
|
1946
|
-
* Convert milliseconds to Breeze expected time.
|
|
1947
|
-
* @internal
|
|
1948
|
-
*/
|
|
1949
|
-
function msToTimeSpan(ms) {
|
|
1950
|
-
let totalms = ms;
|
|
1951
|
-
if (Number.isNaN(totalms) || totalms < 0 || !Number.isFinite(ms)) {
|
|
1952
|
-
totalms = 0;
|
|
1953
|
-
}
|
|
1954
|
-
let sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, "");
|
|
1955
|
-
let min = `${Math.floor(totalms / (1000 * 60)) % 60}`;
|
|
1956
|
-
let hour = `${Math.floor(totalms / (1000 * 60 * 60)) % 24}`;
|
|
1957
|
-
const days = Math.floor(totalms / (1000 * 60 * 60 * 24));
|
|
1958
|
-
sec = sec.indexOf(".") < 2 ? `0${sec}` : sec;
|
|
1959
|
-
min = min.length < 2 ? `0${min}` : min;
|
|
1960
|
-
hour = hour.length < 2 ? `0${hour}` : hour;
|
|
1961
|
-
const daysText = days > 0 ? `${days}.` : "";
|
|
1962
|
-
return `${daysText + hour}:${min}:${sec}`;
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
1871
|
class NetworkStatsbeat {
|
|
1966
1872
|
constructor(endpoint, host) {
|
|
1967
1873
|
this.endpoint = endpoint;
|
|
@@ -2109,60 +2015,178 @@ class StatsbeatMetrics {
|
|
|
2109
2015
|
}
|
|
2110
2016
|
|
|
2111
2017
|
// Copyright (c) Microsoft Corporation.
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
this._attach = "sdk";
|
|
2119
|
-
this._connectionString = super._getConnectionString(options.endpointUrl);
|
|
2120
|
-
this._networkStatsbeatMeterProvider = new sdkMetrics.MeterProvider();
|
|
2121
|
-
const exporterConfig = {
|
|
2122
|
-
connectionString: this._connectionString,
|
|
2123
|
-
};
|
|
2124
|
-
this._networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);
|
|
2125
|
-
// Exports Network Statsbeat every 15 minutes
|
|
2126
|
-
const networkMetricReaderOptions = {
|
|
2127
|
-
exporter: this._networkAzureExporter,
|
|
2128
|
-
exportIntervalMillis: options.networkCollectionInterval || this._statsCollectionShortInterval, // 15 minutes
|
|
2129
|
-
};
|
|
2130
|
-
this._networkMetricReader = new sdkMetrics.PeriodicExportingMetricReader(networkMetricReaderOptions);
|
|
2131
|
-
this._networkStatsbeatMeterProvider.addMetricReader(this._networkMetricReader);
|
|
2132
|
-
this._networkStatsbeatMeter = this._networkStatsbeatMeterProvider.getMeter("Azure Monitor Network Statsbeat");
|
|
2133
|
-
this._endpointUrl = options.endpointUrl;
|
|
2134
|
-
this._runtimeVersion = process.version;
|
|
2135
|
-
this._language = STATSBEAT_LANGUAGE;
|
|
2136
|
-
this._version = packageVersion;
|
|
2137
|
-
this._host = this._getShortHost(options.endpointUrl);
|
|
2138
|
-
this._cikey = options.instrumentationKey;
|
|
2139
|
-
this._successCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.SUCCESS_COUNT);
|
|
2140
|
-
this._failureCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.FAILURE_COUNT);
|
|
2141
|
-
this._retryCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.RETRY_COUNT);
|
|
2142
|
-
this._throttleCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.THROTTLE_COUNT);
|
|
2143
|
-
this._exceptionCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
|
|
2144
|
-
this._averageDurationGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
|
|
2145
|
-
this._commonProperties = {
|
|
2146
|
-
os: super._os,
|
|
2147
|
-
rp: super._resourceProvider,
|
|
2148
|
-
cikey: this._cikey,
|
|
2149
|
-
runtimeVersion: this._runtimeVersion,
|
|
2150
|
-
language: this._language,
|
|
2151
|
-
version: this._version,
|
|
2152
|
-
attach: this._attach,
|
|
2153
|
-
};
|
|
2154
|
-
this._networkProperties = {
|
|
2155
|
-
endpoint: this._endpointUrl,
|
|
2156
|
-
host: this._host,
|
|
2157
|
-
};
|
|
2158
|
-
this._isInitialized = true;
|
|
2159
|
-
this._initialize();
|
|
2018
|
+
function createPropertiesFromMetricAttributes(attributes) {
|
|
2019
|
+
const properties = {};
|
|
2020
|
+
if (attributes) {
|
|
2021
|
+
for (const key of Object.keys(attributes)) {
|
|
2022
|
+
properties[key] = attributes[key];
|
|
2023
|
+
}
|
|
2160
2024
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2025
|
+
return properties;
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Metric to Azure envelope parsing.
|
|
2029
|
+
* @internal
|
|
2030
|
+
*/
|
|
2031
|
+
function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
2032
|
+
let envelopes = [];
|
|
2033
|
+
const time = new Date();
|
|
2034
|
+
const instrumentationKey = ikey;
|
|
2035
|
+
const tags = createTagsFromResource(metrics.resource);
|
|
2036
|
+
let envelopeName;
|
|
2037
|
+
if (isStatsbeat) {
|
|
2038
|
+
envelopeName = "Microsoft.ApplicationInsights.Statsbeat";
|
|
2163
2039
|
}
|
|
2164
|
-
|
|
2165
|
-
|
|
2040
|
+
else {
|
|
2041
|
+
envelopeName = "Microsoft.ApplicationInsights.Metric";
|
|
2042
|
+
}
|
|
2043
|
+
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
2044
|
+
scopeMetric.metrics.forEach((metric) => {
|
|
2045
|
+
metric.dataPoints.forEach((dataPoint) => {
|
|
2046
|
+
let baseData = {
|
|
2047
|
+
metrics: [],
|
|
2048
|
+
version: 2,
|
|
2049
|
+
properties: {},
|
|
2050
|
+
};
|
|
2051
|
+
baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
|
|
2052
|
+
var metricDataPoint = {
|
|
2053
|
+
name: metric.descriptor.name,
|
|
2054
|
+
value: 0,
|
|
2055
|
+
dataPointType: "Aggregation",
|
|
2056
|
+
};
|
|
2057
|
+
if (metric.dataPointType == sdkMetrics.DataPointType.SUM ||
|
|
2058
|
+
metric.dataPointType == sdkMetrics.DataPointType.GAUGE) {
|
|
2059
|
+
metricDataPoint.value = dataPoint.value;
|
|
2060
|
+
metricDataPoint.count = 1;
|
|
2061
|
+
}
|
|
2062
|
+
else {
|
|
2063
|
+
metricDataPoint.value = dataPoint.value.sum || 0;
|
|
2064
|
+
metricDataPoint.count = dataPoint.value.count;
|
|
2065
|
+
metricDataPoint.max = dataPoint.value.max;
|
|
2066
|
+
metricDataPoint.min = dataPoint.value.min;
|
|
2067
|
+
}
|
|
2068
|
+
baseData.metrics.push(metricDataPoint);
|
|
2069
|
+
let envelope = {
|
|
2070
|
+
name: envelopeName,
|
|
2071
|
+
time: time,
|
|
2072
|
+
sampleRate: 100,
|
|
2073
|
+
instrumentationKey: instrumentationKey,
|
|
2074
|
+
tags: tags,
|
|
2075
|
+
version: 1,
|
|
2076
|
+
data: {
|
|
2077
|
+
baseType: "MetricData",
|
|
2078
|
+
baseData: Object.assign({}, baseData),
|
|
2079
|
+
},
|
|
2080
|
+
};
|
|
2081
|
+
envelopes.push(envelope);
|
|
2082
|
+
});
|
|
2083
|
+
});
|
|
2084
|
+
});
|
|
2085
|
+
return envelopes;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
// Copyright (c) Microsoft Corporation.
|
|
2089
|
+
/**
|
|
2090
|
+
* Azure Monitor Statsbeat Exporter
|
|
2091
|
+
*/
|
|
2092
|
+
class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
2093
|
+
/**
|
|
2094
|
+
* Initializes a new instance of the AzureMonitorStatsbeatExporter class.
|
|
2095
|
+
* @param options - Exporter configuration
|
|
2096
|
+
*/
|
|
2097
|
+
constructor(options) {
|
|
2098
|
+
super(options, true);
|
|
2099
|
+
/**
|
|
2100
|
+
* Flag to determine if the Exporter is shutdown.
|
|
2101
|
+
*/
|
|
2102
|
+
this._isShutdown = false;
|
|
2103
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Export Statsbeat metrics.
|
|
2107
|
+
*/
|
|
2108
|
+
async export(metrics, resultCallback) {
|
|
2109
|
+
if (this._isShutdown) {
|
|
2110
|
+
setTimeout(() => resultCallback({ code: core.ExportResultCode.FAILED }), 0);
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
let envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey, true // isStatsbeat flag passed to create a Statsbeat envelope.
|
|
2114
|
+
);
|
|
2115
|
+
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
2116
|
+
api.context.with(core.suppressTracing(api.context.active()), async () => {
|
|
2117
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Shutdown AzureMonitorStatsbeatExporter.
|
|
2122
|
+
*/
|
|
2123
|
+
async shutdown() {
|
|
2124
|
+
this._isShutdown = true;
|
|
2125
|
+
return this._sender.shutdown();
|
|
2126
|
+
}
|
|
2127
|
+
/**
|
|
2128
|
+
* Force flush.
|
|
2129
|
+
*/
|
|
2130
|
+
async forceFlush() {
|
|
2131
|
+
return Promise.resolve();
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
// Copyright (c) Microsoft Corporation.
|
|
2136
|
+
class NetworkStatsbeatMetrics extends StatsbeatMetrics {
|
|
2137
|
+
constructor(options) {
|
|
2138
|
+
super();
|
|
2139
|
+
this._isInitialized = false;
|
|
2140
|
+
this._statsCollectionShortInterval = 900000; // 15 minutes
|
|
2141
|
+
this._networkStatsbeatCollection = [];
|
|
2142
|
+
this._attach = "sdk";
|
|
2143
|
+
this._connectionString = super._getConnectionString(options.endpointUrl);
|
|
2144
|
+
this._networkStatsbeatMeterProvider = new sdkMetrics.MeterProvider();
|
|
2145
|
+
const exporterConfig = {
|
|
2146
|
+
connectionString: this._connectionString,
|
|
2147
|
+
};
|
|
2148
|
+
this._networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);
|
|
2149
|
+
// Exports Network Statsbeat every 15 minutes
|
|
2150
|
+
const networkMetricReaderOptions = {
|
|
2151
|
+
exporter: this._networkAzureExporter,
|
|
2152
|
+
exportIntervalMillis: options.networkCollectionInterval || this._statsCollectionShortInterval, // 15 minutes
|
|
2153
|
+
};
|
|
2154
|
+
this._networkMetricReader = new sdkMetrics.PeriodicExportingMetricReader(networkMetricReaderOptions);
|
|
2155
|
+
this._networkStatsbeatMeterProvider.addMetricReader(this._networkMetricReader);
|
|
2156
|
+
this._networkStatsbeatMeter = this._networkStatsbeatMeterProvider.getMeter("Azure Monitor Network Statsbeat");
|
|
2157
|
+
this._endpointUrl = options.endpointUrl;
|
|
2158
|
+
this._runtimeVersion = process.version;
|
|
2159
|
+
this._language = STATSBEAT_LANGUAGE;
|
|
2160
|
+
this._version = packageVersion;
|
|
2161
|
+
this._host = this._getShortHost(options.endpointUrl);
|
|
2162
|
+
this._cikey = options.instrumentationKey;
|
|
2163
|
+
this._successCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.SUCCESS_COUNT);
|
|
2164
|
+
this._failureCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.FAILURE_COUNT);
|
|
2165
|
+
this._retryCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.RETRY_COUNT);
|
|
2166
|
+
this._throttleCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.THROTTLE_COUNT);
|
|
2167
|
+
this._exceptionCountGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.EXCEPTION_COUNT);
|
|
2168
|
+
this._averageDurationGauge = this._networkStatsbeatMeter.createObservableGauge(StatsbeatCounter.AVERAGE_DURATION);
|
|
2169
|
+
this._commonProperties = {
|
|
2170
|
+
os: super._os,
|
|
2171
|
+
rp: super._resourceProvider,
|
|
2172
|
+
cikey: this._cikey,
|
|
2173
|
+
runtimeVersion: this._runtimeVersion,
|
|
2174
|
+
language: this._language,
|
|
2175
|
+
version: this._version,
|
|
2176
|
+
attach: this._attach,
|
|
2177
|
+
};
|
|
2178
|
+
this._networkProperties = {
|
|
2179
|
+
endpoint: this._endpointUrl,
|
|
2180
|
+
host: this._host,
|
|
2181
|
+
};
|
|
2182
|
+
this._isInitialized = true;
|
|
2183
|
+
this._initialize();
|
|
2184
|
+
}
|
|
2185
|
+
isInitialized() {
|
|
2186
|
+
return this._isInitialized;
|
|
2187
|
+
}
|
|
2188
|
+
shutdown() {
|
|
2189
|
+
this._networkStatsbeatMeterProvider.shutdown();
|
|
2166
2190
|
}
|
|
2167
2191
|
async _initialize() {
|
|
2168
2192
|
try {
|
|
@@ -2351,7 +2375,7 @@ class NetworkStatsbeatMetrics extends StatsbeatMetrics {
|
|
|
2351
2375
|
}
|
|
2352
2376
|
|
|
2353
2377
|
// Copyright (c) Microsoft Corporation.
|
|
2354
|
-
let instance = null;
|
|
2378
|
+
let instance$1 = null;
|
|
2355
2379
|
/**
|
|
2356
2380
|
* Long Interval Statsbeat Metrics
|
|
2357
2381
|
* @internal
|
|
@@ -2453,93 +2477,81 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
|
|
|
2453
2477
|
* Singleton LongIntervalStatsbeatMetrics instance.
|
|
2454
2478
|
* @internal
|
|
2455
2479
|
*/
|
|
2456
|
-
function getInstance(options) {
|
|
2457
|
-
if (!instance) {
|
|
2458
|
-
instance = new LongIntervalStatsbeatMetrics(options);
|
|
2480
|
+
function getInstance$1(options) {
|
|
2481
|
+
if (!instance$1) {
|
|
2482
|
+
instance$1 = new LongIntervalStatsbeatMetrics(options);
|
|
2459
2483
|
}
|
|
2460
|
-
return instance;
|
|
2484
|
+
return instance$1;
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
// Copyright (c) Microsoft Corporation.
|
|
2488
|
+
// Licensed under the MIT license.
|
|
2489
|
+
/**
|
|
2490
|
+
* Breeze retriable status codes.
|
|
2491
|
+
* @internal
|
|
2492
|
+
*/
|
|
2493
|
+
function isRetriable(statusCode) {
|
|
2494
|
+
return (statusCode === 206 || // Partial Accept
|
|
2495
|
+
statusCode === 401 || // Unauthorized
|
|
2496
|
+
statusCode === 403 || // Forbidden
|
|
2497
|
+
statusCode === 408 || // Timeout
|
|
2498
|
+
statusCode === 429 || // Too many requests
|
|
2499
|
+
statusCode === 439 || // Daily quota exceeded (legacy)
|
|
2500
|
+
statusCode === 500 || // Server Error
|
|
2501
|
+
statusCode === 502 || // Bad Gateway
|
|
2502
|
+
statusCode === 503 || // Server Unavailable
|
|
2503
|
+
statusCode === 504 // Gateway Timeout
|
|
2504
|
+
);
|
|
2505
|
+
}
|
|
2506
|
+
/**
|
|
2507
|
+
* Convert milliseconds to Breeze expected time.
|
|
2508
|
+
* @internal
|
|
2509
|
+
*/
|
|
2510
|
+
function msToTimeSpan(ms) {
|
|
2511
|
+
let totalms = ms;
|
|
2512
|
+
if (Number.isNaN(totalms) || totalms < 0 || !Number.isFinite(ms)) {
|
|
2513
|
+
totalms = 0;
|
|
2514
|
+
}
|
|
2515
|
+
let sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, "");
|
|
2516
|
+
let min = `${Math.floor(totalms / (1000 * 60)) % 60}`;
|
|
2517
|
+
let hour = `${Math.floor(totalms / (1000 * 60 * 60)) % 24}`;
|
|
2518
|
+
const days = Math.floor(totalms / (1000 * 60 * 60 * 24));
|
|
2519
|
+
sec = sec.indexOf(".") < 2 ? `0${sec}` : sec;
|
|
2520
|
+
min = min.length < 2 ? `0${min}` : min;
|
|
2521
|
+
hour = hour.length < 2 ? `0${hour}` : hour;
|
|
2522
|
+
const daysText = days > 0 ? `${days}.` : "";
|
|
2523
|
+
return `${daysText + hour}:${min}:${sec}`;
|
|
2461
2524
|
}
|
|
2462
2525
|
|
|
2463
2526
|
// Copyright (c) Microsoft Corporation.
|
|
2464
2527
|
const DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60000;
|
|
2465
2528
|
/**
|
|
2466
|
-
*
|
|
2529
|
+
* Base sender class
|
|
2530
|
+
* @internal
|
|
2467
2531
|
*/
|
|
2468
|
-
class
|
|
2469
|
-
|
|
2470
|
-
* Initializes a new instance of the AzureMonitorBaseExporter class.
|
|
2471
|
-
* @param AzureMonitorExporterOptions - Exporter configuration.
|
|
2472
|
-
*/
|
|
2473
|
-
constructor(options = {}, isStatsbeatExporter) {
|
|
2474
|
-
var _a;
|
|
2475
|
-
/**
|
|
2476
|
-
* Instrumentation key to be used for exported envelopes
|
|
2477
|
-
*/
|
|
2478
|
-
this._instrumentationKey = "";
|
|
2479
|
-
this._endpointUrl = "";
|
|
2532
|
+
class BaseSender {
|
|
2533
|
+
constructor(endpointUrl, instrumentationKey, trackStatsbeat, options = {}) {
|
|
2480
2534
|
this._statsbeatFailureCount = 0;
|
|
2481
2535
|
this._batchSendRetryIntervalMs = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;
|
|
2482
|
-
this._options = options;
|
|
2483
2536
|
this._numConsecutiveRedirects = 0;
|
|
2484
|
-
this.
|
|
2485
|
-
|
|
2486
|
-
const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];
|
|
2487
|
-
this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;
|
|
2488
|
-
if (connectionString) {
|
|
2489
|
-
const parsedConnectionString = ConnectionStringParser.parse(connectionString);
|
|
2490
|
-
this._instrumentationKey =
|
|
2491
|
-
parsedConnectionString.instrumentationkey || this._instrumentationKey;
|
|
2492
|
-
this._endpointUrl = ((_a = parsedConnectionString.ingestionendpoint) === null || _a === void 0 ? void 0 : _a.trim()) || this._endpointUrl;
|
|
2493
|
-
}
|
|
2494
|
-
// Instrumentation key is required
|
|
2495
|
-
if (!this._instrumentationKey) {
|
|
2496
|
-
const message = "No instrumentation key or connection string was provided to the Azure Monitor Exporter";
|
|
2497
|
-
api.diag.error(message);
|
|
2498
|
-
throw new Error(message);
|
|
2499
|
-
}
|
|
2500
|
-
this._sender = new HttpSender(this._endpointUrl, this._options);
|
|
2501
|
-
this._persister = new FileSystemPersist(this._instrumentationKey, this._options);
|
|
2502
|
-
if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) {
|
|
2537
|
+
this._persister = new FileSystemPersist(instrumentationKey, options);
|
|
2538
|
+
if (trackStatsbeat) {
|
|
2503
2539
|
// Initialize statsbeatMetrics
|
|
2504
2540
|
this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
|
|
2505
|
-
instrumentationKey:
|
|
2506
|
-
endpointUrl:
|
|
2541
|
+
instrumentationKey: instrumentationKey,
|
|
2542
|
+
endpointUrl: endpointUrl,
|
|
2507
2543
|
});
|
|
2508
|
-
this._longIntervalStatsbeatMetrics = getInstance({
|
|
2509
|
-
instrumentationKey:
|
|
2510
|
-
endpointUrl:
|
|
2544
|
+
this._longIntervalStatsbeatMetrics = getInstance$1({
|
|
2545
|
+
instrumentationKey: instrumentationKey,
|
|
2546
|
+
endpointUrl: endpointUrl,
|
|
2511
2547
|
});
|
|
2512
2548
|
}
|
|
2513
2549
|
this._retryTimer = null;
|
|
2514
|
-
api.diag.debug("AzureMonitorExporter was successfully setup");
|
|
2515
|
-
}
|
|
2516
|
-
/**
|
|
2517
|
-
* Persist envelopes to disk
|
|
2518
|
-
*/
|
|
2519
|
-
async _persist(envelopes) {
|
|
2520
|
-
try {
|
|
2521
|
-
const success = await this._persister.push(envelopes);
|
|
2522
|
-
return success
|
|
2523
|
-
? { code: core.ExportResultCode.SUCCESS }
|
|
2524
|
-
: {
|
|
2525
|
-
code: core.ExportResultCode.FAILED,
|
|
2526
|
-
error: new Error("Failed to persist envelope in disk."),
|
|
2527
|
-
};
|
|
2528
|
-
}
|
|
2529
|
-
catch (ex) {
|
|
2530
|
-
return { code: core.ExportResultCode.FAILED, error: ex };
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
/**
|
|
2534
|
-
* Shutdown exporter
|
|
2535
|
-
*/
|
|
2536
|
-
async _shutdown() {
|
|
2537
|
-
return this._sender.shutdown();
|
|
2538
2550
|
}
|
|
2539
2551
|
/**
|
|
2540
2552
|
* Export envelopes
|
|
2541
2553
|
*/
|
|
2542
|
-
async
|
|
2554
|
+
async exportEnvelopes(envelopes) {
|
|
2543
2555
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2544
2556
|
api.diag.info(`Exporting ${envelopes.length} envelope(s)`);
|
|
2545
2557
|
if (envelopes.length < 1) {
|
|
@@ -2547,7 +2559,7 @@ class AzureMonitorBaseExporter {
|
|
|
2547
2559
|
}
|
|
2548
2560
|
try {
|
|
2549
2561
|
const startTime = new Date().getTime();
|
|
2550
|
-
const { result, statusCode } = await this.
|
|
2562
|
+
const { result, statusCode } = await this.send(envelopes);
|
|
2551
2563
|
const endTime = new Date().getTime();
|
|
2552
2564
|
const duration = endTime - startTime;
|
|
2553
2565
|
this._numConsecutiveRedirects = 0;
|
|
@@ -2625,9 +2637,9 @@ class AzureMonitorBaseExporter {
|
|
|
2625
2637
|
const location = restError.response.headers.get("location");
|
|
2626
2638
|
if (location) {
|
|
2627
2639
|
// Update sender URL
|
|
2628
|
-
this.
|
|
2640
|
+
this.handlePermanentRedirect(location);
|
|
2629
2641
|
// Send to redirect endpoint as HTTPs library doesn't handle redirect automatically
|
|
2630
|
-
return this.
|
|
2642
|
+
return this.exportEnvelopes(envelopes);
|
|
2631
2643
|
}
|
|
2632
2644
|
}
|
|
2633
2645
|
}
|
|
@@ -2653,12 +2665,28 @@ class AzureMonitorBaseExporter {
|
|
|
2653
2665
|
return { code: core.ExportResultCode.FAILED, error: restError };
|
|
2654
2666
|
}
|
|
2655
2667
|
}
|
|
2668
|
+
/**
|
|
2669
|
+
* Persist envelopes to disk
|
|
2670
|
+
*/
|
|
2671
|
+
async _persist(envelopes) {
|
|
2672
|
+
try {
|
|
2673
|
+
const success = await this._persister.push(envelopes);
|
|
2674
|
+
return success
|
|
2675
|
+
? { code: core.ExportResultCode.SUCCESS }
|
|
2676
|
+
: {
|
|
2677
|
+
code: core.ExportResultCode.FAILED,
|
|
2678
|
+
error: new Error("Failed to persist envelope in disk."),
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
catch (ex) {
|
|
2682
|
+
return { code: core.ExportResultCode.FAILED, error: ex };
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2656
2685
|
// Disable collection of statsbeat metrics after max failures
|
|
2657
2686
|
_incrementStatsbeatFailure() {
|
|
2658
2687
|
var _a, _b;
|
|
2659
2688
|
this._statsbeatFailureCount++;
|
|
2660
2689
|
if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {
|
|
2661
|
-
this._isStatsbeatExporter = false;
|
|
2662
2690
|
(_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
|
|
2663
2691
|
(_b = this._longIntervalStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.shutdown();
|
|
2664
2692
|
this._networkStatsbeatMetrics = undefined;
|
|
@@ -2669,7 +2697,7 @@ class AzureMonitorBaseExporter {
|
|
|
2669
2697
|
try {
|
|
2670
2698
|
const envelopes = (await this._persister.shift());
|
|
2671
2699
|
if (envelopes) {
|
|
2672
|
-
await this.
|
|
2700
|
+
await this.send(envelopes);
|
|
2673
2701
|
}
|
|
2674
2702
|
}
|
|
2675
2703
|
catch (err) {
|
|
@@ -2684,9 +2712,111 @@ class AzureMonitorBaseExporter {
|
|
|
2684
2712
|
}
|
|
2685
2713
|
}
|
|
2686
2714
|
|
|
2715
|
+
// Copyright (c) Microsoft Corporation.
|
|
2716
|
+
const applicationInsightsResource = "https://monitor.azure.com//.default";
|
|
2717
|
+
/**
|
|
2718
|
+
* Exporter HTTP sender class
|
|
2719
|
+
* @internal
|
|
2720
|
+
*/
|
|
2721
|
+
class HttpSender extends BaseSender {
|
|
2722
|
+
constructor(endpointUrl, instrumentationKey, trackStatsbeat, options) {
|
|
2723
|
+
super(endpointUrl, instrumentationKey, trackStatsbeat, options);
|
|
2724
|
+
// Build endpoint using provided configuration or default values
|
|
2725
|
+
this._appInsightsClientOptions = Object.assign({ host: endpointUrl }, options);
|
|
2726
|
+
if (options === null || options === void 0 ? void 0 : options.credential) {
|
|
2727
|
+
// Add credentialScopes
|
|
2728
|
+
options.credentialScopes = [applicationInsightsResource];
|
|
2729
|
+
}
|
|
2730
|
+
this._appInsightsClient = new ApplicationInsightsClient(this._appInsightsClientOptions);
|
|
2731
|
+
// Handle redirects in HTTP Sender
|
|
2732
|
+
this._appInsightsClient.pipeline.removePolicy({ name: coreRestPipeline.redirectPolicyName });
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Send Azure envelopes
|
|
2736
|
+
* @internal
|
|
2737
|
+
*/
|
|
2738
|
+
async send(envelopes) {
|
|
2739
|
+
var _a;
|
|
2740
|
+
let options = {};
|
|
2741
|
+
try {
|
|
2742
|
+
let response;
|
|
2743
|
+
function onResponse(rawResponse, flatResponse) {
|
|
2744
|
+
response = rawResponse;
|
|
2745
|
+
if (options.onResponse) {
|
|
2746
|
+
options.onResponse(rawResponse, flatResponse);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
await this._appInsightsClient.track(envelopes, Object.assign(Object.assign({}, options), { onResponse }));
|
|
2750
|
+
return { statusCode: response === null || response === void 0 ? void 0 : response.status, result: (_a = response === null || response === void 0 ? void 0 : response.bodyAsText) !== null && _a !== void 0 ? _a : "" };
|
|
2751
|
+
}
|
|
2752
|
+
catch (e) {
|
|
2753
|
+
throw e;
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
/**
|
|
2757
|
+
* Shutdown sender
|
|
2758
|
+
* @internal
|
|
2759
|
+
*/
|
|
2760
|
+
async shutdown() {
|
|
2761
|
+
api.diag.info("HttpSender shutting down");
|
|
2762
|
+
}
|
|
2763
|
+
handlePermanentRedirect(location) {
|
|
2764
|
+
if (location) {
|
|
2765
|
+
const locUrl = new url__default["default"].URL(location);
|
|
2766
|
+
if (locUrl && locUrl.host) {
|
|
2767
|
+
this._appInsightsClient.host = "https://" + locUrl.host;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
// Copyright (c) Microsoft Corporation.
|
|
2774
|
+
let instance = null;
|
|
2775
|
+
/**
|
|
2776
|
+
* Azure Telemetry context.
|
|
2777
|
+
* @internal
|
|
2778
|
+
*/
|
|
2779
|
+
class Context {
|
|
2780
|
+
constructor() {
|
|
2781
|
+
this.tags = {};
|
|
2782
|
+
this._loadDeviceContext();
|
|
2783
|
+
this._loadInternalContext();
|
|
2784
|
+
}
|
|
2785
|
+
_loadDeviceContext() {
|
|
2786
|
+
this.tags[KnownContextTagKeys.AiDeviceOsVersion] = os__namespace && `${os__namespace.type()} ${os__namespace.release()}`;
|
|
2787
|
+
}
|
|
2788
|
+
_loadInternalContext() {
|
|
2789
|
+
const { node } = process.versions;
|
|
2790
|
+
[Context.nodeVersion] = node.split(".");
|
|
2791
|
+
Context.opentelemetryVersion = core.SDK_INFO[semanticConventions.SemanticResourceAttributes.TELEMETRY_SDK_VERSION];
|
|
2792
|
+
Context.sdkVersion = packageVersion;
|
|
2793
|
+
let prefix = process.env["AZURE_MONITOR_AGENT_PREFIX"]
|
|
2794
|
+
? process.env["AZURE_MONITOR_AGENT_PREFIX"]
|
|
2795
|
+
: "";
|
|
2796
|
+
let version = process.env["AZURE_MONITOR_DISTRO_VERSION"]
|
|
2797
|
+
? `dst${process.env["AZURE_MONITOR_DISTRO_VERSION"]}`
|
|
2798
|
+
: `ext${Context.sdkVersion}`;
|
|
2799
|
+
let internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;
|
|
2800
|
+
this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
Context.sdkVersion = null;
|
|
2804
|
+
Context.opentelemetryVersion = null;
|
|
2805
|
+
Context.nodeVersion = "";
|
|
2806
|
+
/**
|
|
2807
|
+
* Singleton Context instance
|
|
2808
|
+
* @internal
|
|
2809
|
+
*/
|
|
2810
|
+
function getInstance() {
|
|
2811
|
+
if (!instance) {
|
|
2812
|
+
instance = new Context();
|
|
2813
|
+
}
|
|
2814
|
+
return instance;
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2687
2817
|
// Copyright (c) Microsoft Corporation.
|
|
2688
2818
|
function createTagsFromResource(resource) {
|
|
2689
|
-
const context = getInstance
|
|
2819
|
+
const context = getInstance();
|
|
2690
2820
|
const tags = Object.assign({}, context.tags);
|
|
2691
2821
|
if (resource && resource.attributes) {
|
|
2692
2822
|
tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);
|
|
@@ -2854,18 +2984,20 @@ function createResourceMetricEnvelope(resource, instrumentationKey) {
|
|
|
2854
2984
|
}
|
|
2855
2985
|
// Only send event when resource attributes are available
|
|
2856
2986
|
if (Object.keys(resourceAttributes).length > 0) {
|
|
2987
|
+
let baseData = {
|
|
2988
|
+
version: 2,
|
|
2989
|
+
metrics: [{ name: "_OTELRESOURCE_", value: 1 }],
|
|
2990
|
+
properties: resourceAttributes,
|
|
2991
|
+
};
|
|
2857
2992
|
let envelope = {
|
|
2858
|
-
name: "
|
|
2993
|
+
name: "Microsoft.ApplicationInsights.Metric",
|
|
2859
2994
|
time: new Date(),
|
|
2860
2995
|
sampleRate: 100,
|
|
2861
2996
|
instrumentationKey: instrumentationKey,
|
|
2862
2997
|
version: 1,
|
|
2863
2998
|
data: {
|
|
2864
2999
|
baseType: "MetricData",
|
|
2865
|
-
baseData:
|
|
2866
|
-
version: 2,
|
|
2867
|
-
properties: resourceAttributes,
|
|
2868
|
-
},
|
|
3000
|
+
baseData: baseData,
|
|
2869
3001
|
},
|
|
2870
3002
|
tags: tags,
|
|
2871
3003
|
};
|
|
@@ -3319,6 +3451,7 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3319
3451
|
* Flag to determine if Exporter is shutdown.
|
|
3320
3452
|
*/
|
|
3321
3453
|
this._isShutdown = false;
|
|
3454
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
3322
3455
|
api.diag.debug("AzureMonitorTraceExporter was successfully setup");
|
|
3323
3456
|
}
|
|
3324
3457
|
/**
|
|
@@ -3335,18 +3468,18 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3335
3468
|
api.diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);
|
|
3336
3469
|
if (spans.length > 0) {
|
|
3337
3470
|
let envelopes = [];
|
|
3338
|
-
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.
|
|
3471
|
+
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.instrumentationKey);
|
|
3339
3472
|
if (resourceMetricEnvelope) {
|
|
3340
3473
|
envelopes.push(resourceMetricEnvelope);
|
|
3341
3474
|
}
|
|
3342
3475
|
spans.forEach((span) => {
|
|
3343
|
-
envelopes.push(readableSpanToEnvelope(span, this.
|
|
3344
|
-
let spanEventEnvelopes = spanEventsToEnvelopes(span, this.
|
|
3476
|
+
envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));
|
|
3477
|
+
let spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);
|
|
3345
3478
|
if (spanEventEnvelopes.length > 0) {
|
|
3346
3479
|
envelopes.push(...spanEventEnvelopes);
|
|
3347
3480
|
}
|
|
3348
3481
|
});
|
|
3349
|
-
resultCallback(await this.
|
|
3482
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
3350
3483
|
}
|
|
3351
3484
|
// No data to export
|
|
3352
3485
|
resultCallback({ code: core.ExportResultCode.SUCCESS });
|
|
@@ -3357,79 +3490,8 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3357
3490
|
async shutdown() {
|
|
3358
3491
|
this._isShutdown = true;
|
|
3359
3492
|
api.diag.info("AzureMonitorTraceExporter shutting down");
|
|
3360
|
-
return this.
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
|
|
3364
|
-
// Copyright (c) Microsoft Corporation.
|
|
3365
|
-
function createPropertiesFromMetricAttributes(attributes) {
|
|
3366
|
-
const properties = {};
|
|
3367
|
-
if (attributes) {
|
|
3368
|
-
for (const key of Object.keys(attributes)) {
|
|
3369
|
-
properties[key] = attributes[key];
|
|
3370
|
-
}
|
|
3371
|
-
}
|
|
3372
|
-
return properties;
|
|
3373
|
-
}
|
|
3374
|
-
/**
|
|
3375
|
-
* Metric to Azure envelope parsing.
|
|
3376
|
-
* @internal
|
|
3377
|
-
*/
|
|
3378
|
-
function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
3379
|
-
let envelopes = [];
|
|
3380
|
-
const time = new Date();
|
|
3381
|
-
const instrumentationKey = ikey;
|
|
3382
|
-
const tags = createTagsFromResource(metrics.resource);
|
|
3383
|
-
let envelopeName;
|
|
3384
|
-
if (isStatsbeat) {
|
|
3385
|
-
envelopeName = "Microsoft.ApplicationInsights.Statsbeat";
|
|
3386
|
-
}
|
|
3387
|
-
else {
|
|
3388
|
-
envelopeName = "Microsoft.ApplicationInsights.Metric";
|
|
3493
|
+
return this._sender.shutdown();
|
|
3389
3494
|
}
|
|
3390
|
-
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
3391
|
-
scopeMetric.metrics.forEach((metric) => {
|
|
3392
|
-
metric.dataPoints.forEach((dataPoint) => {
|
|
3393
|
-
let baseData = {
|
|
3394
|
-
metrics: [],
|
|
3395
|
-
version: 2,
|
|
3396
|
-
properties: {},
|
|
3397
|
-
};
|
|
3398
|
-
baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
|
|
3399
|
-
var metricDataPoint = {
|
|
3400
|
-
name: metric.descriptor.name,
|
|
3401
|
-
value: 0,
|
|
3402
|
-
dataPointType: "Aggregation",
|
|
3403
|
-
};
|
|
3404
|
-
if (metric.dataPointType == sdkMetrics.DataPointType.SUM ||
|
|
3405
|
-
metric.dataPointType == sdkMetrics.DataPointType.GAUGE) {
|
|
3406
|
-
metricDataPoint.value = dataPoint.value;
|
|
3407
|
-
metricDataPoint.count = 1;
|
|
3408
|
-
}
|
|
3409
|
-
else {
|
|
3410
|
-
metricDataPoint.value = dataPoint.value.sum || 0;
|
|
3411
|
-
metricDataPoint.count = dataPoint.value.count;
|
|
3412
|
-
metricDataPoint.max = dataPoint.value.max;
|
|
3413
|
-
metricDataPoint.min = dataPoint.value.min;
|
|
3414
|
-
}
|
|
3415
|
-
baseData.metrics.push(metricDataPoint);
|
|
3416
|
-
let envelope = {
|
|
3417
|
-
name: envelopeName,
|
|
3418
|
-
time: time,
|
|
3419
|
-
sampleRate: 100,
|
|
3420
|
-
instrumentationKey: instrumentationKey,
|
|
3421
|
-
tags: tags,
|
|
3422
|
-
version: 1,
|
|
3423
|
-
data: {
|
|
3424
|
-
baseType: "MetricData",
|
|
3425
|
-
baseData: Object.assign({}, baseData),
|
|
3426
|
-
},
|
|
3427
|
-
};
|
|
3428
|
-
envelopes.push(envelope);
|
|
3429
|
-
});
|
|
3430
|
-
});
|
|
3431
|
-
});
|
|
3432
|
-
return envelopes;
|
|
3433
3495
|
}
|
|
3434
3496
|
|
|
3435
3497
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -3447,7 +3509,7 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3447
3509
|
* Flag to determine if Exporter is shutdown.
|
|
3448
3510
|
*/
|
|
3449
3511
|
this._isShutdown = false;
|
|
3450
|
-
this.
|
|
3512
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
3451
3513
|
api.diag.debug("AzureMonitorMetricExporter was successfully setup");
|
|
3452
3514
|
}
|
|
3453
3515
|
/**
|
|
@@ -3462,10 +3524,10 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3462
3524
|
return;
|
|
3463
3525
|
}
|
|
3464
3526
|
api.diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);
|
|
3465
|
-
let envelopes = resourceMetricsToEnvelope(metrics, this.
|
|
3527
|
+
let envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey);
|
|
3466
3528
|
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
3467
3529
|
api.context.with(core.suppressTracing(api.context.active()), async () => {
|
|
3468
|
-
resultCallback(await this.
|
|
3530
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
3469
3531
|
});
|
|
3470
3532
|
}
|
|
3471
3533
|
/**
|
|
@@ -3474,13 +3536,17 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3474
3536
|
async shutdown() {
|
|
3475
3537
|
this._isShutdown = true;
|
|
3476
3538
|
api.diag.info("AzureMonitorMetricExporter shutting down");
|
|
3477
|
-
return this.
|
|
3539
|
+
return this._sender.shutdown();
|
|
3478
3540
|
}
|
|
3479
3541
|
/**
|
|
3480
3542
|
* Select aggregation temporality
|
|
3481
3543
|
*/
|
|
3482
|
-
selectAggregationTemporality(
|
|
3483
|
-
|
|
3544
|
+
selectAggregationTemporality(instrumentType) {
|
|
3545
|
+
if (instrumentType == sdkMetrics.InstrumentType.UP_DOWN_COUNTER ||
|
|
3546
|
+
instrumentType == sdkMetrics.InstrumentType.OBSERVABLE_UP_DOWN_COUNTER) {
|
|
3547
|
+
return sdkMetrics.AggregationTemporality.CUMULATIVE;
|
|
3548
|
+
}
|
|
3549
|
+
return sdkMetrics.AggregationTemporality.DELTA;
|
|
3484
3550
|
}
|
|
3485
3551
|
/**
|
|
3486
3552
|
* Force flush
|
|
@@ -3652,6 +3718,9 @@ function getLegacyApplicationInsightsBaseData(log) {
|
|
|
3652
3718
|
baseData = JSON.parse(log.body);
|
|
3653
3719
|
break;
|
|
3654
3720
|
}
|
|
3721
|
+
if (typeof (baseData === null || baseData === void 0 ? void 0 : baseData.message) === "object") {
|
|
3722
|
+
baseData.message = JSON.stringify(baseData.message);
|
|
3723
|
+
}
|
|
3655
3724
|
}
|
|
3656
3725
|
catch (err) {
|
|
3657
3726
|
api.diag.error("AzureMonitorLogExporter failed to parse Application Insights Telemetry");
|
|
@@ -3675,6 +3744,7 @@ class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
3675
3744
|
* Flag to determine if Exporter is shutdown.
|
|
3676
3745
|
*/
|
|
3677
3746
|
this._isShutdown = false;
|
|
3747
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
3678
3748
|
api.diag.debug("AzureMonitorLogExporter was successfully setup");
|
|
3679
3749
|
}
|
|
3680
3750
|
/**
|
|
@@ -3691,12 +3761,12 @@ class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
3691
3761
|
api.diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);
|
|
3692
3762
|
let envelopes = [];
|
|
3693
3763
|
logs.forEach((log) => {
|
|
3694
|
-
let envelope = logToEnvelope(log, this.
|
|
3764
|
+
let envelope = logToEnvelope(log, this.instrumentationKey);
|
|
3695
3765
|
if (envelope) {
|
|
3696
3766
|
envelopes.push(envelope);
|
|
3697
3767
|
}
|
|
3698
3768
|
});
|
|
3699
|
-
resultCallback(await this.
|
|
3769
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
3700
3770
|
}
|
|
3701
3771
|
/**
|
|
3702
3772
|
* Shutdown AzureMonitorLogExporter.
|
|
@@ -3704,53 +3774,7 @@ class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
3704
3774
|
async shutdown() {
|
|
3705
3775
|
this._isShutdown = true;
|
|
3706
3776
|
api.diag.info("AzureMonitorLogExporter shutting down");
|
|
3707
|
-
return this.
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
|
|
3711
|
-
// Copyright (c) Microsoft Corporation.
|
|
3712
|
-
/**
|
|
3713
|
-
* Azure Monitor Statsbeat Exporter
|
|
3714
|
-
*/
|
|
3715
|
-
class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
3716
|
-
/**
|
|
3717
|
-
* Initializes a new instance of the AzureMonitorStatsbeatExporter class.
|
|
3718
|
-
* @param options - Exporter configuration
|
|
3719
|
-
*/
|
|
3720
|
-
constructor(options) {
|
|
3721
|
-
super(options, true);
|
|
3722
|
-
/**
|
|
3723
|
-
* Flag to determine if the Exporter is shutdown.
|
|
3724
|
-
*/
|
|
3725
|
-
this._isShutdown = false;
|
|
3726
|
-
}
|
|
3727
|
-
/**
|
|
3728
|
-
* Export Statsbeat metrics.
|
|
3729
|
-
*/
|
|
3730
|
-
async export(metrics, resultCallback) {
|
|
3731
|
-
if (this._isShutdown) {
|
|
3732
|
-
setTimeout(() => resultCallback({ code: core.ExportResultCode.FAILED }), 0);
|
|
3733
|
-
return;
|
|
3734
|
-
}
|
|
3735
|
-
let envelopes = resourceMetricsToEnvelope(metrics, this._instrumentationKey, true // isStatsbeat flag passed to create a Statsbeat envelope.
|
|
3736
|
-
);
|
|
3737
|
-
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
3738
|
-
api.context.with(core.suppressTracing(api.context.active()), async () => {
|
|
3739
|
-
resultCallback(await this._exportEnvelopes(envelopes));
|
|
3740
|
-
});
|
|
3741
|
-
}
|
|
3742
|
-
/**
|
|
3743
|
-
* Shutdown AzureMonitorStatsbeatExporter.
|
|
3744
|
-
*/
|
|
3745
|
-
async shutdown() {
|
|
3746
|
-
this._isShutdown = true;
|
|
3747
|
-
return this._shutdown();
|
|
3748
|
-
}
|
|
3749
|
-
/**
|
|
3750
|
-
* Force flush.
|
|
3751
|
-
*/
|
|
3752
|
-
async forceFlush() {
|
|
3753
|
-
return Promise.resolve();
|
|
3777
|
+
return this._sender.shutdown();
|
|
3754
3778
|
}
|
|
3755
3779
|
}
|
|
3756
3780
|
|
|
@@ -3758,6 +3782,5 @@ exports.ApplicationInsightsSampler = ApplicationInsightsSampler;
|
|
|
3758
3782
|
exports.AzureMonitorBaseExporter = AzureMonitorBaseExporter;
|
|
3759
3783
|
exports.AzureMonitorLogExporter = AzureMonitorLogExporter;
|
|
3760
3784
|
exports.AzureMonitorMetricExporter = AzureMonitorMetricExporter;
|
|
3761
|
-
exports.AzureMonitorStatsbeatExporter = AzureMonitorStatsbeatExporter;
|
|
3762
3785
|
exports.AzureMonitorTraceExporter = AzureMonitorTraceExporter;
|
|
3763
3786
|
//# sourceMappingURL=index.js.map
|