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) + } } /**