@@ -39,11 +39,12 @@ public Size apply(final MethodVisitor mv, final Implementation.Context context)
3939 final boolean exitOnFailure = InstrumenterConfig .get ().isInternalExitOnFailure ();
4040 final String logMethod = exitOnFailure ? "error" : "debug" ;
4141
42- // Writes the following bytecode (note that two statements are conditionally written):
42+ // Writes the following bytecode (note that some statements are conditionally
43+ // written):
4344 //
4445 // BlockingExceptionHandler.rethrowIfBlockingException(t); // when appSecEnabled=true
4546 // try {
46- // InstrumentationErrors.recordError(t);
47+ // if (InstrumentationErrors.isEnabled()) InstrumentationErrors.recordError(t);
4748 // org.slf4j.LoggerFactory.getLogger((Class)ExceptionLogger.class)
4849 // .error("Failed to handle exception in instrumentation for ...", t);
4950 // System.exit(1); // when exitOnFailure=true
@@ -69,15 +70,28 @@ public Size apply(final MethodVisitor mv, final Implementation.Context context)
6970 "(Ljava/lang/Throwable;)Ljava/lang/Throwable;" );
7071 }
7172
73+ final Label skipRecord = new Label ();
74+
7275 mv .visitTryCatchBlock (logStart , logEnd , eatException , "java/lang/Throwable" );
7376 mv .visitLabel (logStart );
77+ mv .visitMethodInsn (
78+ Opcodes .INVOKESTATIC ,
79+ "datadog/trace/bootstrap/InstrumentationErrors" ,
80+ "isEnabled" ,
81+ "()Z" ,
82+ false );
83+ mv .visitJumpInsn (Opcodes .IFEQ , skipRecord );
7484 mv .visitInsn (Opcodes .DUP ); // stack: (top) throwable,throwable
75- // invoke recordError on our exception tracker
7685 mv .visitMethodInsn (
7786 Opcodes .INVOKESTATIC ,
7887 "datadog/trace/bootstrap/InstrumentationErrors" ,
7988 "recordError" ,
80- "(Ljava/lang/Throwable;)V" );
89+ "(Ljava/lang/Throwable;)V" ,
90+ false );
91+ mv .visitLabel (skipRecord );
92+ if (frames ) {
93+ mv .visitFrame (Opcodes .F_SAME1 , 0 , null , 1 , new Object [] {"java/lang/Throwable" });
94+ }
8195
8296 // stack: (top) throwable
8397 mv .visitLdcInsn (Type .getType ("L" + HANDLER_NAME + ";" ));
0 commit comments