UNPKG

newrelic-nestjs-instrumentation

Version:

Comprehensive New Relic instrumentation for NestJS applications - SQS, Kafka, HTTP/2, cron jobs and custom protocols

58 lines 2.69 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NewRelicInterceptor = void 0; const common_1 = require("@nestjs/common"); const rxjs_1 = require("rxjs"); const internal_1 = require("./internal"); const events_1 = __importDefault(require("events")); const start_newrelic_transaction_if_absent_1 = require("./start-newrelic-transaction-if-absent"); let NewRelicInterceptor = class NewRelicInterceptor { customContext; emitter; constructor(customContext, emitter) { this.customContext = customContext; this.emitter = emitter; } intercept(context, next) { (0, start_newrelic_transaction_if_absent_1.startNewrelicTransactionIfAbsent)(context); return next.handle().pipe((0, rxjs_1.tap)({ next: this.finishTransaction, error: this.finishTransaction, })); } finishTransaction = () => { try { const transactionId = this.customContext.customTransactionId; const transaction = this.customContext.transaction; if (!transactionId || !transaction) return; this.emitter.emit('transactionFinished', transactionId); transaction.end(); } catch { } }; }; exports.NewRelicInterceptor = NewRelicInterceptor; exports.NewRelicInterceptor = NewRelicInterceptor = __decorate([ (0, common_1.Injectable)(), __param(1, (0, common_1.Inject)(internal_1.emitterSymbol)), __metadata("design:paramtypes", [internal_1.InternalContext, events_1.default]) ], NewRelicInterceptor); //# sourceMappingURL=newrelic.interceptor.js.map