This repository was archived by the owner on Apr 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
feat: Integration test for End to End tracing #3691
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6d54c9d
Enable End to End tracing in Integration Test
manu2 a0806ee
Integration test for End to End tracing
manu2 00a1735
Integration test for End to End tracing
manu2 a45ca7e
Merge branch 'googleapis:main' into main
manu2 680ce7f
Integration test for End to End tracing
manu2 11baac3
Integration test for End to End tracing
manu2 8f12e88
Fix errors in Integration test for End to End tracing
manu2 8bc559d
Fix errors in Integration test for End to End tracing
manu2 9f81dbb
Add TestEnvOptions to enable End to End tracing for the new Integrati…
manu2 19eee1c
Fix ITEndToEndTracingTest error on direct path build
manu2 646a6b9
Skip ITEndToEndTracingTest on permission denied error for error in di…
manu2 d752823
Assert server side span name
manu2 74b901d
Increase delay before trace fetch.
manu2 9c1cd08
Remove update to GlobalTelemetry. Use opentelemetrysdk created in test.
manu2 8ec9109
Merge branch 'googleapis:main' into main
manu2 eb25e67
Update retry logic for trace retrieval.
manu2 0611d07
Merge branch 'main' into main
surbhigarg92 66856a8
Remove version number from opentelemetry exporter-trace dependency
manu2 9f18bf7
Merge branch 'googleapis:main' into main
manu2 e7f3109
Revert "Remove version number from opentelemetry exporter-trace depen…
manu2 7e42c8c
Merge branch 'googleapis:main' into main
manu2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,6 +455,24 @@ | |
| <artifactId>opentelemetry-sdk-testing</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.cloud.opentelemetry</groupId> | ||
| <artifactId>exporter-trace</artifactId> | ||
| <version>0.33.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>google-cloud-trace</artifactId> | ||
| <version>2.51.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.api.grpc</groupId> | ||
| <artifactId>proto-google-cloud-trace-v1</artifactId> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we adding this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We query trace using trace client which requires this dependency. |
||
| <version>2.51.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <profiles> | ||
| <profile> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITEndToEndTracingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.spanner.it; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| import com.google.api.gax.core.FixedCredentialsProvider; | ||
| import com.google.api.gax.rpc.ApiException; | ||
| import com.google.api.gax.rpc.ResourceExhaustedException; | ||
| import com.google.api.gax.rpc.StatusCode; | ||
| import com.google.cloud.spanner.Database; | ||
| import com.google.cloud.spanner.DatabaseClient; | ||
| import com.google.cloud.spanner.IntegrationTestEnv; | ||
| import com.google.cloud.spanner.IntegrationTestEnv.TestEnvOptions; | ||
| import com.google.cloud.spanner.ParallelIntegrationTest; | ||
| import com.google.cloud.spanner.ResultSet; | ||
| import com.google.cloud.spanner.SpannerOptions; | ||
| import com.google.cloud.spanner.SpannerOptionsHelper; | ||
| import com.google.cloud.spanner.Statement; | ||
| import com.google.cloud.spanner.Struct; | ||
| import com.google.cloud.spanner.Type; | ||
| import com.google.cloud.spanner.Type.StructField; | ||
| import com.google.cloud.spanner.connection.ConnectionOptions; | ||
| import com.google.cloud.trace.v1.TraceServiceClient; | ||
| import com.google.cloud.trace.v1.TraceServiceSettings; | ||
| import com.google.common.base.Stopwatch; | ||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.api.trace.Tracer; | ||
| import io.opentelemetry.context.Scope; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| /** Integration tests for End to End Tracing. */ | ||
| @Category(ParallelIntegrationTest.class) | ||
| @RunWith(JUnit4.class) | ||
| public class ITEndToEndTracingTest { | ||
| public static Collection<TestEnvOptions> testEnvOptions = | ||
| Arrays.asList(TestEnvOptions.USE_END_TO_END_TRACING); | ||
| @ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv(testEnvOptions); | ||
| private static DatabaseClient googleStandardSQLClient; | ||
|
|
||
| static { | ||
| SpannerOptionsHelper.resetActiveTracingFramework(); | ||
| SpannerOptions.enableOpenTelemetryTraces(); | ||
| } | ||
|
|
||
| private static String selectValueQuery = "SELECT @p1 + @p1"; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() { | ||
| setUpDatabase(); | ||
| } | ||
|
|
||
| public static void setUpDatabase() { | ||
| // Empty database. | ||
| Database googleStandardSQLDatabase = env.getTestHelper().createTestDatabase(); | ||
| googleStandardSQLClient = env.getTestHelper().getDatabaseClient(googleStandardSQLDatabase); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void teardown() { | ||
| ConnectionOptions.closeSpanner(); | ||
| } | ||
|
|
||
| private void assertTrace(String traceId) throws IOException, InterruptedException { | ||
| TraceServiceSettings settings = | ||
| env.getTestHelper().getOptions().getCredentials() == null | ||
| ? TraceServiceSettings.newBuilder().build() | ||
| : TraceServiceSettings.newBuilder() | ||
| .setCredentialsProvider( | ||
| FixedCredentialsProvider.create( | ||
| env.getTestHelper().getOptions().getCredentials())) | ||
| .build(); | ||
| try (TraceServiceClient client = TraceServiceClient.create(settings)) { | ||
| boolean foundTrace = false; | ||
| Stopwatch metricsPollingStopwatch = Stopwatch.createStarted(); | ||
| while (!foundTrace && metricsPollingStopwatch.elapsed(TimeUnit.SECONDS) < 30) { | ||
| // Try every 5 seconds | ||
| Thread.sleep(5000); | ||
| try { | ||
| foundTrace = | ||
| client.getTrace(env.getTestHelper().getInstanceId().getProject(), traceId) | ||
| .getSpansList().stream() | ||
| .anyMatch(span -> "Spanner.ExecuteStreamingSql".equals(span.getName())); | ||
| } catch (ApiException apiException) { | ||
| assumeTrue( | ||
| apiException.getStatusCode() != null | ||
| && StatusCode.Code.NOT_FOUND.equals(apiException.getStatusCode().getCode())); | ||
| System.out.println("Trace NOT_FOUND error ignored"); | ||
| } | ||
| } | ||
| assertTrue(foundTrace); | ||
| } catch (ResourceExhaustedException resourceExhaustedException) { | ||
| if (resourceExhaustedException | ||
| .getMessage() | ||
| .contains("Quota exceeded for quota metric 'Read requests (free)'")) { | ||
| // Ignore and allow the test to succeed. | ||
| System.out.println("RESOURCE_EXHAUSTED error ignored"); | ||
| } else { | ||
| throw resourceExhaustedException; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private Struct executeWithRowResultType(Statement statement, Type expectedRowType) { | ||
| ResultSet resultSet = statement.executeQuery(googleStandardSQLClient.singleUse()); | ||
| assertThat(resultSet.next()).isTrue(); | ||
| assertThat(resultSet.getType()).isEqualTo(expectedRowType); | ||
| Struct row = resultSet.getCurrentRowAsStruct(); | ||
| assertThat(resultSet.next()).isFalse(); | ||
| return row; | ||
| } | ||
|
|
||
| @Test | ||
| public void simpleSelect() throws IOException, InterruptedException { | ||
| Tracer tracer = | ||
| env.getTestHelper() | ||
| .getOptions() | ||
| .getOpenTelemetry() | ||
| .getTracer(ITEndToEndTracingTest.class.getName()); | ||
| Span span = tracer.spanBuilder("simpleSelect").startSpan(); | ||
| Scope scope = span.makeCurrent(); | ||
| Type rowType = Type.struct(StructField.of("", Type.int64())); | ||
| Struct row = | ||
| executeWithRowResultType( | ||
| Statement.newBuilder(selectValueQuery).bind("p1").to(1234).build(), rowType); | ||
| assertThat(row.isNull(0)).isFalse(); | ||
| assertThat(row.getLong(0)).isEqualTo(2468); | ||
| scope.close(); | ||
| span.end(); | ||
| assertTrace(span.getSpanContext().getTraceId()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the version from here. It should either fetch from bom or the latest version