@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networkStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAA+B,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAIjB,MAAM,SAAS,CAAC;AAEjB,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAgC3D,YAAY,OAAyB;QACnC,KAAK,EAAE,CAAC;QA9BF,mBAAc,GAAY,KAAK,CAAC;QAChC,kCAA6B,GAAW,MAAM,CAAC,CAAC,aAAa;QAE7D,gCAA2B,GAA4B,EAAE,CAAC;QAW1D,YAAO,GAAW,KAAK,CAAC;QAiB9B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,IAAI,CAAC,8BAA8B,GAAG,IAAI,aAAa,EAAE,CAAC;QAE1D,MAAM,cAAc,GAAgC;YAClD,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;SACzC,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,IAAI,6BAA6B,CAAC,cAAc,CAAC,CAAC;QAE/E,6CAA6C;QAC7C,MAAM,0BAA0B,GAAyC;YACvE,QAAQ,EAAE,IAAI,CAAC,qBAAqB;YACpC,oBAAoB,EAAE,OAAO,CAA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AAQ;gBACzD,IAAI,KAAK,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,IAAI,EACjD;gBACA,OAAO,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;aAC5C;SACF;QACD,oCAAoC;QACpC,IAAI,UAAU,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClD,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,aAAa,CAAC,YAAoB;QACxC,IAAI,SAAS,GAAG,YAAY,CAAC;QAC7B,IAAI;YACF,IAAI,SAAS,GAAG,IAAI,MAAM,CAAC,kCAAkC,CAAC,CAAC;YAC/D,IAAI,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACvC,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;gBACjC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;aACpB;YACD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;SAClD;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n Meter,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions, AzureMonitorStatsbeatExporter } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n NetworkStatsbeat,\n CommonStatsbeatProperties,\n NetworkStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types\";\n\nexport class NetworkStatsbeatMetrics extends StatsbeatMetrics {\n private _commonProperties: CommonStatsbeatProperties;\n private _networkProperties: NetworkStatsbeatProperties;\n private _isInitialized: boolean = false;\n private _statsCollectionShortInterval: number = 900000; // 15 minutes\n\n private _networkStatsbeatCollection: Array<NetworkStatsbeat> = [];\n private _networkStatsbeatMeter: Meter;\n private _networkStatsbeatMeterProvider: MeterProvider;\n private _networkAzureExporter: AzureMonitorStatsbeatExporter;\n private _networkMetricReader: PeriodicExportingMetricReader;\n\n // Custom dimensions\n private _cikey: string;\n private _runtimeVersion: string;\n private _language: string;\n private _version: string;\n private _attach: string = \"sdk\";\n\n // Observable Gauges\n private _successCountGauge: ObservableGauge;\n private _failureCountGauge: ObservableGauge;\n private _retryCountGauge: ObservableGauge;\n private _throttleCountGauge: ObservableGauge;\n private _exceptionCountGauge: ObservableGauge;\n private _averageDurationGauge: ObservableGauge;\n\n // Network attributes\n private _connectionString: string;\n private _endpointUrl: string;\n private _host: string;\n\n constructor(options: StatsbeatOptions) {\n super();\n this._connectionString = super._getConnectionString(options.endpointUrl);\n this._networkStatsbeatMeterProvider = new MeterProvider();\n\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this._connectionString,\n };\n\n this._networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Exports Network Statsbeat every 15 minutes\n const networkMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this._networkAzureExporter,\n exportIntervalMillis: options.networkCollectionInterval || this._statsCollectionShortInterval, // 15 minutes\n };\n\n this._networkMetricReader = new PeriodicExportingMetricReader(networkMetricReaderOptions);\n this._networkStatsbeatMeterProvider.addMetricReader(this._networkMetricReader);\n this._networkStatsbeatMeter = this._networkStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Network Statsbeat\"\n );\n\n this._endpointUrl = options.endpointUrl;\n this._runtimeVersion = process.version;\n this._language = STATSBEAT_LANGUAGE;\n this._version = ai.packageVersion;\n this._host = this._getShortHost(options.endpointUrl);\n this._cikey = options.instrumentationKey;\n\n this._successCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.SUCCESS_COUNT\n );\n this._failureCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FAILURE_COUNT\n );\n this._retryCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.RETRY_COUNT\n );\n this._throttleCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.THROTTLE_COUNT\n );\n this._exceptionCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.EXCEPTION_COUNT\n );\n this._averageDurationGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.AVERAGE_DURATION\n );\n\n this._commonProperties = {\n os: super._os,\n rp: super._resourceProvider,\n cikey: this._cikey,\n runtimeVersion: this._runtimeVersion,\n language: this._language,\n version: this._version,\n attach: this._attach,\n };\n\n this._networkProperties = {\n endpoint: this._endpointUrl,\n host: this._host,\n };\n\n this._isInitialized = true;\n this._initialize();\n }\n\n public isInitialized() {\n return this._isInitialized;\n }\n\n public shutdown() {\n this._networkStatsbeatMeterProvider.shutdown();\n }\n\n private async _initialize() {\n try {\n await super._getResourceProvider();\n\n // Add network observable callbacks\n this._successCountGauge.addCallback(this._successCallback.bind(this));\n this._networkStatsbeatMeter.addBatchObservableCallback(this._failureCallback.bind(this), [\n this._failureCountGauge,\n ]);\n this._networkStatsbeatMeter.addBatchObservableCallback(this._retryCallback.bind(this), [\n this._retryCountGauge,\n ]);\n this._networkStatsbeatMeter.addBatchObservableCallback(this._throttleCallback.bind(this), [\n this._throttleCountGauge,\n ]);\n this._networkStatsbeatMeter.addBatchObservableCallback(this._exceptionCallback.bind(this), [\n this._exceptionCountGauge,\n ]);\n this._averageDurationGauge.addCallback(this._durationCallback.bind(this));\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n // Observable gauge callbacks\n private _successCallback(observableResult: ObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._commonProperties, ...this._networkProperties };\n observableResult.observe(counter.totalSuccesfulRequestCount, attributes);\n counter.totalSuccesfulRequestCount = 0;\n }\n\n private _failureCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n\n /*\n Takes the failureCountGauge, value (of the counter), and attributes\n create a unqiue counter based on statusCode as well\n append statusCode to attributes so the newly created attributes are unique.\n */\n let attributes = { ...this._networkProperties, ...this._commonProperties, statusCode: 0 };\n\n // For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode\n for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {\n attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;\n observableResult.observe(this._failureCountGauge, counter.totalFailedRequestCount[i].count, {\n ...attributes,\n });\n counter.totalFailedRequestCount[i].count = 0;\n }\n }\n\n private _retryCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.retryCount.length; i++) {\n attributes.statusCode = counter.retryCount[i].statusCode;\n observableResult.observe(this._retryCountGauge, counter.retryCount[i].count, {\n ...attributes,\n });\n counter.retryCount[i].count = 0;\n }\n }\n\n private _throttleCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.throttleCount.length; i++) {\n attributes.statusCode = counter.throttleCount[i].statusCode;\n observableResult.observe(this._throttleCountGauge, counter.throttleCount[i].count, {\n ...attributes,\n });\n counter.throttleCount[i].count = 0;\n }\n }\n\n private _exceptionCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties, exceptionType: \"\" };\n\n for (let i = 0; i < counter.exceptionCount.length; i++) {\n attributes.exceptionType = counter.exceptionCount[i].exceptionType;\n observableResult.observe(this._exceptionCountGauge, counter.exceptionCount[i].count, {\n ...attributes,\n });\n counter.exceptionCount[i].count = 0;\n }\n }\n\n private _durationCallback(observableResult: ObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties };\n for (let i = 0; i < this._networkStatsbeatCollection.length; i++) {\n let currentCounter = this._networkStatsbeatCollection[i];\n currentCounter.time = Number(new Date());\n let intervalRequests =\n currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;\n currentCounter.averageRequestExecutionTime =\n (currentCounter.intervalRequestExecutionTime -\n currentCounter.lastIntervalRequestExecutionTime) /\n intervalRequests || 0;\n currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset\n\n currentCounter.lastRequestCount = currentCounter.totalRequestCount;\n currentCounter.lastTime = currentCounter.time;\n }\n observableResult.observe(counter.averageRequestExecutionTime, attributes);\n\n counter.averageRequestExecutionTime = 0;\n }\n\n // Public methods to increase counters\n public countSuccess(duration: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n counter.totalRequestCount++;\n counter.totalSuccesfulRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countFailure(duration: number, statusCode: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentStatusCounter = counter.totalFailedRequestCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.totalFailedRequestCount.push({ statusCode: statusCode, count: 1 });\n }\n\n counter.totalRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countRetry(statusCode: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentStatusCounter = counter.retryCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.retryCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countThrottle(statusCode: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentStatusCounter = counter.throttleCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.throttleCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countException(exceptionType: Error) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentErrorCounter = counter.exceptionCount.find(\n (exceptionCounter) => exceptionType.name === exceptionCounter.exceptionType\n );\n if (currentErrorCounter) {\n currentErrorCounter.count++;\n } else {\n counter.exceptionCount.push({ exceptionType: exceptionType.name, count: 1 });\n }\n }\n\n // Gets a networkStatsbeat counter if one exists for the given endpoint\n private _getNetworkStatsbeatCounter(endpoint: string, host: string): NetworkStatsbeat {\n // Check if the counter is available\n for (let i = 0; i < this._networkStatsbeatCollection.length; i++) {\n // Same object\n if (\n endpoint === this._networkStatsbeatCollection[i].endpoint &&\n host === this._networkStatsbeatCollection[i].host\n ) {\n return this._networkStatsbeatCollection[i];\n }\n }\n // Create a new counter if not found\n let newCounter = new NetworkStatsbeat(endpoint, host);\n this._networkStatsbeatCollection.push(newCounter);\n return newCounter;\n }\n\n private _getShortHost(originalHost: string) {\n let shortHost = originalHost;\n try {\n let hostRegex = new RegExp(/^https?:\\/\\/(?:www\\.)?([^\\/.-]+)/);\n let res = hostRegex.exec(originalHost);\n if (res != null && res.length > 1) {\n shortHost = res[1];\n }\n shortHost = shortHost.replace(\".in.applicationinsights.azure.com\", \"\");\n } catch (error) {\n diag.debug(\"Failed to get the short host name.\");\n }\n return shortHost;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"networkStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAIjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAgC3D,YAAY,OAAyB;QACnC,KAAK,EAAE,CAAC;QA9BF,mBAAc,GAAY,KAAK,CAAC;QAChC,kCAA6B,GAAW,MAAM,CAAC,CAAC,aAAa;QAE7D,gCAA2B,GAA4B,EAAE,CAAC;QAW1D,YAAO,GAAW,KAAK,CAAC;QAiB9B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,IAAI,CAAC,8BAA8B,GAAG,IAAI,aAAa,EAAE,CAAC;QAE1D,MAAM,cAAc,GAAgC;YAClD,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;SACzC,CAAC;QAEF,IAAI,CA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AC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,2BAA2B,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAChE,cAAc;YACd,IACE,QAAQ,KAAK,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,QAAQ;gBACzD,IAAI,KAAK,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,IAAI,EACjD;gBACA,OAAO,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;aAC5C;SACF;QACD,oCAAoC;QACpC,IAAI,UAAU,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClD,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,aAAa,CAAC,YAAoB;QACxC,IAAI,SAAS,GAAG,YAAY,CAAC;QAC7B,IAAI;YACF,IAAI,SAAS,GAAG,IAAI,MAAM,CAAC,kCAAkC,CAAC,CAAC;YAC/D,IAAI,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACvC,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;gBACjC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;aACpB;YACD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;SAClD;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n Meter,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n NetworkStatsbeat,\n CommonStatsbeatProperties,\n NetworkStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nexport class NetworkStatsbeatMetrics extends StatsbeatMetrics {\n private _commonProperties: CommonStatsbeatProperties;\n private _networkProperties: NetworkStatsbeatProperties;\n private _isInitialized: boolean = false;\n private _statsCollectionShortInterval: number = 900000; // 15 minutes\n\n private _networkStatsbeatCollection: Array<NetworkStatsbeat> = [];\n private _networkStatsbeatMeter: Meter;\n private _networkStatsbeatMeterProvider: MeterProvider;\n private _networkAzureExporter: AzureMonitorStatsbeatExporter;\n private _networkMetricReader: PeriodicExportingMetricReader;\n\n // Custom dimensions\n private _cikey: string;\n private _runtimeVersion: string;\n private _language: string;\n private _version: string;\n private _attach: string = \"sdk\";\n\n // Observable Gauges\n private _successCountGauge: ObservableGauge;\n private _failureCountGauge: ObservableGauge;\n private _retryCountGauge: ObservableGauge;\n private _throttleCountGauge: ObservableGauge;\n private _exceptionCountGauge: ObservableGauge;\n private _averageDurationGauge: ObservableGauge;\n\n // Network attributes\n private _connectionString: string;\n private _endpointUrl: string;\n private _host: string;\n\n constructor(options: StatsbeatOptions) {\n super();\n this._connectionString = super._getConnectionString(options.endpointUrl);\n this._networkStatsbeatMeterProvider = new MeterProvider();\n\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this._connectionString,\n };\n\n this._networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Exports Network Statsbeat every 15 minutes\n const networkMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this._networkAzureExporter,\n exportIntervalMillis: options.networkCollectionInterval || this._statsCollectionShortInterval, // 15 minutes\n };\n\n this._networkMetricReader = new PeriodicExportingMetricReader(networkMetricReaderOptions);\n this._networkStatsbeatMeterProvider.addMetricReader(this._networkMetricReader);\n this._networkStatsbeatMeter = this._networkStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Network Statsbeat\"\n );\n\n this._endpointUrl = options.endpointUrl;\n this._runtimeVersion = process.version;\n this._language = STATSBEAT_LANGUAGE;\n this._version = ai.packageVersion;\n this._host = this._getShortHost(options.endpointUrl);\n this._cikey = options.instrumentationKey;\n\n this._successCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.SUCCESS_COUNT\n );\n this._failureCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FAILURE_COUNT\n );\n this._retryCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.RETRY_COUNT\n );\n this._throttleCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.THROTTLE_COUNT\n );\n this._exceptionCountGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.EXCEPTION_COUNT\n );\n this._averageDurationGauge = this._networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.AVERAGE_DURATION\n );\n\n this._commonProperties = {\n os: super._os,\n rp: super._resourceProvider,\n cikey: this._cikey,\n runtimeVersion: this._runtimeVersion,\n language: this._language,\n version: this._version,\n attach: this._attach,\n };\n\n this._networkProperties = {\n endpoint: this._endpointUrl,\n host: this._host,\n };\n\n this._isInitialized = true;\n this._initialize();\n }\n\n public isInitialized() {\n return this._isInitialized;\n }\n\n public shutdown() {\n this._networkStatsbeatMeterProvider.shutdown();\n }\n\n private async _initialize() {\n try {\n await super._getResourceProvider();\n\n // Add network observable callbacks\n this._successCountGauge.addCallback(this._successCallback.bind(this));\n this._networkStatsbeatMeter.addBatchObservableCallback(this._failureCallback.bind(this), [\n this._failureCountGauge,\n ]);\n this._networkStatsbeatMeter.addBatchObservableCallback(this._retryCallback.bind(this), [\n this._retryCountGauge,\n ]);\n this._networkStatsbeatMeter.addBatchObservableCallback(this._throttleCallback.bind(this), [\n this._throttleCountGauge,\n ]);\n this._networkStatsbeatMeter.addBatchObservableCallback(this._exceptionCallback.bind(this), [\n this._exceptionCountGauge,\n ]);\n this._averageDurationGauge.addCallback(this._durationCallback.bind(this));\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n // Observable gauge callbacks\n private _successCallback(observableResult: ObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._commonProperties, ...this._networkProperties };\n observableResult.observe(counter.totalSuccesfulRequestCount, attributes);\n counter.totalSuccesfulRequestCount = 0;\n }\n\n private _failureCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n\n /*\n Takes the failureCountGauge, value (of the counter), and attributes\n create a unqiue counter based on statusCode as well\n append statusCode to attributes so the newly created attributes are unique.\n */\n let attributes = { ...this._networkProperties, ...this._commonProperties, statusCode: 0 };\n\n // For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode\n for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {\n attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;\n observableResult.observe(this._failureCountGauge, counter.totalFailedRequestCount[i].count, {\n ...attributes,\n });\n counter.totalFailedRequestCount[i].count = 0;\n }\n }\n\n private _retryCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.retryCount.length; i++) {\n attributes.statusCode = counter.retryCount[i].statusCode;\n observableResult.observe(this._retryCountGauge, counter.retryCount[i].count, {\n ...attributes,\n });\n counter.retryCount[i].count = 0;\n }\n }\n\n private _throttleCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.throttleCount.length; i++) {\n attributes.statusCode = counter.throttleCount[i].statusCode;\n observableResult.observe(this._throttleCountGauge, counter.throttleCount[i].count, {\n ...attributes,\n });\n counter.throttleCount[i].count = 0;\n }\n }\n\n private _exceptionCallback(observableResult: BatchObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties, exceptionType: \"\" };\n\n for (let i = 0; i < counter.exceptionCount.length; i++) {\n attributes.exceptionType = counter.exceptionCount[i].exceptionType;\n observableResult.observe(this._exceptionCountGauge, counter.exceptionCount[i].count, {\n ...attributes,\n });\n counter.exceptionCount[i].count = 0;\n }\n }\n\n private _durationCallback(observableResult: ObservableResult) {\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let attributes = { ...this._networkProperties, ...this._commonProperties };\n for (let i = 0; i < this._networkStatsbeatCollection.length; i++) {\n let currentCounter = this._networkStatsbeatCollection[i];\n currentCounter.time = Number(new Date());\n let intervalRequests =\n currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;\n currentCounter.averageRequestExecutionTime =\n (currentCounter.intervalRequestExecutionTime -\n currentCounter.lastIntervalRequestExecutionTime) /\n intervalRequests || 0;\n currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset\n\n currentCounter.lastRequestCount = currentCounter.totalRequestCount;\n currentCounter.lastTime = currentCounter.time;\n }\n observableResult.observe(counter.averageRequestExecutionTime, attributes);\n\n counter.averageRequestExecutionTime = 0;\n }\n\n // Public methods to increase counters\n public countSuccess(duration: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n counter.totalRequestCount++;\n counter.totalSuccesfulRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countFailure(duration: number, statusCode: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentStatusCounter = counter.totalFailedRequestCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.totalFailedRequestCount.push({ statusCode: statusCode, count: 1 });\n }\n\n counter.totalRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countRetry(statusCode: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentStatusCounter = counter.retryCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.retryCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countThrottle(statusCode: number) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentStatusCounter = counter.throttleCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.throttleCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countException(exceptionType: Error) {\n if (!this._isInitialized) {\n return;\n }\n let counter: NetworkStatsbeat = this._getNetworkStatsbeatCounter(this._endpointUrl, this._host);\n let currentErrorCounter = counter.exceptionCount.find(\n (exceptionCounter) => exceptionType.name === exceptionCounter.exceptionType\n );\n if (currentErrorCounter) {\n currentErrorCounter.count++;\n } else {\n counter.exceptionCount.push({ exceptionType: exceptionType.name, count: 1 });\n }\n }\n\n // Gets a networkStatsbeat counter if one exists for the given endpoint\n private _getNetworkStatsbeatCounter(endpoint: string, host: string): NetworkStatsbeat {\n // Check if the counter is available\n for (let i = 0; i < this._networkStatsbeatCollection.length; i++) {\n // Same object\n if (\n endpoint === this._networkStatsbeatCollection[i].endpoint &&\n host === this._networkStatsbeatCollection[i].host\n ) {\n return this._networkStatsbeatCollection[i];\n }\n }\n // Create a new counter if not found\n let newCounter = new NetworkStatsbeat(endpoint, host);\n this._networkStatsbeatCollection.push(newCounter);\n return newCounter;\n }\n\n private _getShortHost(originalHost: string) {\n let shortHost = originalHost;\n try {\n let hostRegex = new RegExp(/^https?:\\/\\/(?:www\\.)?([^\\/.-]+)/);\n let res = hostRegex.exec(originalHost);\n if (res != null && res.length > 1) {\n shortHost = res[1];\n }\n shortHost = shortHost.replace(\".in.applicationinsights.azure.com\", \"\");\n } catch (error) {\n diag.debug(\"Failed to get the short host name.\");\n }\n return shortHost;\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { context } from "@opentelemetry/api";
|
|
|
4
4
|
import { ExportResultCode, suppressTracing } from "@opentelemetry/core";
|
|
5
5
|
import { resourceMetricsToEnvelope } from "../../utils/metricUtils";
|
|
6
6
|
import { AzureMonitorBaseExporter } from "../base";
|
|
7
|
+
import { HttpSender } from "../../platform";
|
|
7
8
|
/**
|
|
8
9
|
* Azure Monitor Statsbeat Exporter
|
|
9
10
|
*/
|
|
@@ -18,6 +19,7 @@ export class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
|
18
19
|
* Flag to determine if the Exporter is shutdown.
|
|
19
20
|
*/
|
|
20
21
|
this._isShutdown = false;
|
|
22
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Export Statsbeat metrics.
|
|
@@ -27,11 +29,11 @@ export class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
|
27
29
|
setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
|
-
let envelopes = resourceMetricsToEnvelope(metrics, this.
|
|
32
|
+
let envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey, true // isStatsbeat flag passed to create a Statsbeat envelope.
|
|
31
33
|
);
|
|
32
34
|
// Supress tracing until OpenTelemetry Metrics SDK support it
|
|
33
35
|
context.with(suppressTracing(context.active()), async () => {
|
|
34
|
-
resultCallback(await this.
|
|
36
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
@@ -39,7 +41,7 @@ export class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
|
39
41
|
*/
|
|
40
42
|
async shutdown() {
|
|
41
43
|
this._isShutdown = true;
|
|
42
|
-
return this.
|
|
44
|
+
return this._sender.shutdown();
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Force flush.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statsbeatExporter.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatExporter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"statsbeatExporter.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatExporter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,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under the MIT license.\nimport { context } from \"@opentelemetry/api\";\nimport { PushMetricExporter, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\nimport { resourceMetricsToEnvelope } from \"../../utils/metricUtils\";\nimport { AzureMonitorBaseExporter } from \"../base\";\nimport { HttpSender } from \"../../platform\";\n\n/**\n * Azure Monitor Statsbeat Exporter\n */\nexport class AzureMonitorStatsbeatExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if the Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorStatsbeatExporter class.\n * @param options - Exporter configuration\n */\n constructor(options: AzureMonitorExporterOptions) {\n super(options, true);\n this._sender = new HttpSender(\n this.endpointUrl,\n this.instrumentationKey,\n this.trackStatsbeat,\n options\n );\n }\n\n /**\n * Export Statsbeat metrics.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n if (this._isShutdown) {\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n let envelopes: Envelope[] = resourceMetricsToEnvelope(\n metrics,\n this.instrumentationKey,\n true // isStatsbeat flag passed to create a Statsbeat envelope.\n );\n // Supress tracing until OpenTelemetry Metrics SDK support it\n context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorStatsbeatExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n return this._sender.shutdown();\n }\n\n /**\n * Force flush.\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { ExportResultCode } from "@opentelemetry/core";
|
|
|
5
5
|
import { AzureMonitorBaseExporter } from "./base";
|
|
6
6
|
import { readableSpanToEnvelope, spanEventsToEnvelopes } from "../utils/spanUtils";
|
|
7
7
|
import { createResourceMetricEnvelope } from "../utils/common";
|
|
8
|
+
import { HttpSender } from "../platform";
|
|
8
9
|
/**
|
|
9
10
|
* Azure Monitor OpenTelemetry Trace Exporter.
|
|
10
11
|
*/
|
|
@@ -19,6 +20,7 @@ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
19
20
|
* Flag to determine if Exporter is shutdown.
|
|
20
21
|
*/
|
|
21
22
|
this._isShutdown = false;
|
|
23
|
+
this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
|
|
22
24
|
diag.debug("AzureMonitorTraceExporter was successfully setup");
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
@@ -35,18 +37,18 @@ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
35
37
|
diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);
|
|
36
38
|
if (spans.length > 0) {
|
|
37
39
|
let envelopes = [];
|
|
38
|
-
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.
|
|
40
|
+
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.instrumentationKey);
|
|
39
41
|
if (resourceMetricEnvelope) {
|
|
40
42
|
envelopes.push(resourceMetricEnvelope);
|
|
41
43
|
}
|
|
42
44
|
spans.forEach((span) => {
|
|
43
|
-
envelopes.push(readableSpanToEnvelope(span, this.
|
|
44
|
-
let spanEventEnvelopes = spanEventsToEnvelopes(span, this.
|
|
45
|
+
envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));
|
|
46
|
+
let spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);
|
|
45
47
|
if (spanEventEnvelopes.length > 0) {
|
|
46
48
|
envelopes.push(...spanEventEnvelopes);
|
|
47
49
|
}
|
|
48
50
|
});
|
|
49
|
-
resultCallback(await this.
|
|
51
|
+
resultCallback(await this._sender.exportEnvelopes(envelopes));
|
|
50
52
|
}
|
|
51
53
|
// No data to export
|
|
52
54
|
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
@@ -57,7 +59,7 @@ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
57
59
|
async shutdown() {
|
|
58
60
|
this._isShutdown = true;
|
|
59
61
|
diag.info("AzureMonitorTraceExporter shutting down");
|
|
60
|
-
return this.
|
|
62
|
+
return this._sender.shutdown();
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
//# sourceMappingURL=trace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,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C;gBAC9E,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;oBACjC,SAAS,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAC;iBACvC;YACH,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;SAC/D;QACD,oBAAoB;QACpB,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { ReadableSpan, SpanExporter } from \"@opentelemetry/sdk-trace-base\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { readableSpanToEnvelope, spanEventsToEnvelopes } from \"../utils/spanUtils\";\nimport { createResourceMetricEnvelope } from \"../utils/common\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private readonly _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorTraceExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender(\n this.endpointUrl,\n this.instrumentationKey,\n this.trackStatsbeat,\n options\n );\n diag.debug(\"AzureMonitorTraceExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry spans.\n * @param spans - Spans to export.\n * @param resultCallback - Result callback.\n */\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);\n\n if (spans.length > 0) {\n let envelopes: Envelope[] = [];\n const resourceMetricEnvelope = createResourceMetricEnvelope(\n spans[0].resource,\n this.instrumentationKey\n );\n if (resourceMetricEnvelope) {\n envelopes.push(resourceMetricEnvelope);\n }\n spans.forEach((span) => {\n envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));\n let spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);\n if (spanEventEnvelopes.length > 0) {\n envelopes.push(...spanEventEnvelopes);\n }\n });\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n }\n // No data to export\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /**\n * Shutdown AzureMonitorTraceExporter.\n */\n async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorTraceExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
|
|
@@ -23,7 +23,7 @@ export class ApplicationInsightsClient extends coreClient.ServiceClient {
|
|
|
23
23
|
const defaults = {
|
|
24
24
|
requestContentType: "application/json; charset=utf-8"
|
|
25
25
|
};
|
|
26
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
26
|
+
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.15`;
|
|
27
27
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
28
28
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
29
29
|
: `${packageDetails}`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AAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;KACF;IACD,WAAW,EAAE,UAAU,CAAC,IAAI;IAC5B,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
1
|
+
{"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,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d;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;KACF;IACD,WAAW,EAAE,UAAU,CAAC,IAAI;IAC5B,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.15`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint ?? options.baseUri ?? \"{Host}/v2.1\"\n };\n super(optionsWithDefaults);\n\n if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {\n const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();\n const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(\n (pipelinePolicy) =>\n pipelinePolicy.name ===\n coreRestPipeline.bearerTokenAuthenticationPolicyName\n );\n if (!bearerTokenAuthenticationPolicyFound) {\n this.pipeline.removePolicy({\n name: coreRestPipeline.bearerTokenAuthenticationPolicyName\n });\n this.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n scopes: `${optionsWithDefaults.baseUri}/.default`,\n challengeCallbacks: {\n authorizeRequestOnChallenge:\n coreClient.authorizeRequestOnClaimChallenge\n }\n })\n );\n }\n }\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n\n /**\n * This operation sends a sequence of telemetry events that will be monitored by Azure Monitor.\n * @param body The list of telemetry events to track.\n * @param options The options parameters.\n */\n track(\n body: TelemetryItem[],\n options?: TrackOptionalParams\n ): Promise<TrackOperationResponse> {\n return this.sendOperationRequest({ body, options }, trackOperationSpec);\n }\n}\n// Operation Specifications\nconst serializer = coreClient.createSerializer(Mappers, /* isXml */ false);\n\nconst trackOperationSpec: coreClient.OperationSpec = {\n path: \"/track\",\n httpMethod: \"POST\",\n responses: {\n 200: {\n bodyMapper: Mappers.TrackResponse\n },\n 206: {\n bodyMapper: Mappers.TrackResponse\n },\n 400: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 402: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 429: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 500: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 503: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n }\n },\n requestBody: Parameters.body,\n urlParameters: [Parameters.host],\n headerParameters: [Parameters.contentType, Parameters.accept],\n mediaType: \"json\",\n serializer\n};\n"]}
|
package/dist-esm/src/index.js
CHANGED
|
@@ -5,6 +5,5 @@ export { AzureMonitorBaseExporter } from "./export/base";
|
|
|
5
5
|
export { AzureMonitorTraceExporter } from "./export/trace";
|
|
6
6
|
export { AzureMonitorMetricExporter } from "./export/metric";
|
|
7
7
|
export { AzureMonitorLogExporter } from "./export/log";
|
|
8
|
-
export { AzureMonitorStatsbeatExporter } from "./export/statsbeat/statsbeatExporter";
|
|
9
8
|
export { ServiceApiVersion } from "./Declarations/Constants";
|
|
10
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { ApplicationInsightsSampler } from \"./sampling\";\nexport { AzureMonitorBaseExporter } from \"./export/base\";\nexport { AzureMonitorTraceExporter } from \"./export/trace\";\nexport { AzureMonitorMetricExporter } from \"./export/metric\";\nexport { AzureMonitorLogExporter } from \"./export/log\";\nexport { AzureMonitorExporterOptions } from \"./config\";\nexport { ServiceApiVersion } from \"./Declarations/Constants\";\nexport { ApplicationInsightsClientOptionalParams } from \"./generated/models\";\n"]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { diag } from "@opentelemetry/api";
|
|
4
|
+
import { FileSystemPersist } from "./persist";
|
|
5
|
+
import { ExportResultCode } from "@opentelemetry/core";
|
|
6
|
+
import { NetworkStatsbeatMetrics } from "../../export/statsbeat/networkStatsbeatMetrics";
|
|
7
|
+
import { getInstance } from "../../export/statsbeat/longIntervalStatsbeatMetrics";
|
|
8
|
+
import { MAX_STATSBEAT_FAILURES } from "../../export/statsbeat/types";
|
|
9
|
+
import { isRetriable } from "../../utils/breezeUtils";
|
|
10
|
+
const DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60000;
|
|
11
|
+
/**
|
|
12
|
+
* Base sender class
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export class BaseSender {
|
|
16
|
+
constructor(endpointUrl, instrumentationKey, trackStatsbeat, options = {}) {
|
|
17
|
+
this._statsbeatFailureCount = 0;
|
|
18
|
+
this._batchSendRetryIntervalMs = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;
|
|
19
|
+
this._numConsecutiveRedirects = 0;
|
|
20
|
+
this._persister = new FileSystemPersist(instrumentationKey, options);
|
|
21
|
+
if (trackStatsbeat) {
|
|
22
|
+
// Initialize statsbeatMetrics
|
|
23
|
+
this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
|
|
24
|
+
instrumentationKey: instrumentationKey,
|
|
25
|
+
endpointUrl: endpointUrl,
|
|
26
|
+
});
|
|
27
|
+
this._longIntervalStatsbeatMetrics = getInstance({
|
|
28
|
+
instrumentationKey: instrumentationKey,
|
|
29
|
+
endpointUrl: endpointUrl,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
this._retryTimer = null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Export envelopes
|
|
36
|
+
*/
|
|
37
|
+
async exportEnvelopes(envelopes) {
|
|
38
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
39
|
+
diag.info(`Exporting ${envelopes.length} envelope(s)`);
|
|
40
|
+
if (envelopes.length < 1) {
|
|
41
|
+
return { code: ExportResultCode.SUCCESS };
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const startTime = new Date().getTime();
|
|
45
|
+
const { result, statusCode } = await this.send(envelopes);
|
|
46
|
+
const endTime = new Date().getTime();
|
|
47
|
+
const duration = endTime - startTime;
|
|
48
|
+
this._numConsecutiveRedirects = 0;
|
|
49
|
+
if (statusCode === 200) {
|
|
50
|
+
// Success -- @todo: start retry timer
|
|
51
|
+
if (!this._retryTimer) {
|
|
52
|
+
this._retryTimer = setTimeout(() => {
|
|
53
|
+
this._retryTimer = null;
|
|
54
|
+
this._sendFirstPersistedFile();
|
|
55
|
+
}, this._batchSendRetryIntervalMs);
|
|
56
|
+
this._retryTimer.unref();
|
|
57
|
+
}
|
|
58
|
+
// If we are not exportings statsbeat and statsbeat is not disabled -- count success
|
|
59
|
+
(_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countSuccess(duration);
|
|
60
|
+
return { code: ExportResultCode.SUCCESS };
|
|
61
|
+
}
|
|
62
|
+
else if (statusCode && isRetriable(statusCode)) {
|
|
63
|
+
// Failed -- persist failed data
|
|
64
|
+
if (statusCode === 429 || statusCode === 439) {
|
|
65
|
+
(_b = this._networkStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.countThrottle(statusCode);
|
|
66
|
+
}
|
|
67
|
+
if (result) {
|
|
68
|
+
diag.info(result);
|
|
69
|
+
const breezeResponse = JSON.parse(result);
|
|
70
|
+
const filteredEnvelopes = [];
|
|
71
|
+
if (breezeResponse.errors) {
|
|
72
|
+
breezeResponse.errors.forEach((error) => {
|
|
73
|
+
if (error.statusCode && isRetriable(error.statusCode)) {
|
|
74
|
+
filteredEnvelopes.push(envelopes[error.index]);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (filteredEnvelopes.length > 0) {
|
|
79
|
+
(_c = this._networkStatsbeatMetrics) === null || _c === void 0 ? void 0 : _c.countRetry(statusCode);
|
|
80
|
+
// calls resultCallback(ExportResult) based on result of persister.push
|
|
81
|
+
return await this._persist(filteredEnvelopes);
|
|
82
|
+
}
|
|
83
|
+
// Failed -- not retriable
|
|
84
|
+
(_d = this._networkStatsbeatMetrics) === null || _d === void 0 ? void 0 : _d.countFailure(duration, statusCode);
|
|
85
|
+
return {
|
|
86
|
+
code: ExportResultCode.FAILED,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// calls resultCallback(ExportResult) based on result of persister.push
|
|
91
|
+
(_e = this._networkStatsbeatMetrics) === null || _e === void 0 ? void 0 : _e.countRetry(statusCode);
|
|
92
|
+
return await this._persist(envelopes);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Failed -- not retriable
|
|
97
|
+
if (this._networkStatsbeatMetrics) {
|
|
98
|
+
if (statusCode) {
|
|
99
|
+
this._networkStatsbeatMetrics.countFailure(duration, statusCode);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this._incrementStatsbeatFailure();
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
code: ExportResultCode.FAILED,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
const restError = error;
|
|
112
|
+
if (restError.statusCode &&
|
|
113
|
+
(restError.statusCode === 307 || // Temporary redirect
|
|
114
|
+
restError.statusCode === 308)) {
|
|
115
|
+
// Permanent redirect
|
|
116
|
+
this._numConsecutiveRedirects++;
|
|
117
|
+
// To prevent circular redirects
|
|
118
|
+
if (this._numConsecutiveRedirects < 10) {
|
|
119
|
+
if (restError.response && restError.response.headers) {
|
|
120
|
+
const location = restError.response.headers.get("location");
|
|
121
|
+
if (location) {
|
|
122
|
+
// Update sender URL
|
|
123
|
+
this.handlePermanentRedirect(location);
|
|
124
|
+
// Send to redirect endpoint as HTTPs library doesn't handle redirect automatically
|
|
125
|
+
return this.exportEnvelopes(envelopes);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
let redirectError = new Error("Circular redirect");
|
|
131
|
+
(_f = this._networkStatsbeatMetrics) === null || _f === void 0 ? void 0 : _f.countException(redirectError);
|
|
132
|
+
return { code: ExportResultCode.FAILED, error: redirectError };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (restError.statusCode && isRetriable(restError.statusCode)) {
|
|
136
|
+
(_g = this._networkStatsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
|
|
137
|
+
return await this._persist(envelopes);
|
|
138
|
+
}
|
|
139
|
+
if (this._isNetworkError(restError)) {
|
|
140
|
+
if (restError.statusCode) {
|
|
141
|
+
(_h = this._networkStatsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
|
|
142
|
+
}
|
|
143
|
+
diag.error("Retrying due to transient client side error. Error message:", restError.message);
|
|
144
|
+
return await this._persist(envelopes);
|
|
145
|
+
}
|
|
146
|
+
(_j = this._networkStatsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
|
|
147
|
+
diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
|
|
148
|
+
return { code: ExportResultCode.FAILED, error: restError };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Persist envelopes to disk
|
|
153
|
+
*/
|
|
154
|
+
async _persist(envelopes) {
|
|
155
|
+
try {
|
|
156
|
+
const success = await this._persister.push(envelopes);
|
|
157
|
+
return success
|
|
158
|
+
? { code: ExportResultCode.SUCCESS }
|
|
159
|
+
: {
|
|
160
|
+
code: ExportResultCode.FAILED,
|
|
161
|
+
error: new Error("Failed to persist envelope in disk."),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
catch (ex) {
|
|
165
|
+
return { code: ExportResultCode.FAILED, error: ex };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Disable collection of statsbeat metrics after max failures
|
|
169
|
+
_incrementStatsbeatFailure() {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
this._statsbeatFailureCount++;
|
|
172
|
+
if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {
|
|
173
|
+
(_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
|
|
174
|
+
(_b = this._longIntervalStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.shutdown();
|
|
175
|
+
this._networkStatsbeatMetrics = undefined;
|
|
176
|
+
this._statsbeatFailureCount = 0;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async _sendFirstPersistedFile() {
|
|
180
|
+
try {
|
|
181
|
+
const envelopes = (await this._persister.shift());
|
|
182
|
+
if (envelopes) {
|
|
183
|
+
await this.send(envelopes);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
diag.warn(`Failed to fetch persisted file`, err);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
_isNetworkError(error) {
|
|
191
|
+
if (error && error.code && error.code === "REQUEST_SEND_ERROR") {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=baseSender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/baseSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAk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,SAAS,CAAC;YAC1C,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACnC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAsB,CAAC;YACvE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC5B;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,eAAe,CAAC,KAAgB;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage, SenderResult } from \"../../types\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { FileSystemPersist } from \"./persist\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { NetworkStatsbeatMetrics } from \"../../export/statsbeat/networkStatsbeatMetrics\";\nimport { getInstance } from \"../../export/statsbeat/longIntervalStatsbeatMetrics\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { MAX_STATSBEAT_FAILURES } from \"../../export/statsbeat/types\";\nimport { BreezeResponse, isRetriable } from \"../../utils/breezeUtils\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n\n/**\n * Base sender class\n * @internal\n */\nexport abstract class BaseSender {\n private readonly _persister: PersistentStorage;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n private _networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private _longIntervalStatsbeatMetrics;\n private _statsbeatFailureCount: number = 0;\n private _batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n\n constructor(\n endpointUrl: string,\n instrumentationKey: string,\n trackStatsbeat: boolean,\n options: AzureMonitorExporterOptions = {}\n ) {\n this._numConsecutiveRedirects = 0;\n this._persister = new FileSystemPersist(instrumentationKey, options);\n if (trackStatsbeat) {\n // Initialize statsbeatMetrics\n this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: instrumentationKey,\n endpointUrl: endpointUrl,\n });\n this._longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: instrumentationKey,\n endpointUrl: endpointUrl,\n });\n }\n this._retryTimer = null;\n }\n\n abstract send(payload: unknown[]): Promise<SenderResult>;\n abstract shutdown(): Promise<void>;\n abstract handlePermanentRedirect(location: string | undefined): void;\n\n /**\n * Export envelopes\n */\n public async exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n if (envelopes.length < 1) {\n return { code: ExportResultCode.SUCCESS };\n }\n\n try {\n const startTime = new Date().getTime();\n const { result, statusCode } = await this.send(envelopes);\n const endTime = new Date().getTime();\n const duration = endTime - startTime;\n this._numConsecutiveRedirects = 0;\n\n if (statusCode === 200) {\n // Success -- @todo: start retry timer\n if (!this._retryTimer) {\n this._retryTimer = setTimeout(() => {\n this._retryTimer = null;\n this._sendFirstPersistedFile();\n }, this._batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n // If we are not exportings statsbeat and statsbeat is not disabled -- count success\n this._networkStatsbeatMetrics?.countSuccess(duration);\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (statusCode === 429 || statusCode === 439) {\n this._networkStatsbeatMetrics?.countThrottle(statusCode);\n }\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n if (breezeResponse.errors) {\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n }\n if (filteredEnvelopes.length > 0) {\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n this._networkStatsbeatMetrics?.countFailure(duration, statusCode);\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n if (this._networkStatsbeatMetrics) {\n if (statusCode) {\n this._networkStatsbeatMetrics.countFailure(duration, statusCode);\n }\n } else {\n this._incrementStatsbeatFailure();\n }\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error: any) {\n const restError = error as RestError;\n if (\n restError.statusCode &&\n (restError.statusCode === 307 || // Temporary redirect\n restError.statusCode === 308)\n ) {\n // Permanent redirect\n this._numConsecutiveRedirects++;\n // To prevent circular redirects\n if (this._numConsecutiveRedirects < 10) {\n if (restError.response && restError.response.headers) {\n const location = restError.response.headers.get(\"location\");\n if (location) {\n // Update sender URL\n this.handlePermanentRedirect(location);\n // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically\n return this.exportEnvelopes(envelopes);\n }\n }\n } else {\n let redirectError = new Error(\"Circular redirect\");\n this._networkStatsbeatMetrics?.countException(redirectError);\n return { code: ExportResultCode.FAILED, error: redirectError };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\n if (restError.statusCode) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n }\n diag.error(\n \"Retrying due to transient client side error. Error message:\",\n restError.message\n );\n return await this._persist(envelopes);\n }\n this._networkStatsbeatMetrics?.countException(restError);\n diag.error(\n \"Envelopes could not be exported and are not retriable. Error message:\",\n restError.message\n );\n return { code: ExportResultCode.FAILED, error: restError };\n }\n }\n\n /**\n * Persist envelopes to disk\n */\n private async _persist(envelopes: unknown[]): Promise<ExportResult> {\n try {\n const success = await this._persister.push(envelopes);\n return success\n ? { code: ExportResultCode.SUCCESS }\n : {\n code: ExportResultCode.FAILED,\n error: new Error(\"Failed to persist envelope in disk.\"),\n };\n } catch (ex: any) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n // Disable collection of statsbeat metrics after max failures\n private _incrementStatsbeatFailure() {\n this._statsbeatFailureCount++;\n if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\n this._networkStatsbeatMetrics?.shutdown();\n this._longIntervalStatsbeatMetrics?.shutdown();\n this._networkStatsbeatMetrics = undefined;\n this._statsbeatFailureCount = 0;\n }\n }\n\n private async _sendFirstPersistedFile(): Promise<void> {\n try {\n const envelopes = (await this._persister.shift()) as Envelope[] | null;\n if (envelopes) {\n await this.send(envelopes);\n }\n } catch (err: any) {\n diag.warn(`Failed to fetch persisted file`, err);\n }\n }\n\n private _isNetworkError(error: RestError): boolean {\n if (error && error.code && error.code === \"REQUEST_SEND_ERROR\") {\n return true;\n }\n return false;\n }\n}\n"]}
|
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import url from "url";
|
|
4
4
|
import { diag } from "@opentelemetry/api";
|
|
5
|
-
import {
|
|
5
|
+
import { redirectPolicyName } from "@azure/core-rest-pipeline";
|
|
6
6
|
import { ApplicationInsightsClient, } from "../../generated";
|
|
7
|
+
import { BaseSender } from "./baseSender";
|
|
7
8
|
const applicationInsightsResource = "https://monitor.azure.com//.default";
|
|
8
9
|
/**
|
|
9
10
|
* Exporter HTTP sender class
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
|
-
export class HttpSender {
|
|
13
|
-
constructor(endpointUrl, options) {
|
|
13
|
+
export class HttpSender extends BaseSender {
|
|
14
|
+
constructor(endpointUrl, instrumentationKey, trackStatsbeat, options) {
|
|
15
|
+
super(endpointUrl, instrumentationKey, trackStatsbeat, options);
|
|
14
16
|
// Build endpoint using provided configuration or default values
|
|
15
17
|
this._appInsightsClientOptions = Object.assign({ host: endpointUrl }, options);
|
|
18
|
+
if (options === null || options === void 0 ? void 0 : options.credential) {
|
|
19
|
+
// Add credentialScopes
|
|
20
|
+
options.credentialScopes = [applicationInsightsResource];
|
|
21
|
+
}
|
|
16
22
|
this._appInsightsClient = new ApplicationInsightsClient(this._appInsightsClientOptions);
|
|
17
23
|
// Handle redirects in HTTP Sender
|
|
18
24
|
this._appInsightsClient.pipeline.removePolicy({ name: redirectPolicyName });
|
|
19
|
-
if (options === null || options === void 0 ? void 0 : options.aadTokenCredential) {
|
|
20
|
-
let scopes = [applicationInsightsResource];
|
|
21
|
-
this._appInsightsClient.pipeline.addPolicy(bearerTokenAuthenticationPolicy({
|
|
22
|
-
credential: options === null || options === void 0 ? void 0 : options.aadTokenCredential,
|
|
23
|
-
scopes: scopes,
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
28
27
|
* Send Azure envelopes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/httpSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE
|
|
1
|
+
{"version":3,"file":"httpSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/httpSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,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OAAO,KACV,UAAU,IACV,CAAC;YAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,mCAAI,EAAE,EAAE,CAAC;SAC7E;QAAC,OAAO,CAAM,EAAE;YACf,MAAM,CAAC,CAAC;SACT;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACxC,CAAC;IAED,uBAAuB,CAAC,QAA4B;QAClD,IAAI,QAAQ,EAAE;YACZ,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACrC,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;gBACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;aACzD;SACF;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport url from \"url\";\nimport { diag } from \"@opentelemetry/api\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport { SenderResult } from \"../../types\";\nimport {\n TelemetryItem as Envelope,\n ApplicationInsightsClient,\n ApplicationInsightsClientOptionalParams,\n TrackOptionalParams,\n} from \"../../generated\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { BaseSender } from \"./baseSender\";\n\nconst applicationInsightsResource = \"https://monitor.azure.com//.default\";\n\n/**\n * Exporter HTTP sender class\n * @internal\n */\nexport class HttpSender extends BaseSender {\n private readonly _appInsightsClient: ApplicationInsightsClient;\n private _appInsightsClientOptions: ApplicationInsightsClientOptionalParams;\n\n constructor(\n endpointUrl: string,\n instrumentationKey: string,\n trackStatsbeat: boolean,\n options?: AzureMonitorExporterOptions\n ) {\n super(endpointUrl, instrumentationKey, trackStatsbeat, options);\n // Build endpoint using provided configuration or default values\n this._appInsightsClientOptions = {\n host: endpointUrl,\n ...options,\n };\n\n if (options?.credential) {\n // Add credentialScopes\n options.credentialScopes = [applicationInsightsResource];\n }\n this._appInsightsClient = new ApplicationInsightsClient(this._appInsightsClientOptions);\n\n // Handle redirects in HTTP Sender\n this._appInsightsClient.pipeline.removePolicy({ name: redirectPolicyName });\n }\n\n /**\n * Send Azure envelopes\n * @internal\n */\n async send(envelopes: Envelope[]): Promise<SenderResult> {\n let options: TrackOptionalParams = {};\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n await this._appInsightsClient.track(envelopes, {\n ...options,\n onResponse,\n });\n\n return { statusCode: response?.status, result: response?.bodyAsText ?? \"\" };\n } catch (e: any) {\n throw e;\n }\n }\n\n /**\n * Shutdown sender\n * @internal\n */\n async shutdown(): Promise<void> {\n diag.info(\"HttpSender shutting down\");\n }\n\n handlePermanentRedirect(location: string | undefined) {\n if (location) {\n const locUrl = new url.URL(location);\n if (locUrl && locUrl.host) {\n this._appInsightsClient.host = \"https://\" + locUrl.host;\n }\n }\n }\n}\n"]}
|