@azure/monitor-opentelemetry-exporter 1.0.0-beta.14 → 1.0.0-beta.16
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 +433 -412
- 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 +10 -5
- package/dist-esm/src/export/log.js.map +1 -1
- package/dist-esm/src/export/metric.js +8 -6
- 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 +1 -1
- package/dist-esm/src/utils/common.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +1 -1
- 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 -93
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.16";
|
|
70
70
|
var DependencyTypes;
|
|
71
71
|
(function (DependencyTypes) {
|
|
72
72
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -95,6 +95,10 @@ const ApplicationInsightsEventBaseType = "EventData";
|
|
|
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.16`;
|
|
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);
|
|
@@ -2856,7 +2986,7 @@ function createResourceMetricEnvelope(resource, instrumentationKey) {
|
|
|
2856
2986
|
if (Object.keys(resourceAttributes).length > 0) {
|
|
2857
2987
|
let baseData = {
|
|
2858
2988
|
version: 2,
|
|
2859
|
-
metrics: [{ name: "
|
|
2989
|
+
metrics: [{ name: "_OTELRESOURCE_", value: 1 }],
|
|
2860
2990
|
properties: resourceAttributes,
|
|
2861
2991
|
};
|
|
2862
2992
|
let envelope = {
|
|
@@ -3321,6 +3451,7 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3321
3451
|
* Flag to determine if Exporter is shutdown.
|
|
3322
3452
|
*/
|
|
3323
3453
|
this._isShutdown = false;
|
|
3454
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
3324
3455
|
api.diag.debug("AzureMonitorTraceExporter was successfully setup");
|
|
3325
3456
|
}
|
|
3326
3457
|
/**
|
|
@@ -3337,18 +3468,18 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3337
3468
|
api.diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);
|
|
3338
3469
|
if (spans.length > 0) {
|
|
3339
3470
|
let envelopes = [];
|
|
3340
|
-
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.
|
|
3471
|
+
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.instrumentationKey);
|
|
3341
3472
|
if (resourceMetricEnvelope) {
|
|
3342
3473
|
envelopes.push(resourceMetricEnvelope);
|
|
3343
3474
|
}
|
|
3344
3475
|
spans.forEach((span) => {
|
|
3345
|
-
envelopes.push(readableSpanToEnvelope(span, this.
|
|
3346
|
-
let spanEventEnvelopes = spanEventsToEnvelopes(span, this.
|
|
3476
|
+
envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));
|
|
3477
|
+
let spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);
|
|
3347
3478
|
if (spanEventEnvelopes.length > 0) {
|
|
3348
3479
|
envelopes.push(...spanEventEnvelopes);
|
|
3349
3480
|
}
|
|
3350
3481
|
});
|
|
3351
|
-
resultCallback(await this.
|
|
3482
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
3352
3483
|
}
|
|
3353
3484
|
// No data to export
|
|
3354
3485
|
resultCallback({ code: core.ExportResultCode.SUCCESS });
|
|
@@ -3359,79 +3490,8 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3359
3490
|
async shutdown() {
|
|
3360
3491
|
this._isShutdown = true;
|
|
3361
3492
|
api.diag.info("AzureMonitorTraceExporter shutting down");
|
|
3362
|
-
return this.
|
|
3363
|
-
}
|
|
3364
|
-
}
|
|
3365
|
-
|
|
3366
|
-
// Copyright (c) Microsoft Corporation.
|
|
3367
|
-
function createPropertiesFromMetricAttributes(attributes) {
|
|
3368
|
-
const properties = {};
|
|
3369
|
-
if (attributes) {
|
|
3370
|
-
for (const key of Object.keys(attributes)) {
|
|
3371
|
-
properties[key] = attributes[key];
|
|
3372
|
-
}
|
|
3493
|
+
return this._sender.shutdown();
|
|
3373
3494
|
}
|
|
3374
|
-
return properties;
|
|
3375
|
-
}
|
|
3376
|
-
/**
|
|
3377
|
-
* Metric to Azure envelope parsing.
|
|
3378
|
-
* @internal
|
|
3379
|
-
*/
|
|
3380
|
-
function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
3381
|
-
let envelopes = [];
|
|
3382
|
-
const time = new Date();
|
|
3383
|
-
const instrumentationKey = ikey;
|
|
3384
|
-
const tags = createTagsFromResource(metrics.resource);
|
|
3385
|
-
let envelopeName;
|
|
3386
|
-
if (isStatsbeat) {
|
|
3387
|
-
envelopeName = "Microsoft.ApplicationInsights.Statsbeat";
|
|
3388
|
-
}
|
|
3389
|
-
else {
|
|
3390
|
-
envelopeName = "Microsoft.ApplicationInsights.Metric";
|
|
3391
|
-
}
|
|
3392
|
-
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
3393
|
-
scopeMetric.metrics.forEach((metric) => {
|
|
3394
|
-
metric.dataPoints.forEach((dataPoint) => {
|
|
3395
|
-
let baseData = {
|
|
3396
|
-
metrics: [],
|
|
3397
|
-
version: 2,
|
|
3398
|
-
properties: {},
|
|
3399
|
-
};
|
|
3400
|
-
baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
|
|
3401
|
-
var metricDataPoint = {
|
|
3402
|
-
name: metric.descriptor.name,
|
|
3403
|
-
value: 0,
|
|
3404
|
-
dataPointType: "Aggregation",
|
|
3405
|
-
};
|
|
3406
|
-
if (metric.dataPointType == sdkMetrics.DataPointType.SUM ||
|
|
3407
|
-
metric.dataPointType == sdkMetrics.DataPointType.GAUGE) {
|
|
3408
|
-
metricDataPoint.value = dataPoint.value;
|
|
3409
|
-
metricDataPoint.count = 1;
|
|
3410
|
-
}
|
|
3411
|
-
else {
|
|
3412
|
-
metricDataPoint.value = dataPoint.value.sum || 0;
|
|
3413
|
-
metricDataPoint.count = dataPoint.value.count;
|
|
3414
|
-
metricDataPoint.max = dataPoint.value.max;
|
|
3415
|
-
metricDataPoint.min = dataPoint.value.min;
|
|
3416
|
-
}
|
|
3417
|
-
baseData.metrics.push(metricDataPoint);
|
|
3418
|
-
let envelope = {
|
|
3419
|
-
name: envelopeName,
|
|
3420
|
-
time: time,
|
|
3421
|
-
sampleRate: 100,
|
|
3422
|
-
instrumentationKey: instrumentationKey,
|
|
3423
|
-
tags: tags,
|
|
3424
|
-
version: 1,
|
|
3425
|
-
data: {
|
|
3426
|
-
baseType: "MetricData",
|
|
3427
|
-
baseData: Object.assign({}, baseData),
|
|
3428
|
-
},
|
|
3429
|
-
};
|
|
3430
|
-
envelopes.push(envelope);
|
|
3431
|
-
});
|
|
3432
|
-
});
|
|
3433
|
-
});
|
|
3434
|
-
return envelopes;
|
|
3435
3495
|
}
|
|
3436
3496
|
|
|
3437
3497
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -3449,6 +3509,7 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3449
3509
|
* Flag to determine if Exporter is shutdown.
|
|
3450
3510
|
*/
|
|
3451
3511
|
this._isShutdown = false;
|
|
3512
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
3452
3513
|
api.diag.debug("AzureMonitorMetricExporter was successfully setup");
|
|
3453
3514
|
}
|
|
3454
3515
|
/**
|
|
@@ -3463,10 +3524,10 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3463
3524
|
return;
|
|
3464
3525
|
}
|
|
3465
3526
|
api.diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);
|
|
3466
|
-
let envelopes = resourceMetricsToEnvelope(metrics, this.
|
|
3527
|
+
let envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey);
|
|
3467
3528
|
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
3468
3529
|
api.context.with(core.suppressTracing(api.context.active()), async () => {
|
|
3469
|
-
resultCallback(await this.
|
|
3530
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
3470
3531
|
});
|
|
3471
3532
|
}
|
|
3472
3533
|
/**
|
|
@@ -3475,14 +3536,14 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3475
3536
|
async shutdown() {
|
|
3476
3537
|
this._isShutdown = true;
|
|
3477
3538
|
api.diag.info("AzureMonitorMetricExporter shutting down");
|
|
3478
|
-
return this.
|
|
3539
|
+
return this._sender.shutdown();
|
|
3479
3540
|
}
|
|
3480
3541
|
/**
|
|
3481
3542
|
* Select aggregation temporality
|
|
3482
3543
|
*/
|
|
3483
|
-
selectAggregationTemporality(
|
|
3484
|
-
if (
|
|
3485
|
-
|
|
3544
|
+
selectAggregationTemporality(instrumentType) {
|
|
3545
|
+
if (instrumentType == sdkMetrics.InstrumentType.UP_DOWN_COUNTER ||
|
|
3546
|
+
instrumentType == sdkMetrics.InstrumentType.OBSERVABLE_UP_DOWN_COUNTER) {
|
|
3486
3547
|
return sdkMetrics.AggregationTemporality.CUMULATIVE;
|
|
3487
3548
|
}
|
|
3488
3549
|
return sdkMetrics.AggregationTemporality.DELTA;
|
|
@@ -3657,6 +3718,9 @@ function getLegacyApplicationInsightsBaseData(log) {
|
|
|
3657
3718
|
baseData = JSON.parse(log.body);
|
|
3658
3719
|
break;
|
|
3659
3720
|
}
|
|
3721
|
+
if (typeof (baseData === null || baseData === void 0 ? void 0 : baseData.message) === "object") {
|
|
3722
|
+
baseData.message = JSON.stringify(baseData.message);
|
|
3723
|
+
}
|
|
3660
3724
|
}
|
|
3661
3725
|
catch (err) {
|
|
3662
3726
|
api.diag.error("AzureMonitorLogExporter failed to parse Application Insights Telemetry");
|
|
@@ -3680,6 +3744,7 @@ class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
3680
3744
|
* Flag to determine if Exporter is shutdown.
|
|
3681
3745
|
*/
|
|
3682
3746
|
this._isShutdown = false;
|
|
3747
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
3683
3748
|
api.diag.debug("AzureMonitorLogExporter was successfully setup");
|
|
3684
3749
|
}
|
|
3685
3750
|
/**
|
|
@@ -3696,66 +3761,23 @@ class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
|
3696
3761
|
api.diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);
|
|
3697
3762
|
let envelopes = [];
|
|
3698
3763
|
logs.forEach((log) => {
|
|
3699
|
-
let envelope = logToEnvelope(log, this.
|
|
3764
|
+
let envelope = logToEnvelope(log, this.instrumentationKey);
|
|
3700
3765
|
if (envelope) {
|
|
3701
3766
|
envelopes.push(envelope);
|
|
3702
3767
|
}
|
|
3703
3768
|
});
|
|
3704
|
-
|
|
3705
|
-
}
|
|
3706
|
-
/**
|
|
3707
|
-
* Shutdown AzureMonitorLogExporter.
|
|
3708
|
-
*/
|
|
3709
|
-
async shutdown() {
|
|
3710
|
-
this._isShutdown = true;
|
|
3711
|
-
api.diag.info("AzureMonitorLogExporter shutting down");
|
|
3712
|
-
return this._shutdown();
|
|
3713
|
-
}
|
|
3714
|
-
}
|
|
3715
|
-
|
|
3716
|
-
// Copyright (c) Microsoft Corporation.
|
|
3717
|
-
/**
|
|
3718
|
-
* Azure Monitor Statsbeat Exporter
|
|
3719
|
-
*/
|
|
3720
|
-
class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
3721
|
-
/**
|
|
3722
|
-
* Initializes a new instance of the AzureMonitorStatsbeatExporter class.
|
|
3723
|
-
* @param options - Exporter configuration
|
|
3724
|
-
*/
|
|
3725
|
-
constructor(options) {
|
|
3726
|
-
super(options, true);
|
|
3727
|
-
/**
|
|
3728
|
-
* Flag to determine if the Exporter is shutdown.
|
|
3729
|
-
*/
|
|
3730
|
-
this._isShutdown = false;
|
|
3731
|
-
}
|
|
3732
|
-
/**
|
|
3733
|
-
* Export Statsbeat metrics.
|
|
3734
|
-
*/
|
|
3735
|
-
async export(metrics, resultCallback) {
|
|
3736
|
-
if (this._isShutdown) {
|
|
3737
|
-
setTimeout(() => resultCallback({ code: core.ExportResultCode.FAILED }), 0);
|
|
3738
|
-
return;
|
|
3739
|
-
}
|
|
3740
|
-
let envelopes = resourceMetricsToEnvelope(metrics, this._instrumentationKey, true // isStatsbeat flag passed to create a Statsbeat envelope.
|
|
3741
|
-
);
|
|
3742
|
-
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
3769
|
+
// Supress tracing until OpenTelemetry Logs SDK support it
|
|
3743
3770
|
api.context.with(core.suppressTracing(api.context.active()), async () => {
|
|
3744
|
-
resultCallback(await this.
|
|
3771
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
3745
3772
|
});
|
|
3746
3773
|
}
|
|
3747
3774
|
/**
|
|
3748
|
-
* Shutdown
|
|
3775
|
+
* Shutdown AzureMonitorLogExporter.
|
|
3749
3776
|
*/
|
|
3750
3777
|
async shutdown() {
|
|
3751
3778
|
this._isShutdown = true;
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
/**
|
|
3755
|
-
* Force flush.
|
|
3756
|
-
*/
|
|
3757
|
-
async forceFlush() {
|
|
3758
|
-
return Promise.resolve();
|
|
3779
|
+
api.diag.info("AzureMonitorLogExporter shutting down");
|
|
3780
|
+
return this._sender.shutdown();
|
|
3759
3781
|
}
|
|
3760
3782
|
}
|
|
3761
3783
|
|
|
@@ -3763,6 +3785,5 @@ exports.ApplicationInsightsSampler = ApplicationInsightsSampler;
|
|
|
3763
3785
|
exports.AzureMonitorBaseExporter = AzureMonitorBaseExporter;
|
|
3764
3786
|
exports.AzureMonitorLogExporter = AzureMonitorLogExporter;
|
|
3765
3787
|
exports.AzureMonitorMetricExporter = AzureMonitorMetricExporter;
|
|
3766
|
-
exports.AzureMonitorStatsbeatExporter = AzureMonitorStatsbeatExporter;
|
|
3767
3788
|
exports.AzureMonitorTraceExporter = AzureMonitorTraceExporter;
|
|
3768
3789
|
//# sourceMappingURL=index.js.map
|