Skip to content

Commit 11baac3

Browse files
committed
Integration test for End to End tracing
1 parent 680ce7f commit 11baac3

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected void before() throws Throwable {
122122

123123
this.config.setUp();
124124
// OpenTelemetry set up for enabling End to End tracing for all integration test env.
125-
// The grpc stub and connections are created during test env set up using SpannerOptions and are
125+
// The gRPC stub and connections are created during test env set up using SpannerOptions and are
126126
// reused for executing statements.
127127
SpannerOptions options = spannerOptionsWithEndToEndTracing();
128128
String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, "");

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITEndToEndTracingTest.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.cloud.spanner.it;
218

319
import static com.google.common.truth.Truth.assertThat;
@@ -46,14 +62,15 @@ public class ITEndToEndTracingTest {
4662
@ClassRule
4763
public static IntegrationTestEnv env = new IntegrationTestEnv();
4864
private static DatabaseClient googleStandardSQLClient;
49-
private String selectValueQuery;
5065

5166
static {
5267
SpannerOptionsHelper.resetActiveTracingFramework();
5368
SpannerOptions.enableOpenTelemetryMetrics();
5469
SpannerOptions.enableOpenTelemetryTraces();
5570
}
5671

72+
private String selectValueQuery;
73+
5774
@BeforeClass
5875
public static void setUp() {
5976
setUpDatabase();
@@ -65,26 +82,23 @@ public static void setUpDatabase() {
6582
googleStandardSQLClient = env.getTestHelper().getDatabaseClient(googleStandardSQLDatabase);
6683
}
6784

68-
@Before
69-
public void initSelectValueQuery() {
70-
selectValueQuery = "SELECT @p1 + @p1 ";
71-
}
72-
7385
@AfterClass
7486
public static void teardown() {
7587
ConnectionOptions.closeSpanner();
7688
}
7789

90+
@Before
91+
public void initSelectValueQuery() {
92+
selectValueQuery = "SELECT @p1 + @p1 ";
93+
}
94+
7895
private void assertTrace(String spanName, String traceid)
7996
throws IOException, InterruptedException {
80-
TraceServiceSettings settings =
81-
env.getTestHelper().getOptions().getCredentials() == null
82-
? TraceServiceSettings.newBuilder().build()
83-
: TraceServiceSettings.newBuilder()
84-
.setCredentialsProvider(
85-
FixedCredentialsProvider.create(
86-
env.getTestHelper().getOptions().getCredentials()))
87-
.build();
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();
88102
try (TraceServiceClient client = TraceServiceClient.create(settings)) {
89103
// It can take a few seconds before the trace is visible.
90104
Thread.sleep(5000L);
@@ -105,8 +119,7 @@ private void assertTrace(String spanName, String traceid)
105119
}
106120
assertTrue(foundTrace);
107121
} catch (ResourceExhaustedException resourceExhaustedException) {
108-
if (resourceExhaustedException
109-
.getMessage()
122+
if (resourceExhaustedException.getMessage()
110123
.contains("Quota exceeded for quota metric 'Read requests (free)'")) {
111124
// Ignore and allow the test to succeed.
112125
System.out.println("RESOURCE_EXHAUSTED error ignored");
@@ -117,8 +130,7 @@ private void assertTrace(String spanName, String traceid)
117130
}
118131

119132
private Struct executeWithRowResultType(Statement statement, Type expectedRowType) {
120-
ResultSet resultSet =
121-
statement.executeQuery(googleStandardSQLClient.singleUse());
133+
ResultSet resultSet = statement.executeQuery(googleStandardSQLClient.singleUse());
122134
assertThat(resultSet.next()).isTrue();
123135
assertThat(resultSet.getType()).isEqualTo(expectedRowType);
124136
Struct row = resultSet.getCurrentRowAsStruct();
@@ -141,4 +153,4 @@ public void simpleSelect() throws IOException, InterruptedException {
141153
span.end();
142154
assertTrace(spanName, span.getSpanContext().getTraceId());
143155
}
144-
}
156+
}

0 commit comments

Comments
 (0)