io.opentelemetry
opentelemetry-sdk-common
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java
index 596ce96d8..6167cedca 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java
@@ -19,13 +19,16 @@
import com.google.api.core.InternalApi;
import com.google.api.gax.retrying.RetrySettings;
import com.google.cloud.datastore.Datastore;
+import com.google.cloud.datastore.DatastoreOpenTelemetryOptions;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.Key;
import com.google.cloud.datastore.Query;
import com.google.cloud.datastore.QueryResults;
import com.google.cloud.datastore.StructuredQuery;
import com.google.cloud.http.HttpTransportOptions;
+import io.opentelemetry.sdk.OpenTelemetrySdk;
import java.util.UUID;
+import javax.annotation.Nullable;
import org.threeten.bp.Duration;
/**
@@ -38,13 +41,13 @@
* RetrySettings#getTotalTimeout()} is {@code 120000} and {@link
* RetrySettings#getInitialRetryDelay()} is {@code 250}. {@link
* HttpTransportOptions#getConnectTimeout()} and {@link HttpTransportOptions#getReadTimeout()} are
- * both both set to {@code 60000}.
+ * both both set to {@code 60000}. If an OpenTelemetrySdk object is passed in, OpenTelemetry Trace
+ * collection will be enabled for the Client application.
*
* Internal testing use only
*/
@InternalApi
public class RemoteDatastoreHelper {
-
private final DatastoreOptions options;
private final Datastore datastore;
private final String namespace;
@@ -78,18 +81,30 @@ public static RemoteDatastoreHelper create() {
}
/** Creates a {@code RemoteStorageHelper} object. */
- public static RemoteDatastoreHelper create(String databaseId) {
+ public static RemoteDatastoreHelper create(
+ String databaseId, @Nullable OpenTelemetrySdk openTelemetrySdk) {
HttpTransportOptions transportOptions = DatastoreOptions.getDefaultHttpTransportOptions();
transportOptions =
transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build();
- DatastoreOptions datastoreOption =
+ DatastoreOptions.Builder datastoreOptionBuilder =
DatastoreOptions.newBuilder()
.setDatabaseId(databaseId)
.setNamespace(UUID.randomUUID().toString())
.setRetrySettings(retrySettings())
- .setTransportOptions(transportOptions)
- .build();
- return new RemoteDatastoreHelper(datastoreOption);
+ .setTransportOptions(transportOptions);
+
+ if (openTelemetrySdk != null) {
+ datastoreOptionBuilder.setOpenTelemetryOptions(
+ DatastoreOpenTelemetryOptions.newBuilder()
+ .setOpenTelemetry(openTelemetrySdk)
+ .setTracingEnabled(true)
+ .build());
+ }
+ return new RemoteDatastoreHelper(datastoreOptionBuilder.build());
+ }
+
+ public static RemoteDatastoreHelper create(String databaseId) {
+ return create(databaseId, /*openTelemetrySdk=*/ null);
}
private static RetrySettings retrySettings() {
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
index a25600335..46a3522c0 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
@@ -26,10 +26,10 @@
import com.google.api.gax.rpc.NotFoundException;
import com.google.cloud.datastore.Datastore;
-import com.google.cloud.datastore.DatastoreOpenTelemetryOptions;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.Entity;
import com.google.cloud.datastore.Key;
+import com.google.cloud.datastore.testing.RemoteDatastoreHelper;
import com.google.cloud.opentelemetry.trace.TraceConfiguration;
import com.google.cloud.opentelemetry.trace.TraceExporter;
import com.google.cloud.trace.v1.TraceServiceClient;
@@ -189,8 +189,6 @@ private boolean dfsContainsCallStack(long spanId, List expectedCallStack
private static final Logger logger = Logger.getLogger(ITE2ETracingTest.class.getName());
- private static final String SERVICE = "google.datastore.v1.Datastore/";
-
private static final String RUN_AGGREGATION_QUERY_RPC_NAME = "RunAggregationQuery";
private static final String RUN_QUERY_RPC_NAME = "RunQuery";
@@ -237,7 +235,7 @@ private boolean dfsContainsCallStack(long spanId, List expectedCallStack
@TestParameter boolean useGlobalOpenTelemetrySDK;
- @TestParameter({"default", "test-db"})
+ @TestParameter({"jimit-test-datastore" /*, "default", "test-db"*/})
String datastoreNamedDatabase;
@BeforeClass
@@ -284,34 +282,14 @@ public void before() throws Exception {
}
// Initialize the Datastore DB w/ the OTel SDK. Ideally we'd do this is the @BeforeAll method
- // but because gRPC traces need to be deterministically force-flushed, datastore.shutdown()
- // must be called in @After for each test.
- DatastoreOptions.Builder optionsBuilder;
- if (isUsingGlobalOpenTelemetrySDK()) {
- optionsBuilder =
- DatastoreOptions.newBuilder()
- .setOpenTelemetryOptions(
- DatastoreOpenTelemetryOptions.newBuilder().setTracingEnabled(true).build());
- } else {
- optionsBuilder =
- DatastoreOptions.newBuilder()
- .setOpenTelemetryOptions(
- DatastoreOpenTelemetryOptions.newBuilder()
- .setOpenTelemetry(openTelemetrySdk)
- .setTracingEnabled(true)
- .build());
- }
-
+ // but because gRPC traces need to be deterministically force-flushed for every test
String namedDb = datastoreNamedDatabase();
- if (!namedDb.equals("default")) {
- logger.log(Level.INFO, "Integration test using named database " + namedDb);
- optionsBuilder = optionsBuilder.setDatabaseId(namedDb);
- } else {
- logger.log(Level.INFO, "Integration test using default database.");
- }
- optionsBuilder.setDatabaseId(namedDb);
- options = optionsBuilder.build();
+ logger.log(Level.INFO, "Integration test using named database " + namedDb);
+ RemoteDatastoreHelper remoteDatastoreHelper =
+ RemoteDatastoreHelper.create(namedDb, openTelemetrySdk);
+ options = remoteDatastoreHelper.getOptions();
datastore = options.getService();
+
Preconditions.checkNotNull(
datastore,
"Error instantiating Datastore. Check that the service account credentials "
From c7b80dd1dd8f3b3cf317fd05df252eebc0ba54e1 Mon Sep 17 00:00:00 2001
From: jimit-j-shah <57637300+jimit-j-shah@users.noreply.github.com>
Date: Wed, 15 May 2024 12:06:00 -0700
Subject: [PATCH 16/17] Code review: clean up personal changes
---
.../java/com/google/cloud/datastore/it/ITE2ETracingTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
index 46a3522c0..37b1be723 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
@@ -235,7 +235,7 @@ private boolean dfsContainsCallStack(long spanId, List expectedCallStack
@TestParameter boolean useGlobalOpenTelemetrySDK;
- @TestParameter({"jimit-test-datastore" /*, "default", "test-db"*/})
+ @TestParameter({"default", "test-db"})
String datastoreNamedDatabase;
@BeforeClass
From 89d28d1aec793c678f1ef39339bcc35697ffe3ec Mon Sep 17 00:00:00 2001
From: jimit-j-shah <57637300+jimit-j-shah@users.noreply.github.com>
Date: Wed, 15 May 2024 13:20:13 -0700
Subject: [PATCH 17/17] Code review: clean up
---
.../java/com/google/cloud/datastore/it/ITE2ETracingTest.java | 5 -----
1 file changed, 5 deletions(-)
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
index 37b1be723..24a9a7149 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITE2ETracingTest.java
@@ -241,15 +241,10 @@ private boolean dfsContainsCallStack(long spanId, List expectedCallStack
@BeforeClass
public static void setup() throws IOException {
projectId = DatastoreOptions.getDefaultProjectId();
- logger.info("projectId:" + projectId);
-
- // TODO(jimit) Make it re-usable w/ InMemorySpanExporter
traceExporter =
TraceExporter.createWithConfiguration(
TraceConfiguration.builder().setProjectId(projectId).build());
-
traceClient_v1 = TraceServiceClient.create();
-
random = new Random();
}