UNPKG

applicationinsights

Version:

Microsoft Application Insights module for Node.js

60 lines 2.21 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. Object.defineProperty(exports, "__esModule", { value: true }); exports.EtwWritter = void 0; const fs = require("fs"); const path = require("path"); const util_1 = require("../../../shared/util"); class EtwWritter { constructor() { const nodeMajVer = parseInt(process.versions.node.split('.')[0], 10); try { this._etwModule = this._loadEtwModule(nodeMajVer); if (this._etwModule) { console.log('AppInsightsAgent: Successfully loaded ETW'); } else { console.log('AppInsightsAgent: ETW could not be loaded'); } } catch (e) { console.log('Could not load ETW. Defaulting to console logging', e); this._etwModule = undefined; } } log(message, optional) { if (this._etwModule) { // eslint-disable-next-line @typescript-eslint/ban-types this._etwModule.logInfoEvent(message, ...optional); } else { console.log(util_1.Util.getInstance().stringify(message)); } } error(message, optional) { if (this._etwModule) { // eslint-disable-next-line @typescript-eslint/ban-types this._etwModule.logErrEvent(message, ...optional); } else { console.error(util_1.Util.getInstance().stringify(message)); } } _loadEtwModule(nodeMajVer) { // Try to load precompiled ETW module if it exists and is "importable" const dirname = path.join(__dirname, '../../../../../../../etw', `etw_${nodeMajVer}`); try { // throws an error if directory is not readable / does not exist fs.accessSync(dirname, fs.constants.R_OK); // eslint-disable-next-line @typescript-eslint/no-var-requires return require(dirname); } catch (e) { // Could not load ETW, return nothing return undefined; } } } exports.EtwWritter = EtwWritter; //# sourceMappingURL=etwWritter.js.map