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,13 @@ 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;" );
107+ && descriptor .endsWith ("Ldatadog/context/Context;" );
107108 } else if (!success
108109 && opcode == Opcodes .INVOKEVIRTUAL
109110 && owner .equals ("org/eclipse/jetty/server/Server" )
@@ -124,24 +125,8 @@ public void visitMethodInsn(
124125 return ;
125126 }
126127
127- Label doBlockLabel = new Label ();
128- Label beforeHandle = new Label ();
129128 Label afterHandle = new Label ();
130129
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 );
145130 super .visitVarInsn (Opcodes .ALOAD , 0 );
146131 super .visitMethodInsn (
147132 Opcodes .INVOKEVIRTUAL ,
@@ -156,27 +141,17 @@ public void visitMethodInsn(
156141 "getResponse" ,
157142 "()Lorg/eclipse/jetty/server/Response;" ,
158143 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 );
144+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
167145 super .visitMethodInsn (
168146 Opcodes .INVOKESTATIC ,
169147 Type .getInternalName (JettyBlockingHelper .class ),
170148 "block" ,
171149 "(Lorg/eclipse/jetty/server/Request;Lorg/eclipse/jetty/server/Response;"
172- + Type .getDescriptor (Flow .Action .RequestBlockingAction .class )
173- + Type .getDescriptor (AgentSpan .class )
150+ + Type .getDescriptor (Context .class )
174151 + ")Z" ,
175152 false );
176153 super .visitJumpInsn (Opcodes .IFNE , afterHandle );
177154
178- super .visitLabel (beforeHandle );
179- super .visitFrame (Opcodes .F_SAME , 0 , null , 0 , null );
180155 mv .commitVisitations (savedVisitations );
181156 super .visitMethodInsn (opcode , owner , name , descriptor , isInterface );
182157 super .visitLabel (afterHandle );
@@ -214,9 +189,9 @@ public void visitMethodInsn(
214189 Label beforeRegularDispatch = new Label ();
215190 Label afterRegularDispatch = new Label ();
216191
217- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
192+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
218193 super .visitJumpInsn (Opcodes .IFNULL , beforeRegularDispatch );
219- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
194+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
220195 super .visitMethodInsn (
221196 Opcodes .INVOKEINTERFACE ,
222197 "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
@@ -248,14 +223,14 @@ public void visitMethodInsn(
248223 "getResponse" ,
249224 "()Lorg/eclipse/jetty/server/Response;" ,
250225 false );
251- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
226+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
252227 super .visitMethodInsn (
253228 Opcodes .INVOKEINTERFACE ,
254229 "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
255230 "getRequestBlockingAction" ,
256231 "()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
257232 true );
258- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
233+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
259234
260235 // create the lambda
261236 super .visitInvokeDynamicInsn (
@@ -337,7 +312,7 @@ private boolean checkDispatchMethodState(final List<Function> savedVisitations)
337312 @ Override
338313 public void visitVarInsn (int opcode , int varIndex ) {
339314 if (lookForStore && opcode == Opcodes .ASTORE ) {
340- agentSpanVar = varIndex ;
315+ contextVar = varIndex ;
341316 lookForStore = false ;
342317 }
343318
0 commit comments