Skip to content

Commit

Permalink
feat: client built in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Oct 14, 2024
1 parent 1f53d38 commit 08501b9
Showing 1 changed file with 10 additions and 16 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,7 +725,6 @@ 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";

Expand Down Expand Up @@ -754,13 +753,6 @@ public boolean isEnableApiTracing() {
return Boolean.parseBoolean(System.getenv(SPANNER_ENABLE_API_TRACING));
}

@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));
}

@Override
public boolean isEnableEndToEndTracing() {
return Boolean.parseBoolean(System.getenv(SPANNER_ENABLE_END_TO_END_TRACING));
Expand Down Expand Up @@ -828,7 +820,7 @@ 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 enableBuiltInMetrics = true;
private boolean enableEndToEndTracing = SpannerOptions.environment.isEnableEndToEndTracing();

private static String createCustomClientLibToken(String token) {
Expand Down Expand Up @@ -1410,8 +1402,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 as default.
*/
public Builder setEnableBuiltInMetrics(boolean enableBuiltInMetrics) {
this.enableBuiltInMetrics = enableBuiltInMetrics;
return this;
}
Expand Down Expand Up @@ -1726,14 +1721,13 @@ private ApiTracerFactory getDefaultApiTracerFactory() {
private ApiTracerFactory createMetricsApiTracerFactory() {
OpenTelemetry openTelemetry =
this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry(
getDefaultProjectId(), getCredentials());
this.getProjectId(), getCredentials());

return openTelemetry != null
? new MetricsTracerFactory(
new OpenTelemetryMetricsRecorder(openTelemetry, BuiltInMetricsConstant.METER_NAME),
builtInOpenTelemetryMetricsProvider.createClientAttributes(
getDefaultProjectId(),
"spanner-java/" + GaxProperties.getLibraryVersion(getClass())))
this.getProjectId(), "spanner-java/" + GaxProperties.getLibraryVersion(getClass())))
: null;
}

Expand All @@ -1750,7 +1744,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

0 comments on commit 08501b9

Please sign in to comment.