Skip to content

feat: client built in metrics #3408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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
Loading