applicationinsights
Version:
Microsoft Application Insights module for Node.js
89 lines • 3.84 kB
JavaScript
;
// 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.JsonConfig = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const api_1 = require("@opentelemetry/api");
const ENV_CONFIGURATION_FILE = "APPLICATIONINSIGHTS_CONFIGURATION_FILE";
const ENV_CONTENT = "APPLICATIONINSIGHTS_CONFIGURATION_CONTENT";
class JsonConfig {
constructor() {
this._loadJsonFile();
}
static getInstance() {
if (!JsonConfig._instance) {
JsonConfig._instance = new JsonConfig();
}
return JsonConfig._instance;
}
_loadJsonFile() {
let jsonString = "";
const contentJsonConfig = process.env[ENV_CONTENT];
// JSON string added directly in env variable
if (contentJsonConfig) {
jsonString = contentJsonConfig;
}
// JSON file
else {
const configFileName = "applicationinsights.json";
const rootPath = path.join(__dirname, "../../../"); // Root of folder (__dirname = ../dist-esm/src)
let tempDir = path.join(rootPath, configFileName); // default
const configFile = process.env[ENV_CONFIGURATION_FILE];
if (configFile) {
if (path.isAbsolute(configFile)) {
tempDir = configFile;
}
else {
tempDir = path.join(rootPath, configFile); // Relative path to applicationinsights folder
}
}
try {
jsonString = fs.readFileSync(tempDir, "utf8");
}
catch (err) {
api_1.diag.info("Failed to read JSON config file: ", err);
}
}
try {
const jsonConfig = JSON.parse(jsonString);
this.enableAutoCollectExceptions = jsonConfig.enableAutoCollectExceptions;
this.otlpLogExporterConfig = jsonConfig.otlpLogExporterConfig;
this.otlpMetricExporterConfig = jsonConfig.otlpMetricExporterConfig;
this.otlpTraceExporterConfig = jsonConfig.otlpTraceExporterConfig;
this.enableAutoCollectPerformance = jsonConfig.enableAutoCollectPerformance;
this.azureMonitorExporterOptions = jsonConfig.azureMonitorExporterOptions;
this.samplingRatio = jsonConfig.samplingRatio;
this.instrumentationOptions = jsonConfig.instrumentationOptions;
}
catch (err) {
api_1.diag.info("Missing or invalid JSON config file: ", err);
}
}
}
exports.JsonConfig = JsonConfig;
//# sourceMappingURL=jsonConfig.js.map