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
* // ...
29
+ * AgentSpan span = Java8BytecodeBridge(context);
28
30
* if (span != null && span.getBlockingAction() != null &&
29
31
* JettyBlockingHelper.block(this.getRequest(), this.getResponse())) {
30
32
* // nothing
@@ -82,7 +84,7 @@ public class HandleVisitor extends MethodVisitor {
82
84
private static final Logger log = LoggerFactory .getLogger (HandleVisitor .class );
83
85
84
86
private boolean lookForStore ;
85
- private int agentSpanVar = -1 ;
87
+ private int contextVar = -1 ;
86
88
private boolean success ;
87
89
private final String methodName ;
88
90
@@ -98,12 +100,12 @@ DelayCertainInsMethodVisitor delayVisitorDelegate() {
98
100
@ Override
99
101
public void visitMethodInsn (
100
102
int opcode , String owner , String name , String descriptor , boolean isInterface ) {
101
- if (agentSpanVar == -1 ) {
103
+ if (contextVar == -1 ) {
102
104
lookForStore =
103
105
!lookForStore
104
106
&& opcode == Opcodes .INVOKEVIRTUAL
105
107
&& name .equals ("startSpan" )
106
- && descriptor .endsWith ("Ldatadog/trace/bootstrap/instrumentation/api/AgentSpan ;" );
108
+ && descriptor .endsWith ("Ldatadog.context.Context ;" );
107
109
} else if (!success
108
110
&& opcode == Opcodes .INVOKEVIRTUAL
109
111
&& owner .equals ("org/eclipse/jetty/server/Server" )
@@ -128,9 +130,17 @@ public void visitMethodInsn(
128
130
Label beforeHandle = new Label ();
129
131
Label afterHandle = new Label ();
130
132
131
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
133
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
134
+ super .visitMethodInsn (
135
+ Opcodes .INVOKESTATIC ,
136
+ "datadog/trace/bootstrap/instrumentation/api/Java8BytecodeBridge" ,
137
+ "spanFromContext" ,
138
+ "(" + Type .getDescriptor (Context .class ) + ")" + Type .getDescriptor (AgentSpan .class ),
139
+ false );
140
+ super .visitVarInsn (Opcodes .ASTORE , contextVar );
141
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
132
142
super .visitJumpInsn (Opcodes .IFNULL , beforeHandle );
133
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
143
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
134
144
super .visitMethodInsn (
135
145
Opcodes .INVOKEINTERFACE ,
136
146
"datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
@@ -156,14 +166,14 @@ public void visitMethodInsn(
156
166
"getResponse" ,
157
167
"()Lorg/eclipse/jetty/server/Response;" ,
158
168
false );
159
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
169
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
160
170
super .visitMethodInsn (
161
171
Opcodes .INVOKEINTERFACE ,
162
172
"datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
163
173
"getRequestBlockingAction" ,
164
174
"()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
165
175
true );
166
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
176
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
167
177
super .visitMethodInsn (
168
178
Opcodes .INVOKESTATIC ,
169
179
Type .getInternalName (JettyBlockingHelper .class ),
@@ -214,9 +224,9 @@ public void visitMethodInsn(
214
224
Label beforeRegularDispatch = new Label ();
215
225
Label afterRegularDispatch = new Label ();
216
226
217
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
227
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
218
228
super .visitJumpInsn (Opcodes .IFNULL , beforeRegularDispatch );
219
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
229
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
220
230
super .visitMethodInsn (
221
231
Opcodes .INVOKEINTERFACE ,
222
232
"datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
@@ -248,14 +258,14 @@ public void visitMethodInsn(
248
258
"getResponse" ,
249
259
"()Lorg/eclipse/jetty/server/Response;" ,
250
260
false );
251
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
261
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
252
262
super .visitMethodInsn (
253
263
Opcodes .INVOKEINTERFACE ,
254
264
"datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
255
265
"getRequestBlockingAction" ,
256
266
"()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
257
267
true );
258
- super .visitVarInsn (Opcodes .ALOAD , agentSpanVar );
268
+ super .visitVarInsn (Opcodes .ALOAD , contextVar );
259
269
260
270
// create the lambda
261
271
super .visitInvokeDynamicInsn (
@@ -337,7 +347,7 @@ private boolean checkDispatchMethodState(final List<Function> savedVisitations)
337
347
@ Override
338
348
public void visitVarInsn (int opcode , int varIndex ) {
339
349
if (lookForStore && opcode == Opcodes .ASTORE ) {
340
- agentSpanVar = varIndex ;
350
+ contextVar = varIndex ;
341
351
lookForStore = false ;
342
352
}
343
353
0 commit comments