UNPKG

@azure/monitor-opentelemetry

Version:
99 lines 5.28 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricHandler = void 0; const monitor_opentelemetry_exporter_1 = require("@azure/monitor-opentelemetry-exporter"); const sdk_metrics_1 = require("@opentelemetry/sdk-metrics"); const standardMetrics_js_1 = require("./standardMetrics.js"); const types_js_1 = require("./types.js"); const liveMetrics_js_1 = require("./quickpulse/liveMetrics.js"); const performanceCounters_js_1 = require("./performanceCounters.js"); /** * Azure Monitor OpenTelemetry Metric Handler */ class MetricHandler { /** * Initializes a new instance of the MetricHandler class. * @param config - Distro configuration. * @param options - Metric Handler options. */ constructor(config, options) { var _a, _b, _c, _d, _e, _f, _g; this._collectionInterval = 60000; // 60 seconds this._config = config; // Adding Views of instrumentations will allow customer to add Metric Readers after, and get access to previously created metrics using the views shared state this._views = []; if ((_a = config.instrumentationOptions.azureSdk) === null || _a === void 0 ? void 0 : _a.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" })); } if ((_b = config.instrumentationOptions.http) === null || _b === void 0 ? void 0 : _b.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@azure/opentelemetry-instrumentation-http" })); } if ((_c = config.instrumentationOptions.mongoDb) === null || _c === void 0 ? void 0 : _c.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" })); } if ((_d = config.instrumentationOptions.mySql) === null || _d === void 0 ? void 0 : _d.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@opentelemetry/instrumentation-mysql" })); } if ((_e = config.instrumentationOptions.postgreSql) === null || _e === void 0 ? void 0 : _e.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@opentelemetry/instrumentation-pg" })); } if ((_f = config.instrumentationOptions.redis4) === null || _f === void 0 ? void 0 : _f.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@opentelemetry/instrumentation-redis-4" })); } if ((_g = config.instrumentationOptions.redis) === null || _g === void 0 ? void 0 : _g.enabled) { this._views.push(new sdk_metrics_1.View({ meterName: "@azure/opentelemetry-instrumentation-redis" })); } this._azureExporter = new monitor_opentelemetry_exporter_1.AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions); const metricReaderOptions = { exporter: this._azureExporter, exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval, }; this._metricReader = new sdk_metrics_1.PeriodicExportingMetricReader(metricReaderOptions); if (this._config.enableStandardMetrics && !process.env[types_js_1.APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) { this._standardMetrics = new standardMetrics_js_1.StandardMetrics(this._config); } if (this._config.enableLiveMetrics) { this._liveMetrics = new liveMetrics_js_1.LiveMetrics(this._config); } if (this._config.enablePerformanceCounters) { this._performanceCounters = new performanceCounters_js_1.PerformanceCounterMetrics(this._config); } } getMetricReader() { return this._metricReader; } getViews() { return this._views; } markSpanAsProcessed(span) { var _a; (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.markSpanAsProcessed(span); } recordSpan(span) { var _a, _b, _c; (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.recordSpan(span); (_b = this._liveMetrics) === null || _b === void 0 ? void 0 : _b.recordSpan(span); (_c = this._performanceCounters) === null || _c === void 0 ? void 0 : _c.recordSpan(span); } recordLog(logRecord) { var _a, _b, _c; (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.recordLog(logRecord); (_b = this._liveMetrics) === null || _b === void 0 ? void 0 : _b.recordLog(logRecord); (_c = this._performanceCounters) === null || _c === void 0 ? void 0 : _c.recordLog(logRecord); } /** * Shutdown handler */ // eslint-disable-next-line @typescript-eslint/require-await async shutdown() { var _a, _b, _c; (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.shutdown(); (_b = this._liveMetrics) === null || _b === void 0 ? void 0 : _b.shutdown(); (_c = this._performanceCounters) === null || _c === void 0 ? void 0 : _c.shutdown(); } } exports.MetricHandler = MetricHandler; //# sourceMappingURL=handler.js.map