5252import org .junit .runner .RunWith ;
5353import org .junit .runners .JUnit4 ;
5454
55- /**
56- * Integration tests for End to End Tracing.
57- */
55+ /** Integration tests for End to End Tracing. */
5856@ Category (ParallelIntegrationTest .class )
5957@ RunWith (JUnit4 .class )
6058public class ITEndToEndTracingTest {
6159
62- @ ClassRule
63- public static IntegrationTestEnv env = new IntegrationTestEnv ();
60+ @ ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv ();
6461 private static DatabaseClient googleStandardSQLClient ;
6562
6663 static {
@@ -92,24 +89,30 @@ public void initSelectValueQuery() {
9289 selectValueQuery = "SELECT @p1 + @p1 " ;
9390 }
9491
95- private void assertTrace (String spanName , String traceid )
92+ private void assertTrace (String traceId )
9693 throws IOException , InterruptedException {
97- TraceServiceSettings settings = env .getTestHelper ().getOptions ().getCredentials () == null
98- ? TraceServiceSettings .newBuilder ().build () : TraceServiceSettings .newBuilder ()
99- .setCredentialsProvider (
100- FixedCredentialsProvider .create (env .getTestHelper ().getOptions ().getCredentials ()))
101- .build ();
94+ TraceServiceSettings settings =
95+ env .getTestHelper ().getOptions ().getCredentials () == null
96+ ? TraceServiceSettings .newBuilder ().build ()
97+ : TraceServiceSettings .newBuilder ()
98+ .setCredentialsProvider (
99+ FixedCredentialsProvider .create (
100+ env .getTestHelper ().getOptions ().getCredentials ()))
101+ .build ();
102102 try (TraceServiceClient client = TraceServiceClient .create (settings )) {
103103 // It can take a few seconds before the trace is visible.
104104 Thread .sleep (5000L );
105105 boolean foundTrace = false ;
106106 for (int attempts = 0 ; attempts < 2 ; attempts ++) {
107107 try {
108- Trace clientTrace = client . getTrace ( env . getTestHelper (). getInstanceId (). getProject (),
109- traceid );
108+ Trace clientTrace =
109+ client . getTrace ( env . getTestHelper (). getInstanceId (). getProject (), traceId );
110110 // Assert Spanner Frontend Trace is present
111- assertTrue (clientTrace .getSpansList ().stream ().anyMatch (
112- span -> "CloudSpannerOperation.ExecuteStreamingQuery" .equals (span .getName ())));
111+ assertTrue (
112+ clientTrace .getSpansList ().stream ()
113+ .anyMatch (
114+ span ->
115+ "CloudSpannerOperation.ExecuteStreamingQuery" .equals (span .getName ())));
113116 foundTrace = true ;
114117 break ;
115118 } catch (ApiException apiException ) {
@@ -119,7 +122,8 @@ private void assertTrace(String spanName, String traceid)
119122 }
120123 assertTrue (foundTrace );
121124 } catch (ResourceExhaustedException resourceExhaustedException ) {
122- if (resourceExhaustedException .getMessage ()
125+ if (resourceExhaustedException
126+ .getMessage ()
123127 .contains ("Quota exceeded for quota metric 'Read requests (free)'" )) {
124128 // Ignore and allow the test to succeed.
125129 System .out .println ("RESOURCE_EXHAUSTED error ignored" );
@@ -141,16 +145,16 @@ private Struct executeWithRowResultType(Statement statement, Type expectedRowTyp
141145 @ Test
142146 public void simpleSelect () throws IOException , InterruptedException {
143147 Tracer tracer = GlobalOpenTelemetry .getTracer (ITEndToEndTracingTest .class .getName ());
144- String spanName = "simpleSelect" ;
145- Span span = tracer .spanBuilder (spanName ).startSpan ();
148+ Span span = tracer .spanBuilder ("simpleSelect" ).startSpan ();
146149 Scope scope = span .makeCurrent ();
147150 Type rowType = Type .struct (StructField .of ("" , Type .int64 ()));
148- Struct row = executeWithRowResultType (
149- Statement .newBuilder (selectValueQuery ).bind ("p1" ).to (1234 ).build (), rowType );
151+ Struct row =
152+ executeWithRowResultType (
153+ Statement .newBuilder (selectValueQuery ).bind ("p1" ).to (1234 ).build (), rowType );
150154 assertThat (row .isNull (0 )).isFalse ();
151155 assertThat (row .getLong (0 )).isEqualTo (2468 );
152156 scope .close ();
153157 span .end ();
154- assertTrace (spanName , span .getSpanContext ().getTraceId ());
158+ assertTrace (span .getSpanContext ().getTraceId ());
155159 }
156- }
160+ }
0 commit comments