File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -457,6 +457,50 @@ public static void methodExit(
457457}
458458```
459459
460+ ## Logging in Instrumentations
461+
462+ Logging should only be used in helper classes where you can easily add and access a static logger field:
463+
464+ ``` java
465+ // GOOD - Logger only in helper classes
466+ public class MyInstrumentationHelper {
467+ private static final Logger log = LoggerFactory . getLogger(MyInstrumentationHelper . class);
468+
469+ public void helperMethod () {
470+ log. debug(" Logging from helper is safe" );
471+ // This helper is called from instrumentation/advice
472+ }
473+ }
474+ ```
475+
476+ ` org.slf4j ` is the logging facade to use.
477+ It is shaded and redirects to our internal logger.
478+
479+ > [ !CAUTION]
480+ > Do NOT put logger fields in instrumentation classes or refer to them in advice:
481+
482+ ``` java
483+ // BAD - Logger in instrumentation class
484+ public class MyInstrumentation extends InstrumenterModule .Tracing {
485+ private static final Logger log = LoggerFactory . getLogger(MyInstrumentation . class);
486+ }
487+ ```
488+
489+ > [ !CAUTION]
490+ > Do NOT put logger fields in Advice classes:
491+
492+ ``` java
493+ // BAD - Logger in advice class
494+ public class MyAdvice {
495+ private static final Logger log = LoggerFactory . getLogger(MyAdvice . class);
496+
497+ @Advice.OnMethodEnter (suppress = Throwable . class)
498+ public static void enter () {
499+ log. debug(" Entering method" ); // BAD
500+ }
501+ }
502+ ```
503+
460504## InjectAdapters & Custom GETTERs/SETTERs
461505
462506Custom Inject Adapter static instances typically named ` SETTER ` implement the ` AgentPropagation.Setter ` interface and
You can’t perform that action at this time.
0 commit comments