UNPKG

applicationinsights

Version:
107 lines 5.71 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AKSLoader = void 0; const os = __importStar(require("os")); const path = __importStar(require("path")); const diagnosticLogger_1 = require("./diagnostics/diagnosticLogger"); const fileWriter_1 = require("./diagnostics/writers/fileWriter"); const statusLogger_1 = require("./diagnostics/statusLogger"); const agentLoader_1 = require("./agentLoader"); const exporter_metrics_otlp_proto_1 = require("@opentelemetry/exporter-metrics-otlp-proto"); const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http"); const sdk_metrics_1 = require("@opentelemetry/sdk-metrics"); const types_1 = require("./types"); class AKSLoader extends agentLoader_1.AgentLoader { constructor() { super(); if (this._canLoad) { this._options.instrumentationOptions = Object.assign(Object.assign({}, this._options.instrumentationOptions), { console: { enabled: true }, bunyan: { enabled: true }, winston: { enabled: true } }); let statusLogDir = '/var/log/applicationinsights/'; if (this._isWindows) { if (process.env.HOME) { statusLogDir = path.join(process.env.HOME, "LogFiles", "ApplicationInsights", "status"); } else { statusLogDir = path.join(os.tmpdir(), "Microsoft", "ApplicationInsights", "StatusMonitor", "LogFiles", "ApplicationInsights", "status"); } } this._statusLogger = new statusLogger_1.StatusLogger(this._instrumentationKey, new fileWriter_1.FileWriter(statusLogDir, 'status_nodejs.json', { append: false, deleteOnExit: false, renamePolicy: 'overwrite', sizeLimit: 1024 * 1024, })); this._diagnosticLogger = new diagnosticLogger_1.DiagnosticLogger(this._instrumentationKey, new fileWriter_1.FileWriter(statusLogDir, 'applicationinsights-extension.log', { append: true, deleteOnExit: false, renamePolicy: 'overwrite', sizeLimit: 1024 * 1024, // 1 MB })); // Create metricReaders array and add OTLP reader if environment variables request it try { const metricReaders = []; const metricsExporter = (process.env.OTEL_METRICS_EXPORTER || '').toLowerCase(); const exportersList = metricsExporter.split(',').map(exp => exp.trim()); const hasOtlpExporter = exportersList.includes('otlp'); if (hasOtlpExporter && (process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT)) { try { // Determine which exporter to use based on protocol setting const protocol = process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL || process.env.OTEL_EXPORTER_OTLP_PROTOCOL; let otlpExporter; if (protocol === 'http/json') { otlpExporter = new exporter_metrics_otlp_http_1.OTLPMetricExporter(); } else { // Use protobuf for 'http/protobuf', 'grpc', or any other value otlpExporter = new exporter_metrics_otlp_proto_1.OTLPMetricExporter(); } const otlpMetricReader = new sdk_metrics_1.PeriodicExportingMetricReader({ exporter: otlpExporter, exportIntervalMillis: types_1.OTLP_METRIC_EXPORTER_EXPORT_INTERVAL, }); metricReaders.push(otlpMetricReader); } catch (error) { console.warn("AKSLoader: Failed to create OTLP metric reader:", error); } } // Attach metricReaders to the options so the distro can consume them if ((metricReaders || []).length > 0) { this._options.metricReaders = metricReaders; } } catch (err) { console.warn("AKSLoader: Error while preparing metricReaders:", err); } } } } exports.AKSLoader = AKSLoader; //# sourceMappingURL=aksLoader.js.map