UNPKG

@reportfy/apm

Version:

Pacote para utilização de apm do reportfy.com.br

74 lines 3.16 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.init = void 0; var config_1 = require("./config"); var log_1 = require("./log"); var event_1 = require("./event"); var customer_1 = require("./customer"); var http_1 = require("./http"); var prometheus_1 = require("./providers/prometheus"); var Provider; (function (Provider) { Provider["prometheus"] = "prometheus"; Provider["reportfy"] = "reportfy"; })(Provider || (Provider = {})); function removeQuote(val) { if (val && val !== undefined) { val = String(val).replace(/\'/g, ""); val = String(val).replace(/\"/g, ""); } return val; } var initDefault = { accessKey: process.env.REPORTFY_ACCESS_KEY, secretKey: process.env.REPORTFY_SECRET_KEY, key: process.env.REPORTFY_KEY, environment: process.env.NODE_ENV || 'development', log: process.env.REPORTFY_LOG || false, tracing: process.env.REPORTFY_TRACING || false, provider: process.env.REPORTFY_PROVIDER || 'reportfy', }; function realMerge(to, from) { return Object.keys(to).reduce(function (acc, val) { if (to[val] && from[val]) acc[val] = removeQuote(to[val]); else if (to[val]) acc[val] = removeQuote(to[val]); else acc[val] = removeQuote(from[val]); return acc; }, {}); } ; function init(_a) { var _b = _a === void 0 ? {} : _a, _c = _b.key, key = _c === void 0 ? "" : _c, _d = _b.accessKey, accessKey = _d === void 0 ? "" : _d, _e = _b.secretKey, secretKey = _e === void 0 ? "" : _e, _f = _b.log, log = _f === void 0 ? false : _f, _g = _b.tracing, tracing = _g === void 0 ? false : _g, _h = _b.environment, environment = _h === void 0 ? "" : _h, _j = _b.provider, provider = _j === void 0 ? "" : _j; try { var data = realMerge({ key: key, accessKey: accessKey, secretKey: secretKey, log: log, tracing: tracing, environment: environment, provider: provider }, initDefault); var eventListening = (0, event_1.getEvent)(data).eventListening; (0, config_1.getConfigFile)(data); if (log) (0, log_1.logs)(data); (0, http_1.LogHttpRequest)(data); eventListening(); return __assign(__assign({}, (data === null || data === void 0 ? void 0 : data.provider.toLowerCase()) === 'prometheus' ? { metricsReportfy: prometheus_1.metricsReportfy } : {}), { customError: (0, customer_1.customEvents)(data) }); } catch (_) { return { customError: realMerge({ key: key, accessKey: accessKey, secretKey: secretKey, log: log, tracing: tracing, environment: environment }, initDefault), metricsReportfy: prometheus_1.metricsReportfy }; } } exports.init = init; //# sourceMappingURL=index.js.map