11package datadog .trace .instrumentation .jetty9 ;
22
3+ import datadog .context .Context ;
34import datadog .trace .api .gateway .Flow ;
45import datadog .trace .bootstrap .instrumentation .api .AgentSpan ;
56import datadog .trace .instrumentation .jetty .JettyBlockingHelper ;
2526 * </code> is replaced with: <code>
2627 * case REQUEST_DISPATCH:
2728 * // ...
28- * if (span != null && span.getBlockingAction() != null &&
29- * JettyBlockingHelper.block(this.getRequest(), this.getResponse())) {
29+ * if (JettyBlockingHelper.block(this.getRequest(), this.getResponse(), context)) {
3030 * // nothing
3131 * } else {
3232 * getServer().handle(this);
@@ -82,7 +82,7 @@ public class HandleVisitor extends MethodVisitor {
8282 private static final Logger log = LoggerFactory .getLogger (HandleVisitor .class );
8383
8484 private boolean lookForStore ;
85- private int agentSpanVar = -1 ;
85+ private int contextVar = -1 ;
8686 private boolean success ;
8787 private final String methodName ;
8888
@@ -98,12 +98,12 @@ DelayCertainInsMethodVisitor delayVisitorDelegate() {
9898 @ Override
9999 public void visitMethodInsn (
100100 int opcode , String owner , String name , String descriptor , boolean isInterface ) {
101- if (agentSpanVar == -1 ) {
101+ if (contextVar == -1 ) {
102102 lookForStore =
103103 !lookForStore
104104 && opcode == Opcodes .INVOKEVIRTUAL
105105 && name .equals ("startSpan" )
106- && descriptor .endsWith ("Ldatadog/trace/bootstrap/instrumentation/api/AgentSpan ;" );
106+ && descriptor .endsWith ("Ldatadog.context.Context ;" );
107107 } else if (!success
108108 && opcode == Opcodes .INVOKEVIRTUAL
109109 && owner .equals ("org/eclipse/jetty/server/Server" )
@@ -124,24 +124,8 @@ public void visitMethodInsn(
124124 return ;
125125 }
126126
127- Label doBlockLabel = new Label ();
128- Label beforeHandle = new Label ();
129127 Label afterHandle = new Label ();
130128
131- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
132- super .visitJumpInsn (Opcodes .IFNULL , beforeHandle );
133- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
134- super .visitMethodInsn (
135- Opcodes .INVOKEINTERFACE ,
136- "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
137- "getRequestBlockingAction" ,
138- "()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
139- true );
140- super .visitJumpInsn (Opcodes .IFNONNULL , doBlockLabel );
141- super .visitJumpInsn (Opcodes .GOTO , beforeHandle );
142-
143- super .visitLabel (doBlockLabel );
144- super .visitFrame (Opcodes .F_SAME , 0 , null , 0 , null );
145129 super .visitVarInsn (Opcodes .ALOAD , 0 );
146130 super .visitMethodInsn (
147131 Opcodes .INVOKEVIRTUAL ,
@@ -156,27 +140,17 @@ public void visitMethodInsn(
156140 "getResponse" ,
157141 "()Lorg/eclipse/jetty/server/Response;" ,
158142 false );
159- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
160- super .visitMethodInsn (
161- Opcodes .INVOKEINTERFACE ,
162- "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
163- "getRequestBlockingAction" ,
164- "()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
165- true );
166- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
143+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
167144 super .visitMethodInsn (
168145 Opcodes .INVOKESTATIC ,
169146 Type .getInternalName (JettyBlockingHelper .class ),
170147 "block" ,
171148 "(Lorg/eclipse/jetty/server/Request;Lorg/eclipse/jetty/server/Response;"
172- + Type .getDescriptor (Flow .Action .RequestBlockingAction .class )
173- + Type .getDescriptor (AgentSpan .class )
149+ + Type .getDescriptor (Context .class )
174150 + ")Z" ,
175151 false );
176152 super .visitJumpInsn (Opcodes .IFNE , afterHandle );
177153
178- super .visitLabel (beforeHandle );
179- super .visitFrame (Opcodes .F_SAME , 0 , null , 0 , null );
180154 mv .commitVisitations (savedVisitations );
181155 super .visitMethodInsn (opcode , owner , name , descriptor , isInterface );
182156 super .visitLabel (afterHandle );
@@ -214,9 +188,9 @@ public void visitMethodInsn(
214188 Label beforeRegularDispatch = new Label ();
215189 Label afterRegularDispatch = new Label ();
216190
217- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
191+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
218192 super .visitJumpInsn (Opcodes .IFNULL , beforeRegularDispatch );
219- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
193+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
220194 super .visitMethodInsn (
221195 Opcodes .INVOKEINTERFACE ,
222196 "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
@@ -248,14 +222,14 @@ public void visitMethodInsn(
248222 "getResponse" ,
249223 "()Lorg/eclipse/jetty/server/Response;" ,
250224 false );
251- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
225+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
252226 super .visitMethodInsn (
253227 Opcodes .INVOKEINTERFACE ,
254228 "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
255229 "getRequestBlockingAction" ,
256230 "()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
257231 true );
258- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
232+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
259233
260234 // create the lambda
261235 super .visitInvokeDynamicInsn (
@@ -337,7 +311,7 @@ private boolean checkDispatchMethodState(final List<Function> savedVisitations)
337311 @ Override
338312 public void visitVarInsn (int opcode , int varIndex ) {
339313 if (lookForStore && opcode == Opcodes .ASTORE ) {
340- agentSpanVar = varIndex ;
314+ contextVar = varIndex ;
341315 lookForStore = false ;
342316 }
343317
0 commit comments