2020import static org .mockito .Mockito .verify ;
2121import static org .mockito .Mockito .when ;
2222import static utils .InstrumentationTestHelper .compileAndLoadClass ;
23+ import static utils .InstrumentationTestHelper .getLineForLineProbe ;
2324
2425import com .datadog .debugger .el .DSL ;
2526import com .datadog .debugger .el .ProbeCondition ;
@@ -60,6 +61,8 @@ public class SpanDecorationProbeInstrumentationTest extends ProbeInstrumentation
6061 private static final ProbeId PROBE_ID2 = new ProbeId ("beae1807-f3b0-4ea8-a74f-826790c5e6f7" , 0 );
6162 private static final ProbeId PROBE_ID3 = new ProbeId ("beae1807-f3b0-4ea8-a74f-826790c5e6f8" , 0 );
6263 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 );
6366
6467 private TestTraceInterceptor traceInterceptor = new TestTraceInterceptor ();
6568
@@ -259,14 +262,16 @@ public void methodActiveSpanSynthException() throws IOException, URISyntaxExcept
259262 public void lineActiveSpanSimpleTag () throws IOException , URISyntaxException {
260263 final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20" ;
261264 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 );
263268 Class <?> testClass = compileAndLoadClass (CLASS_NAME );
264269 int result = Reflect .on (testClass ).call ("main" , "1" ).get ();
265270 assertEquals (84 , result );
266271 MutableSpan span = traceInterceptor .getFirstSpan ();
267272 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 ));
270275 }
271276
272277 @ Test
@@ -275,8 +280,14 @@ public void lineRootSpanTagList() throws IOException, URISyntaxException {
275280 SpanDecorationProbe .Decoration deco1 = createDecoration ("tag1" , "{arg}" );
276281 SpanDecorationProbe .Decoration deco2 = createDecoration ("tag2" , "{this.intField}" );
277282 SpanDecorationProbe .Decoration deco3 = createDecoration ("tag3" , "{strField}" );
283+ int line = getLineForLineProbe (CLASS_NAME , LINE_PROBE_ID1 );
278284 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 );
280291 Class <?> testClass = compileAndLoadClass (CLASS_NAME );
281292 int result = Reflect .on (testClass ).call ("main" , "1" ).get ();
282293 assertEquals (45 , result );
@@ -292,7 +303,9 @@ public void lineActiveSpanCondition() throws IOException, URISyntaxException {
292303 final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20" ;
293304 SpanDecorationProbe .Decoration decoration =
294305 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 );
296309 Class <?> testClass = compileAndLoadClass (CLASS_NAME );
297310 for (int i = 0 ; i < 10 ; i ++) {
298311 int result = Reflect .on (testClass ).call ("main" , String .valueOf (i )).get ();
@@ -308,7 +321,9 @@ public void lineActiveSpanInvalidCondition() throws IOException, URISyntaxExcept
308321 final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20" ;
309322 SpanDecorationProbe .Decoration decoration =
310323 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 );
312327 Class <?> testClass = compileAndLoadClass (CLASS_NAME );
313328 int result = Reflect .on (testClass ).call ("main" , "5" ).get ();
314329 assertEquals (84 , result );
@@ -338,24 +353,12 @@ public void mixedWithLogProbes() throws IOException, URISyntaxException {
338353 SpanDecorationProbe .Decoration decoration2 = createDecoration ("tag2" , "{arg}" );
339354 SpanDecorationProbe spanDecoProbe1 =
340355 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 )
348357 .evaluateAt (MethodLocation .EXIT )
349358 .build ();
350359 SpanDecorationProbe spanDecoProbe2 =
351360 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 )
359362 .evaluateAt (MethodLocation .ENTRY )
360363 .build ();
361364 LogProbe logProbe1 =
@@ -403,24 +406,12 @@ public void mixedEntryExit() throws IOException, URISyntaxException {
403406 SpanDecorationProbe .Decoration decoration2 = createDecoration ("tag2" , "{arg}" );
404407 SpanDecorationProbe spanDecoProbe1 =
405408 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 )
413410 .evaluateAt (MethodLocation .EXIT )
414411 .build ();
415412 SpanDecorationProbe spanDecoProbe2 =
416413 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 )
424415 .evaluateAt (MethodLocation .ENTRY )
425416 .build ();
426417 Configuration configuration =
@@ -624,12 +615,14 @@ private void installSingleSpanDecoration(
624615 }
625616
626617 private void installSingleSpanDecoration (
618+ ProbeId probeId ,
627619 String typeName ,
628620 SpanDecorationProbe .TargetSpan targetSpan ,
629621 SpanDecorationProbe .Decoration decoration ,
630622 String sourceFile ,
631623 int line ) {
632- installSingleSpanDecoration (typeName , targetSpan , asList (decoration ), sourceFile , line );
624+ installSingleSpanDecoration (
625+ probeId , typeName , targetSpan , asList (decoration ), sourceFile , line );
633626 }
634627
635628 private void installSingleSpanDecoration (
@@ -645,12 +638,13 @@ private void installSingleSpanDecoration(
645638 }
646639
647640 private void installSingleSpanDecoration (
641+ ProbeId probeId ,
648642 String typeName ,
649643 SpanDecorationProbe .TargetSpan targetSpan ,
650644 List <SpanDecorationProbe .Decoration > decorations ,
651645 String sourceFile ,
652646 int line ) {
653- SpanDecorationProbe probe = createProbe (PROBE_ID , targetSpan , decorations , sourceFile , line );
647+ SpanDecorationProbe probe = createProbe (probeId , targetSpan , decorations , sourceFile , line );
654648 installSpanDecorationProbes (
655649 typeName , Configuration .builder ().setService (SERVICE_NAME ).add (probe ).build ());
656650 }
@@ -661,10 +655,8 @@ private static SpanDecorationProbe createProbe(
661655 List <SpanDecorationProbe .Decoration > decorationList ,
662656 String typeName ,
663657 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 )
668660 .evaluateAt (MethodLocation .EXIT )
669661 .build ();
670662 }
@@ -684,12 +676,11 @@ private static SpanDecorationProbe.Builder createProbeBuilder(
684676 List <SpanDecorationProbe .Decoration > decorationList ,
685677 String typeName ,
686678 String methodName ,
687- String signature ,
688- String ... lines ) {
679+ String signature ) {
689680 return SpanDecorationProbe .builder ()
690681 .language (LANGUAGE )
691682 .probeId (id )
692- .where (typeName , methodName , signature , lines )
683+ .where (typeName , methodName , signature )
693684 .evaluateAt (MethodLocation .EXIT )
694685 .targetSpan (targetSpan )
695686 .decorate (decorationList );
0 commit comments