18
18
19
19
import static org .junit .Assert .assertEquals ;
20
20
import static org .junit .Assert .assertFalse ;
21
+ import static org .junit .Assert .assertNotNull ;
21
22
import static org .junit .Assert .assertThrows ;
22
23
import static org .junit .Assert .assertTrue ;
23
24
@@ -748,6 +749,17 @@ public void testTransactionRunnerWithRetryOnBeginTransaction() {
748
749
beginTransactionSpan .toString (),
749
750
beginTransactionSpan .getEvents ().stream ()
750
751
.anyMatch (event -> event .getName ().equals ("Starting RPC retry 1" )));
752
+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
753
+ }
754
+
755
+ private void verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (List <SpanData > finishedSpans ) {
756
+ AttributeKey <String > attributeKey = AttributeKey .stringKey ("x_goog_spanner_request_id" );
757
+ SpanData matchedSpan =
758
+ finishedSpans .stream ()
759
+ .filter (span -> !span .getAttributes ().get (attributeKey ).isEmpty ())
760
+ .findAny ()
761
+ .orElseThrow (IllegalStateException ::new );
762
+ assertNotNull (matchedSpan );
751
763
}
752
764
753
765
@ Test
@@ -798,6 +810,7 @@ public void testSingleUseRetryOnExecuteStreamingSql() {
798
810
executeStreamingQuery .toString (),
799
811
executeStreamingQuery .getEvents ().stream ()
800
812
.anyMatch (event -> event .getName ().contains ("Stream broken. Safe to retry" )));
813
+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
801
814
}
802
815
803
816
@ Test
@@ -845,6 +858,7 @@ public void testRetryOnExecuteSql() {
845
858
executeSqlSpan .toString (),
846
859
executeSqlSpan .getEvents ().stream ()
847
860
.anyMatch (event -> event .getName ().equals ("Starting RPC retry 1" )));
861
+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
848
862
}
849
863
850
864
@ Test
@@ -866,12 +880,14 @@ public void testTableAttributes() {
866
880
}
867
881
return null ;
868
882
});
883
+ List <SpanData > finishedSpans = spanExporter .getFinishedSpanItems ();
869
884
SpanData spanData =
870
- spanExporter . getFinishedSpanItems () .stream ()
885
+ finishedSpans .stream ()
871
886
.filter (x -> x .getName ().equals ("CloudSpannerOperation.ExecuteStreamingRead" ))
872
887
.findFirst ()
873
888
.get ();
874
889
verifyTableAttributes (spanData );
890
+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
875
891
}
876
892
877
893
private void waitForFinishedSpans (int numExpectedSpans ) {
0 commit comments