UNPKG

@azure/monitor-opentelemetry

Version:
101 lines 4.25 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 { _azureExporter; _metricReader; _standardMetrics; _performanceCounters; _liveMetrics; _config; _views; /** * Initializes a new instance of the MetricHandler class. * @param config - Distro configuration. * @param options - Metric Handler options. */ constructor(config) { const defaultInterval = 60000; 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 (config.instrumentationOptions.azureSdk?.enabled) { this._views.push({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" }); } if (config.instrumentationOptions.http?.enabled) { this._views.push({ meterName: "@azure/opentelemetry-instrumentation-http" }); } if (config.instrumentationOptions.mongoDb?.enabled) { this._views.push({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }); } if (config.instrumentationOptions.mySql?.enabled) { this._views.push({ meterName: "@opentelemetry/instrumentation-mysql" }); } if (config.instrumentationOptions.postgreSql?.enabled) { this._views.push({ meterName: "@opentelemetry/instrumentation-pg" }); } if (config.instrumentationOptions.redis4?.enabled) { this._views.push({ meterName: "@opentelemetry/instrumentation-redis-4" }); } if (config.instrumentationOptions.redis?.enabled) { this._views.push({ meterName: "@azure/opentelemetry-instrumentation-redis" }); } this._azureExporter = new monitor_opentelemetry_exporter_1.AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions); const metricReaderOptions = { exporter: this._azureExporter, exportIntervalMillis: this._config.metricExportIntervalMillis || defaultInterval, }; 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) { this._standardMetrics?.markSpanAsProcessed(span); } recordSpan(span) { this._standardMetrics?.recordSpan(span); this._liveMetrics?.recordSpan(span); this._performanceCounters?.recordSpan(span); } recordLog(logRecord) { this._standardMetrics?.recordLog(logRecord); this._liveMetrics?.recordLog(logRecord); this._performanceCounters?.recordLog(logRecord); } /** * Shutdown handler */ // eslint-disable-next-line @typescript-eslint/require-await async shutdown() { this._standardMetrics?.shutdown(); this._liveMetrics?.shutdown(); this._performanceCounters?.shutdown(); } } exports.MetricHandler = MetricHandler; //# sourceMappingURL=handler.js.map