File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,12 +85,16 @@ export class BunyanInstrumentation extends InstrumentationBase {
8585 inherits ( LoggerTraced , Logger ) ;
8686
8787 const patchedExports = Object . assign ( LoggerTraced , Logger ) ;
88+ // Ensure patchedExports.prototype points to LoggerTraced.prototype
89+ // so that prototype modifications (like bunyan.prototype.monitor = ...)
90+ // work correctly on logger instances
91+ patchedExports . prototype = LoggerTraced . prototype ;
8892
8993 this . _wrap (
9094 patchedExports ,
9195 'createLogger' ,
9296 // eslint-disable-next-line @typescript-eslint/no-explicit-any
93- this . _getPatchedCreateLogger ( ) as any
97+ this . _getPatchedCreateLogger ( LoggerTraced . prototype ) as any
9498 ) ;
9599
96100 return patchedExports ;
@@ -138,11 +142,14 @@ export class BunyanInstrumentation extends InstrumentationBase {
138142 } ;
139143 }
140144
141- private _getPatchedCreateLogger ( ) {
145+ private _getPatchedCreateLogger ( loggerTracedPrototype : any ) {
142146 return ( original : ( ...args : unknown [ ] ) => void ) => {
143147 const instrumentation = this ;
144148 return function patchedCreateLogger ( ...args : unknown [ ] ) {
145149 const logger = original ( ...args ) ;
150+ // Ensure logger instances inherit from LoggerTraced.prototype so that
151+ // prototype modifications (like bunyan.prototype.monitor = ...) work correctly
152+ Object . setPrototypeOf ( logger , loggerTracedPrototype ) ;
146153 instrumentation . _addStream ( logger ) ;
147154 return logger ;
148155 } ;
You can’t perform that action at this time.
0 commit comments