Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.google.cloud.datastore;

import com.google.api.core.BetaApi;
import com.google.common.base.Preconditions;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Represents the options that are used to configure the use of OpenTelemetry for telemetry
Expand All @@ -29,7 +30,7 @@ public class DatastoreOpenTelemetryOptions {
private final boolean tracingEnabled;
private final boolean metricsEnabled;
private final boolean exportBuiltinMetricsToGoogleCloudMonitoring;
private final @Nullable OpenTelemetry openTelemetry;
private final OpenTelemetry openTelemetry;

DatastoreOpenTelemetryOptions(Builder builder) {
this.tracingEnabled = builder.tracingEnabled;
Expand Down Expand Up @@ -92,7 +93,7 @@ public boolean isExportBuiltinMetricsToGoogleCloudMonitoring() {
*
* @return the custom {@link OpenTelemetry} instance, or {@code null} if none was provided.
*/
@Nullable
@Nonnull
Comment thread
lqiu96 marked this conversation as resolved.
public OpenTelemetry getOpenTelemetry() {
return openTelemetry;
}
Expand Down Expand Up @@ -123,7 +124,7 @@ public static class Builder {
private boolean metricsEnabled;
private boolean exportBuiltinMetricsToGoogleCloudMonitoring;

@Nullable private OpenTelemetry openTelemetry;
private OpenTelemetry openTelemetry;

private Builder() {
tracingEnabled = false;
Expand Down Expand Up @@ -159,8 +160,8 @@ public DatastoreOpenTelemetryOptions.Builder setTracingEnabled(boolean enabled)
* @param enabled Whether metrics should be enabled.
* @return this builder instance.
*/
@Nonnull
DatastoreOpenTelemetryOptions.Builder setMetricsEnabled(boolean enabled) {
@BetaApi
public DatastoreOpenTelemetryOptions.Builder setMetricsEnabled(boolean enabled) {
this.metricsEnabled = enabled;
return this;
}
Expand Down Expand Up @@ -191,8 +192,8 @@ public DatastoreOpenTelemetryOptions.Builder setExportBuiltinMetricsToGoogleClou
* @return this builder instance.
*/
@Nonnull
public DatastoreOpenTelemetryOptions.Builder setOpenTelemetry(
@Nonnull OpenTelemetry openTelemetry) {
public DatastoreOpenTelemetryOptions.Builder setOpenTelemetry(OpenTelemetry openTelemetry) {
Preconditions.checkNotNull(openTelemetry, "Custom Otel Instance cannot be null");
Comment thread
lqiu96 marked this conversation as resolved.
Outdated
this.openTelemetry = openTelemetry;
return this;
}
Expand All @@ -204,6 +205,8 @@ public DatastoreOpenTelemetryOptions.Builder setOpenTelemetry(
*/
@Nonnull
public DatastoreOpenTelemetryOptions build() {
// If no custom Otel was provided, fall back to using GlobalOpenTelemetry.
this.openTelemetry = openTelemetry == null ? GlobalOpenTelemetry.get() : openTelemetry;
Comment thread
lqiu96 marked this conversation as resolved.
Outdated
return new DatastoreOpenTelemetryOptions(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ static DatastoreMetricsRecorder getInstance(
// Note: Metrics will not be sent if an emulator is enabled.
if (otelOptions.isMetricsEnabled()) {
OpenTelemetry customOtel = otelOptions.getOpenTelemetry();
if (customOtel == null) {
customOtel = GlobalOpenTelemetry.get();
}
recorders.add(
new OpenTelemetryDatastoreMetricsRecorder(customOtel, TelemetryConstants.METRIC_PREFIX));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.cloud.datastore.telemetry.TraceUtil.Span;
import com.google.common.base.Throwables;
import io.grpc.ManagedChannelBuilder;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
Expand All @@ -51,16 +50,8 @@ public class EnabledTraceUtil implements TraceUtil {
private final DatastoreOptions datastoreOptions;

EnabledTraceUtil(DatastoreOptions datastoreOptions) {
OpenTelemetry openTelemetry = datastoreOptions.getOpenTelemetryOptions().getOpenTelemetry();

// If tracing is enabled, but an OpenTelemetry instance is not provided, fall back
// to using GlobalOpenTelemetry.
if (openTelemetry == null) {
openTelemetry = GlobalOpenTelemetry.get();
}

this.datastoreOptions = datastoreOptions;
this.openTelemetry = openTelemetry;
this.openTelemetry = datastoreOptions.getOpenTelemetryOptions().getOpenTelemetry();
this.tracer = openTelemetry.getTracer(LIBRARY_NAME);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
* limitations under the License.
*/

package com.google.cloud.datastore;
package com.google.cloud.datastore.it;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assume.assumeNotNull;

import com.google.cloud.TransportOptions;
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.telemetry.TelemetryConstants;
import com.google.cloud.grpc.GrpcTransportOptions;
import com.google.cloud.http.HttpTransportOptions;
Expand Down Expand Up @@ -59,16 +64,15 @@
*/
@RunWith(Parameterized.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class ITDatastoreBuiltInAndCustomMetrics {
public class ITDatastoreClientSideMetrics {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String DATABASE_ID =
System.getenv().getOrDefault("DATASTORE_DATABASE_ID", "");
private boolean isDatastoreClosed = false;

private final TransportOptions transportOptions;

public ITDatastoreBuiltInAndCustomMetrics(TransportOptions transportOptions) {
public ITDatastoreClientSideMetrics(TransportOptions transportOptions) {
this.transportOptions = transportOptions;
}

Expand Down Expand Up @@ -134,6 +138,7 @@ public void setUp() {

@After
public void tearDown() throws Exception {
boolean isDatastoreClosed = false;
Comment thread
lqiu96 marked this conversation as resolved.
Outdated
if (datastore != null && !isDatastoreClosed) {
Key key = datastore.newKeyFactory().setKind(kind).newKey("metrics-it-entity");
try {
Expand Down
Loading