@@ -269,6 +269,12 @@ class Producer {
269269 /* TODO: Add a warning if dr_cb is set? Or else, create a trampoline for it. */
270270 rdKafkaConfig . dr_cb = true ;
271271
272+ if ( Object . hasOwn ( rdKafkaConfig , 'stats_cb' ) ) {
273+ if ( typeof rdKafkaConfig [ 'stats_cb' ] === 'function' )
274+ this . #statsCb = rdKafkaConfig [ 'stats_cb' ] ;
275+ delete rdKafkaConfig [ 'stats_cb' ] ;
276+ }
277+
272278 return rdKafkaConfig ;
273279 }
274280
@@ -373,6 +379,12 @@ class Producer {
373379 this . #logger. error ( err , this . #createProducerBindingMessageMetadata( ) ) ;
374380 }
375381
382+ /**
383+ * Callback for the event.stats event, if defined.
384+ * @private
385+ */
386+ #statsCb = null ;
387+
376388 /**
377389 * Set up the client and connect to the bootstrap brokers.
378390 *
@@ -394,6 +406,9 @@ class Producer {
394406 this . #internalClient. on ( 'event.error' , this . #errorCb. bind ( this ) ) ;
395407 this . #internalClient. on ( 'error' , this . #errorCb. bind ( this ) ) ;
396408 this . #internalClient. on ( 'event.log' , ( msg ) => loggerTrampoline ( msg , this . #logger) ) ;
409+ if ( this . #statsCb) {
410+ this . #internalClient. on ( 'event.stats' , this . #statsCb. bind ( this ) ) ;
411+ }
397412
398413 return new Promise ( ( resolve , reject ) => {
399414 this . #connectPromiseFunc = { resolve, reject } ;
0 commit comments