1
1
package datadog .trace .instrumentation .jetty9 ;
2
2
3
+ import datadog .context .Context ;
3
4
import datadog .trace .api .gateway .Flow ;
4
5
import datadog .trace .bootstrap .instrumentation .api .AgentSpan ;
5
6
import datadog .trace .instrumentation .jetty .JettyBlockingHelper ;
25
26
* </code> is replaced with: <code>
26
27
* case REQUEST_DISPATCH:
27
28
* // ...
28
- * if (span != null && span.getBlockingAction() != null &&
29
- * JettyBlockingHelper.block(this.getRequest(), this.getResponse())) {
29
+ * if (JettyBlockingHelper.block(this.getRequest(), this.getResponse(), context)) {
30
30
* // nothing
31
31
* } else {
32
32
* getServer().handle(this);
@@ -82,7 +82,7 @@ public class HandleVisitor extends MethodVisitor {
82
82
private static final Logger log = LoggerFactory .getLogger (HandleVisitor .class );
83
83
84
84
private boolean lookForStore ;
85
- private int agentSpanVar = -1 ;
85
+ private int contextVar = -1 ;
86
86
private boolean success ;
87
87
private final String methodName ;
88
88
@@ -98,12 +98,13 @@ DelayCertainInsMethodVisitor delayVisitorDelegate() {
98
98
@ Override
99
99
public void visitMethodInsn (
100
100
int opcode , String owner , String name , String descriptor , boolean isInterface ) {
101
- if (agentSpanVar == -1 ) {
101
+ if (contextVar == -1 ) {
102
102
lookForStore =
103
103
!lookForStore
104
104
&& opcode == Opcodes .INVOKEVIRTUAL
105
105
&& name .equals ("startSpan" )
106
- && descriptor .endsWith ("Ldatadog/trace/bootstrap/instrumentation/api/AgentSpan;" );
106
+ && descriptor .endsWith ("Ldatadog.context.Context;" );
107
+ && descriptor .endsWith ("Ldatadog/context/Context;" );
107
108
} else if (!success
108
109
&& opcode == Opcodes .INVOKEVIRTUAL
109
110
&& owner .equals ("org/eclipse/jetty/server/Server" )
@@ -124,24 +125,8 @@ public void visitMethodInsn(
124
125
return ;
125
126
}
126
127
127
- Label doBlockLabel = new Label ();
128
- Label beforeHandle = new Label ();
129
128
Label afterHandle = new Label ();
130
129
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 );
145
130
super .visitVarInsn (Opcodes .ALOAD , 0 );
146
131
super .visitMethodInsn (
147
132
Opcodes .INVOKEVIRTUAL ,
@@ -156,27 +141,17 @@ public void visitMethodInsn(
156
141
"getResponse" ,
157
142
"()Lorg/eclipse/jetty/server/Response;" ,
158
143
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 );
167
145
super .visitMethodInsn (
168
146
Opcodes .INVOKESTATIC ,
169
147
Type .getInternalName (JettyBlockingHelper .class ),
170
148
"block" ,
171
149
"(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 )
174
151
+ ")Z" ,
175
152
false );
176
153
super .visitJumpInsn (Opcodes .IFNE , afterHandle );
177
154
178
- super .visitLabel (beforeHandle );
179
- super .visitFrame (Opcodes .F_SAME , 0 , null , 0 , null );
180
155
mv .commitVisitations (savedVisitations );
181
156
super .visitMethodInsn (opcode , owner , name , descriptor , isInterface );
182
157
super .visitLabel (afterHandle );
@@ -214,9 +189,9 @@ public void visitMethodInsn(
214
189
Label beforeRegularDispatch = new Label ();
215
190
Label afterRegularDispatch = new Label ();
216
191
217
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
192
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
218
193
super .visitJumpInsn (Opcodes .IFNULL , beforeRegularDispatch );
219
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
194
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
220
195
super .visitMethodInsn (
221
196
Opcodes .INVOKEINTERFACE ,
222
197
"datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
@@ -248,14 +223,14 @@ public void visitMethodInsn(
248
223
"getResponse" ,
249
224
"()Lorg/eclipse/jetty/server/Response;" ,
250
225
false );
251
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
226
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
252
227
super .visitMethodInsn (
253
228
Opcodes .INVOKEINTERFACE ,
254
229
"datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
255
230
"getRequestBlockingAction" ,
256
231
"()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
257
232
true );
258
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
233
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
259
234
260
235
// create the lambda
261
236
super .visitInvokeDynamicInsn (
@@ -337,7 +312,7 @@ private boolean checkDispatchMethodState(final List<Function> savedVisitations)
337
312
@ Override
338
313
public void visitVarInsn (int opcode , int varIndex ) {
339
314
if (lookForStore && opcode == Opcodes .ASTORE ) {
340
- agentSpanVar = varIndex ;
315
+ contextVar = varIndex ;
341
316
lookForStore = false ;
342
317
}
343
318
0 commit comments