1818
1919import static org .junit .Assert .assertEquals ;
2020import static org .junit .Assert .assertFalse ;
21+ import static org .junit .Assert .assertNotNull ;
2122import static org .junit .Assert .assertThrows ;
2223import static org .junit .Assert .assertTrue ;
2324
@@ -748,6 +749,17 @@ public void testTransactionRunnerWithRetryOnBeginTransaction() {
748749 beginTransactionSpan .toString (),
749750 beginTransactionSpan .getEvents ().stream ()
750751 .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 );
751763 }
752764
753765 @ Test
@@ -798,6 +810,7 @@ public void testSingleUseRetryOnExecuteStreamingSql() {
798810 executeStreamingQuery .toString (),
799811 executeStreamingQuery .getEvents ().stream ()
800812 .anyMatch (event -> event .getName ().contains ("Stream broken. Safe to retry" )));
813+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
801814 }
802815
803816 @ Test
@@ -845,6 +858,7 @@ public void testRetryOnExecuteSql() {
845858 executeSqlSpan .toString (),
846859 executeSqlSpan .getEvents ().stream ()
847860 .anyMatch (event -> event .getName ().equals ("Starting RPC retry 1" )));
861+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
848862 }
849863
850864 @ Test
@@ -866,12 +880,14 @@ public void testTableAttributes() {
866880 }
867881 return null ;
868882 });
883+ List <SpanData > finishedSpans = spanExporter .getFinishedSpanItems ();
869884 SpanData spanData =
870- spanExporter . getFinishedSpanItems () .stream ()
885+ finishedSpans .stream ()
871886 .filter (x -> x .getName ().equals ("CloudSpannerOperation.ExecuteStreamingRead" ))
872887 .findFirst ()
873888 .get ();
874889 verifyTableAttributes (spanData );
890+ verifyAtLeast1SpanHasXGoogSpannerRequestIdAttribute (finishedSpans );
875891 }
876892
877893 private void waitForFinishedSpans (int numExpectedSpans ) {
0 commit comments