File tree Expand file tree Collapse file tree
dd-java-agent/agent-tooling/src
main/java/datadog/trace/agent/tooling
groovy/datadog/trace/agent/test
java/datadog/trace/agent/test
dd-trace-ot/src/test/groovy/datadog/opentracing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import datadog .trace .agent .bootstrap .ExceptionLogger ;
44import net .bytebuddy .implementation .Implementation ;
55import net .bytebuddy .implementation .bytecode .StackManipulation ;
6- import net .bytebuddy .implementation .bytecode .StackSize ;
76import net .bytebuddy .jar .asm .Label ;
87import net .bytebuddy .jar .asm .MethodVisitor ;
98import net .bytebuddy .jar .asm .Opcodes ;
@@ -19,7 +18,8 @@ public class ExceptionHandlers {
1918
2019 private static final StackManipulation EXCEPTION_STACK_HANDLER =
2120 new StackManipulation () {
22- private final Size size = StackSize .SINGLE .toDecreasingSize ();
21+ // Pops one Throwable off the stack. Maxes the stack to at least 3.
22+ private final Size size = new StackManipulation .Size (-1 , 3 );
2323
2424 @ Override
2525 public boolean isValid () {
Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ class ExceptionHandlerTest extends Specification {
3333 .advice(
3434 isMethod(). and(named(" isInstrumented" )),
3535 BadAdvice . getName()))
36+ .transform(
37+ new AgentBuilder.Transformer.ForAdvice ()
38+ .with(new AgentBuilder.LocationStrategy.Simple (ClassFileLocator.ForClassLoader . of(BadAdvice . getClassLoader())))
39+ .withExceptionHandler(ExceptionHandlers . defaultExceptionHandler())
40+ .advice(
41+ isMethod(). and(named(" smallStack" ). or(named(" largeStack" ))),
42+ BadAdvice.NoOpAdvice . getName()))
3643 .asDecorator()
3744
3845 ByteBuddyAgent . install()
@@ -80,9 +87,31 @@ class ExceptionHandlerTest extends Specification {
8087 testAppender. list. size() == initLogEvents
8188 }
8289
90+ def " exception handler sets the correct stack size" () {
91+ when :
92+ SomeClass . smallStack()
93+ SomeClass . largeStack()
94+
95+ then :
96+ noExceptionThrown()
97+ }
98+
8399 static class SomeClass {
84100 static boolean isInstrumented () {
85101 return false
86102 }
103+
104+ static void smallStack () {
105+ // a method with a max stack of 0
106+ }
107+
108+ static void largeStack () {
109+ // a method with a max stack of 6
110+ long l = 22l
111+ int i = 3
112+ double d = 32.2d
113+ Object o = new Object ()
114+ println " large stack: $l $i $d $o "
115+ }
87116 }
88117}
Original file line number Diff line number Diff line change @@ -8,4 +8,11 @@ public static void throwAnException(@Advice.Return(readOnly = false) boolean ret
88 returnVal = true ;
99 throw new RuntimeException ("Test Exception" );
1010 }
11+
12+ public static class NoOpAdvice {
13+ @ Advice .OnMethodExit (suppress = Throwable .class )
14+ public static void doNothing () {
15+ System .currentTimeMillis ();
16+ }
17+ }
1118}
File renamed without changes.
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import spock.lang.Timeout
77
88import java.util.concurrent.TimeUnit
99
10- @Timeout (1 )
10+ @Timeout (10 )
1111class DDSpanTest extends Specification {
1212 def writer = new ListWriter ()
1313 def tracer = new DDTracer (writer)
You can’t perform that action at this time.
0 commit comments