From d6b88a5c8d5ce727625a2183e0838baeb7b13551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=BAlio=20Ornelas?= Date: Tue, 26 Mar 2019 10:43:19 +0100 Subject: [PATCH] Merge pull request #321 from tulios/only-emit-events-if-there-are-listeners Only emit events if there are listeners --- src/instrumentation/emitter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/instrumentation/emitter.js b/src/instrumentation/emitter.js index b45cd1750..e9323c988 100644 --- a/src/instrumentation/emitter.js +++ b/src/instrumentation/emitter.js @@ -19,8 +19,10 @@ module.exports = class InstrumentationEventEmitter { throw new KafkaJSError('Invalid event name', { retriable: false }) } - const event = new InstrumentationEvent(eventName, payload) - this.emitter.emit(eventName, event) + if (this.emitter.listenerCount(eventName) > 0) { + const event = new InstrumentationEvent(eventName, payload) + this.emitter.emit(eventName, event) + } } /**