20
20
import static org .mockito .Mockito .verify ;
21
21
import static org .mockito .Mockito .when ;
22
22
import static utils .InstrumentationTestHelper .compileAndLoadClass ;
23
+ import static utils .InstrumentationTestHelper .getLineForLineProbe ;
23
24
24
25
import com .datadog .debugger .el .DSL ;
25
26
import com .datadog .debugger .el .ProbeCondition ;
@@ -60,6 +61,8 @@ public class SpanDecorationProbeInstrumentationTest extends ProbeInstrumentation
60
61
private static final ProbeId PROBE_ID2 = new ProbeId ("beae1807-f3b0-4ea8-a74f-826790c5e6f7" , 0 );
61
62
private static final ProbeId PROBE_ID3 = new ProbeId ("beae1807-f3b0-4ea8-a74f-826790c5e6f8" , 0 );
62
63
private static final ProbeId PROBE_ID4 = new ProbeId ("beae1807-f3b0-4ea8-a74f-826790c5e6f9" , 0 );
64
+ private static final ProbeId LINE_PROBE_ID1 =
65
+ new ProbeId ("beae1817-f3b0-4ea8-a74f-000000000001" , 0 );
63
66
64
67
private TestTraceInterceptor traceInterceptor = new TestTraceInterceptor ();
65
68
@@ -259,14 +262,16 @@ public void methodActiveSpanSynthException() throws IOException, URISyntaxExcept
259
262
public void lineActiveSpanSimpleTag () throws IOException , URISyntaxException {
260
263
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20" ;
261
264
SpanDecorationProbe .Decoration decoration = createDecoration ("tag1" , "{arg}" );
262
- installSingleSpanDecoration (CLASS_NAME , ACTIVE , decoration , "CapturedSnapshot20.java" , 47 );
265
+ int line = getLineForLineProbe (CLASS_NAME , LINE_PROBE_ID1 );
266
+ installSingleSpanDecoration (
267
+ LINE_PROBE_ID1 , CLASS_NAME , ACTIVE , decoration , "CapturedSnapshot20.java" , line );
263
268
Class <?> testClass = compileAndLoadClass (CLASS_NAME );
264
269
int result = Reflect .on (testClass ).call ("main" , "1" ).get ();
265
270
assertEquals (84 , result );
266
271
MutableSpan span = traceInterceptor .getFirstSpan ();
267
272
assertEquals ("1" , span .getTags ().get ("tag1" ));
268
- assertEquals (PROBE_ID .getId (), span .getTags ().get ("_dd.di.tag1.probe_id" ));
269
- verify (probeStatusSink ).addEmitting (ArgumentMatchers .eq (PROBE_ID ));
273
+ assertEquals (LINE_PROBE_ID1 .getId (), span .getTags ().get ("_dd.di.tag1.probe_id" ));
274
+ verify (probeStatusSink ).addEmitting (ArgumentMatchers .eq (LINE_PROBE_ID1 ));
270
275
}
271
276
272
277
@ Test
@@ -275,8 +280,14 @@ public void lineRootSpanTagList() throws IOException, URISyntaxException {
275
280
SpanDecorationProbe .Decoration deco1 = createDecoration ("tag1" , "{arg}" );
276
281
SpanDecorationProbe .Decoration deco2 = createDecoration ("tag2" , "{this.intField}" );
277
282
SpanDecorationProbe .Decoration deco3 = createDecoration ("tag3" , "{strField}" );
283
+ int line = getLineForLineProbe (CLASS_NAME , LINE_PROBE_ID1 );
278
284
installSingleSpanDecoration (
279
- CLASS_NAME , ROOT , asList (deco1 , deco2 , deco3 ), "CapturedSnapshot21.java" , 67 );
285
+ LINE_PROBE_ID1 ,
286
+ CLASS_NAME ,
287
+ ROOT ,
288
+ asList (deco1 , deco2 , deco3 ),
289
+ "CapturedSnapshot21.java" ,
290
+ line );
280
291
Class <?> testClass = compileAndLoadClass (CLASS_NAME );
281
292
int result = Reflect .on (testClass ).call ("main" , "1" ).get ();
282
293
assertEquals (45 , result );
@@ -292,7 +303,9 @@ public void lineActiveSpanCondition() throws IOException, URISyntaxException {
292
303
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20" ;
293
304
SpanDecorationProbe .Decoration decoration =
294
305
createDecoration (eq (ref ("arg" ), value ("5" )), "arg == '5'" , "tag1" , "{arg}" );
295
- installSingleSpanDecoration (CLASS_NAME , ACTIVE , decoration , "CapturedSnapshot20.java" , 47 );
306
+ int line = getLineForLineProbe (CLASS_NAME , LINE_PROBE_ID1 );
307
+ installSingleSpanDecoration (
308
+ LINE_PROBE_ID1 , CLASS_NAME , ACTIVE , decoration , "CapturedSnapshot20.java" , line );
296
309
Class <?> testClass = compileAndLoadClass (CLASS_NAME );
297
310
for (int i = 0 ; i < 10 ; i ++) {
298
311
int result = Reflect .on (testClass ).call ("main" , String .valueOf (i )).get ();
@@ -308,7 +321,9 @@ public void lineActiveSpanInvalidCondition() throws IOException, URISyntaxExcept
308
321
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20" ;
309
322
SpanDecorationProbe .Decoration decoration =
310
323
createDecoration (eq (ref ("noarg" ), value ("5" )), "arg == '5'" , "tag1" , "{arg}" );
311
- installSingleSpanDecoration (CLASS_NAME , ACTIVE , decoration , "CapturedSnapshot20.java" , 47 );
324
+ int line = getLineForLineProbe (CLASS_NAME , LINE_PROBE_ID1 );
325
+ installSingleSpanDecoration (
326
+ LINE_PROBE_ID1 , CLASS_NAME , ACTIVE , decoration , "CapturedSnapshot20.java" , line );
312
327
Class <?> testClass = compileAndLoadClass (CLASS_NAME );
313
328
int result = Reflect .on (testClass ).call ("main" , "5" ).get ();
314
329
assertEquals (84 , result );
@@ -338,24 +353,12 @@ public void mixedWithLogProbes() throws IOException, URISyntaxException {
338
353
SpanDecorationProbe .Decoration decoration2 = createDecoration ("tag2" , "{arg}" );
339
354
SpanDecorationProbe spanDecoProbe1 =
340
355
createProbeBuilder (
341
- PROBE_ID1 ,
342
- ACTIVE ,
343
- singletonList (decoration1 ),
344
- CLASS_NAME ,
345
- "process" ,
346
- null ,
347
- (String []) null )
356
+ PROBE_ID1 , ACTIVE , singletonList (decoration1 ), CLASS_NAME , "process" , null )
348
357
.evaluateAt (MethodLocation .EXIT )
349
358
.build ();
350
359
SpanDecorationProbe spanDecoProbe2 =
351
360
createProbeBuilder (
352
- PROBE_ID2 ,
353
- ACTIVE ,
354
- singletonList (decoration2 ),
355
- CLASS_NAME ,
356
- "process" ,
357
- null ,
358
- (String []) null )
361
+ PROBE_ID2 , ACTIVE , singletonList (decoration2 ), CLASS_NAME , "process" , null )
359
362
.evaluateAt (MethodLocation .ENTRY )
360
363
.build ();
361
364
LogProbe logProbe1 =
@@ -403,24 +406,12 @@ public void mixedEntryExit() throws IOException, URISyntaxException {
403
406
SpanDecorationProbe .Decoration decoration2 = createDecoration ("tag2" , "{arg}" );
404
407
SpanDecorationProbe spanDecoProbe1 =
405
408
createProbeBuilder (
406
- PROBE_ID1 ,
407
- ACTIVE ,
408
- singletonList (decoration1 ),
409
- CLASS_NAME ,
410
- "process" ,
411
- null ,
412
- (String []) null )
409
+ PROBE_ID1 , ACTIVE , singletonList (decoration1 ), CLASS_NAME , "process" , null )
413
410
.evaluateAt (MethodLocation .EXIT )
414
411
.build ();
415
412
SpanDecorationProbe spanDecoProbe2 =
416
413
createProbeBuilder (
417
- PROBE_ID2 ,
418
- ACTIVE ,
419
- singletonList (decoration2 ),
420
- CLASS_NAME ,
421
- "process" ,
422
- null ,
423
- (String []) null )
414
+ PROBE_ID2 , ACTIVE , singletonList (decoration2 ), CLASS_NAME , "process" , null )
424
415
.evaluateAt (MethodLocation .ENTRY )
425
416
.build ();
426
417
Configuration configuration =
@@ -624,12 +615,14 @@ private void installSingleSpanDecoration(
624
615
}
625
616
626
617
private void installSingleSpanDecoration (
618
+ ProbeId probeId ,
627
619
String typeName ,
628
620
SpanDecorationProbe .TargetSpan targetSpan ,
629
621
SpanDecorationProbe .Decoration decoration ,
630
622
String sourceFile ,
631
623
int line ) {
632
- installSingleSpanDecoration (typeName , targetSpan , asList (decoration ), sourceFile , line );
624
+ installSingleSpanDecoration (
625
+ probeId , typeName , targetSpan , asList (decoration ), sourceFile , line );
633
626
}
634
627
635
628
private void installSingleSpanDecoration (
@@ -645,12 +638,13 @@ private void installSingleSpanDecoration(
645
638
}
646
639
647
640
private void installSingleSpanDecoration (
641
+ ProbeId probeId ,
648
642
String typeName ,
649
643
SpanDecorationProbe .TargetSpan targetSpan ,
650
644
List <SpanDecorationProbe .Decoration > decorations ,
651
645
String sourceFile ,
652
646
int line ) {
653
- SpanDecorationProbe probe = createProbe (PROBE_ID , targetSpan , decorations , sourceFile , line );
647
+ SpanDecorationProbe probe = createProbe (probeId , targetSpan , decorations , sourceFile , line );
654
648
installSpanDecorationProbes (
655
649
typeName , Configuration .builder ().setService (SERVICE_NAME ).add (probe ).build ());
656
650
}
@@ -661,10 +655,8 @@ private static SpanDecorationProbe createProbe(
661
655
List <SpanDecorationProbe .Decoration > decorationList ,
662
656
String typeName ,
663
657
String methodName ,
664
- String signature ,
665
- String ... lines ) {
666
- return createProbeBuilder (
667
- id , targetSpan , decorationList , typeName , methodName , signature , lines )
658
+ String signature ) {
659
+ return createProbeBuilder (id , targetSpan , decorationList , typeName , methodName , signature )
668
660
.evaluateAt (MethodLocation .EXIT )
669
661
.build ();
670
662
}
@@ -684,12 +676,11 @@ private static SpanDecorationProbe.Builder createProbeBuilder(
684
676
List <SpanDecorationProbe .Decoration > decorationList ,
685
677
String typeName ,
686
678
String methodName ,
687
- String signature ,
688
- String ... lines ) {
679
+ String signature ) {
689
680
return SpanDecorationProbe .builder ()
690
681
.language (LANGUAGE )
691
682
.probeId (id )
692
- .where (typeName , methodName , signature , lines )
683
+ .where (typeName , methodName , signature )
693
684
.evaluateAt (MethodLocation .EXIT )
694
685
.targetSpan (targetSpan )
695
686
.decorate (decorationList );
0 commit comments