Skip to content

Commit

Permalink
feat: client built in metrics (#3408)
Browse files Browse the repository at this point in the history
* feat: client built in metrics

* review comments

* Added environment variable for disabling client metrics
  • Loading branch information
surbhigarg92 authored Nov 1, 2024
1 parent b39cf00 commit 6a36103
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ default boolean isEnableApiTracing() {
}

default boolean isEnableBuiltInMetrics() {
return false;
return true;
}

default boolean isEnableEndToEndTracing() {
Expand All @@ -725,9 +725,9 @@ private static class SpannerEnvironmentImpl implements SpannerEnvironment {
"SPANNER_OPTIMIZER_STATISTICS_PACKAGE";
private static final String SPANNER_ENABLE_EXTENDED_TRACING = "SPANNER_ENABLE_EXTENDED_TRACING";
private static final String SPANNER_ENABLE_API_TRACING = "SPANNER_ENABLE_API_TRACING";
private static final String SPANNER_ENABLE_BUILTIN_METRICS = "SPANNER_ENABLE_BUILTIN_METRICS";
private static final String SPANNER_ENABLE_END_TO_END_TRACING =
"SPANNER_ENABLE_END_TO_END_TRACING";
private static final String SPANNER_DISABLE_BUILTIN_METRICS = "SPANNER_DISABLE_BUILTIN_METRICS";

private SpannerEnvironmentImpl() {}

Expand Down Expand Up @@ -756,9 +756,7 @@ public boolean isEnableApiTracing() {

@Override
public boolean isEnableBuiltInMetrics() {
// The environment variable SPANNER_ENABLE_BUILTIN_METRICS is used for testing and will be
// removed in the future.
return Boolean.parseBoolean(System.getenv(SPANNER_ENABLE_BUILTIN_METRICS));
return !Boolean.parseBoolean(System.getenv(SPANNER_DISABLE_BUILTIN_METRICS));
}

@Override
Expand Down Expand Up @@ -828,8 +826,8 @@ public static class Builder
private OpenTelemetry openTelemetry;
private boolean enableApiTracing = SpannerOptions.environment.isEnableApiTracing();
private boolean enableExtendedTracing = SpannerOptions.environment.isEnableExtendedTracing();
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics();
private boolean enableEndToEndTracing = SpannerOptions.environment.isEnableEndToEndTracing();
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics();

private static String createCustomClientLibToken(String token) {
return token + " " + ServiceOptions.getGoogApiClientLibName();
Expand Down Expand Up @@ -1410,8 +1408,11 @@ public Builder setEnableApiTracing(boolean enableApiTracing) {
return this;
}

/** Enabling this will enable built in metrics for each individual RPC execution. */
Builder setEnableBuiltInMetrics(boolean enableBuiltInMetrics) {
/**
* Sets whether to enable or disable built in metrics for Data client operations. Built in
* metrics are enabled by default.
*/
public Builder setBuiltInMetricsEnabled(boolean enableBuiltInMetrics) {
this.enableBuiltInMetrics = enableBuiltInMetrics;
return this;
}
Expand Down Expand Up @@ -1749,7 +1750,7 @@ public boolean isEnableApiTracing() {
* Returns true if an {@link com.google.api.gax.tracing.MetricsTracer} should be created and set
* on the Spanner client.
*/
boolean isEnableBuiltInMetrics() {
public boolean isEnableBuiltInMetrics() {
return enableBuiltInMetrics;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void createSpannerInstance() {
.build())
// Setting this to false so that Spanner Options does not register Metrics Tracer
// factory again.
.setEnableBuiltInMetrics(false)
.setBuiltInMetricsEnabled(false)
.setApiTracerFactory(metricsTracerFactory)
.build()
.getService();
Expand Down

0 comments on commit 6a36103

Please sign in to comment.