Skip to content

Commit

Permalink
Rename spanner tracing to end to end tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
nareshz committed Sep 26, 2024
1 parent b3a6d31 commit 117c279
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions google-cloud-spanner/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,11 @@
<method>boolean isEnableApiTracing()</method>
</difference>

<!-- Added Spanner tracing option -->
<!-- Added end to end tracing option -->
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/SpannerOptions$SpannerEnvironment</className>
<method>boolean isEnableSpannerTracing()</method>
<method>boolean isEnableEndToEndTracing()</method>
</difference>

<!-- Added Built In Metrics option -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
private final boolean enableApiTracing;
private final boolean enableBuiltInMetrics;
private final boolean enableExtendedTracing;
private final boolean enableSpannerTracing;
private final boolean enableEndToEndTracing;

enum TracingFramework {
OPEN_CENSUS,
Expand Down Expand Up @@ -671,7 +671,7 @@ protected SpannerOptions(Builder builder) {
enableApiTracing = builder.enableApiTracing;
enableExtendedTracing = builder.enableExtendedTracing;
enableBuiltInMetrics = builder.enableBuiltInMetrics;
enableSpannerTracing = builder.enableSpannerTracing;
enableEndToEndTracing = builder.enableEndToEndTracing;
}

/**
Expand Down Expand Up @@ -709,7 +709,7 @@ default boolean isEnableBuiltInMetrics() {
return false;
}

default boolean isEnableSpannerTracing() {
default boolean isEnableEndToEndTracing() {
return false;
}
}
Expand All @@ -726,8 +726,8 @@ private static class SpannerEnvironmentImpl implements SpannerEnvironment {
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_SPANNER_TRACING =
"SPANNER_ENABLE_SPANNER_TRACING";
private static final String SPANNER_ENABLE_END_TO_END_TRACING =
"SPANNER_ENABLE_END_TO_END_TRACING";

private SpannerEnvironmentImpl() {}

Expand Down Expand Up @@ -762,8 +762,8 @@ public boolean isEnableBuiltInMetrics() {
}

@Override
public boolean isEnableSpannerTracing() {
return Boolean.parseBoolean(System.getenv(SPANNER_ENABLE_SPANNER_TRACING));
public boolean isEnableEndToEndTracing() {
return Boolean.parseBoolean(System.getenv(SPANNER_ENABLE_END_TO_END_TRACING));
}
}

Expand Down Expand Up @@ -829,8 +829,8 @@ public static class Builder
private boolean enableApiTracing = SpannerOptions.environment.isEnableApiTracing();
private boolean enableExtendedTracing = SpannerOptions.environment.isEnableExtendedTracing();
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics();
private boolean enableSpannerTracing =
SpannerOptions.environment.isEnableSpannerTracing();
private boolean enableEndToEndTracing =
SpannerOptions.environment.isEnableEndToEndTracing();

private static String createCustomClientLibToken(String token) {
return token + " " + ServiceOptions.getGoogApiClientLibName();
Expand Down Expand Up @@ -897,7 +897,7 @@ protected Builder() {
this.enableApiTracing = options.enableApiTracing;
this.enableExtendedTracing = options.enableExtendedTracing;
this.enableBuiltInMetrics = options.enableBuiltInMetrics;
this.enableSpannerTracing = options.enableSpannerTracing;
this.enableEndToEndTracing = options.enableEndToEndTracing;
}

@Override
Expand Down Expand Up @@ -1432,13 +1432,13 @@ public Builder setEnableExtendedTracing(boolean enableExtendedTracing) {
}

/**
* Sets whether to enable Spanner tracing. Enabling this option will create the trace
* spans at the Spanner layer. By default, spanner tracing is disabled. Enabling spanner
* tracing requires OpenTelemetry to be set up properly. Simply enabling this option
* won't generate spanner traces.
* Sets whether to enable end to end tracing. Enabling this option will create the
* trace spans at the Spanner layer. By default, end to end tracing is disabled.
* Enabling end to end tracing requires OpenTelemetry to be set up properly. Simply
* enabling this option won't generate traces at Spanner layer.
*/
public Builder setEnableSpannerTracing(boolean enableSpannerTracing) {
this.enableSpannerTracing = enableSpannerTracing;
public Builder setEnableEndToEndTracing(boolean enableEndToEndTracing) {
this.enableEndToEndTracing = enableEndToEndTracing;
return this;
}

Expand Down Expand Up @@ -1774,11 +1774,11 @@ public boolean isEnableExtendedTracing() {
}

/**
* Returns whether Spanner tracing is enabled. If this option is enabled then trace spans
* Returns whether end to end tracing is enabled. If this option is enabled then trace spans
* will be created at the Spanner layer.
*/
public boolean isSpannerTracingEnabled() {
return enableSpannerTracing;
public boolean isEndToEndTracingEnabled() {
return enableEndToEndTracing;
}

/** Returns the default query options to use for the specific database. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public class GapicSpannerRpc implements SpannerRpc {
private static final ConcurrentMap<String, RateLimiter> ADMINISTRATIVE_REQUESTS_RATE_LIMITERS =
new ConcurrentHashMap<>();
private final boolean leaderAwareRoutingEnabled;
private final boolean spannerTracingEnabled;
private final boolean endToEndTracingEnabled;
private final int numChannels;
private final boolean isGrpcGcpExtensionEnabled;

Expand Down Expand Up @@ -326,7 +326,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
this.callCredentialsProvider = options.getCallCredentialsProvider();
this.compressorName = options.getCompressorName();
this.leaderAwareRoutingEnabled = options.isLeaderAwareRoutingEnabled();
this.spannerTracingEnabled = options.isSpannerTracingEnabled();
this.endToEndTracingEnabled = options.isEndToEndTracingEnabled();
this.numChannels = options.getNumChannels();
this.isGrpcGcpExtensionEnabled = options.isGrpcGcpExtensionEnabled();

Expand All @@ -353,7 +353,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
options.getInterceptorProvider(),
SpannerInterceptorProvider.createDefault(options.getOpenTelemetry())))
// This sets the trace context headers.
.withTraceContext(spannerTracingEnabled, options.getOpenTelemetry())
.withTraceContext(endToEndTracingEnabled, options.getOpenTelemetry())
// This sets the response compressor (Server -> Client).
.withEncoding(compressorName))
.setHeaderProvider(headerProviderWithUserAgent)
Expand Down Expand Up @@ -2011,8 +2011,8 @@ <ReqT, RespT> GrpcCallContext newCallContext(
if (routeToLeader && leaderAwareRoutingEnabled) {
context = context.withExtraHeaders(metadataProvider.newRouteToLeaderHeader());
}
if (spannerTracingEnabled) {
context = context.withExtraHeaders(metadataProvider.newSpannerTracingHeader());
if (endToEndTracingEnabled) {
context = context.withExtraHeaders(metadataProvider.newEndToEndTracingHeader());
}
if (callCredentialsProvider != null) {
CallCredentials callCredentials = callCredentialsProvider.getCallCredentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ SpannerInterceptorProvider withEncoding(String encoding) {
}

SpannerInterceptorProvider withTraceContext(
boolean spannerTracingEnabled, OpenTelemetry openTelemetry) {
if (spannerTracingEnabled) {
boolean endToEndTracingEnabled, OpenTelemetry openTelemetry) {
if (endToEndTracingEnabled) {
return with(new TraceContextInterceptor(openTelemetry));
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class SpannerMetadataProvider {
private final Map<Metadata.Key<String>, String> headers;
private final String resourceHeaderKey;
private static final String ROUTE_TO_LEADER_HEADER_KEY = "x-goog-spanner-route-to-leader";
private static final String SPANNER_TRACING_HEADER_KEY = "x-goog-spanner-end-to-end-tracing";
private static final String END_TO_END_TRACING_HEADER_KEY = "x-goog-spanner-end-to-end-tracing";
private static final Pattern[] RESOURCE_TOKEN_PATTERNS = {
Pattern.compile("^(?<headerValue>projects/[^/]*/instances/[^/]*/databases/[^/]*)(.*)?"),
Pattern.compile("^(?<headerValue>projects/[^/]*/instances/[^/]*)(.*)?")
};

private static final Map<String, List<String>> ROUTE_TO_LEADER_HEADER_MAP =
ImmutableMap.of(ROUTE_TO_LEADER_HEADER_KEY, Collections.singletonList("true"));
private static final Map<String, List<String>> SPANNER_TRACING_HEADER_MAP =
ImmutableMap.of(SPANNER_TRACING_HEADER_KEY, Collections.singletonList("true"));
private static final Map<String, List<String>> END_TO_END_TRACING_HEADER_MAP =
ImmutableMap.of(END_TO_END_TRACING_HEADER_KEY, Collections.singletonList("true"));

private SpannerMetadataProvider(Map<String, String> headers, String resourceHeaderKey) {
this.resourceHeaderKey = resourceHeaderKey;
Expand Down Expand Up @@ -92,8 +92,8 @@ Map<String, List<String>> newRouteToLeaderHeader() {
return ROUTE_TO_LEADER_HEADER_MAP;
}

Map<String, List<String>> newSpannerTracingHeader() {
return SPANNER_TRACING_HEADER_MAP;
Map<String, List<String>> newEndToEndTracingHeader() {
return END_TO_END_TRACING_HEADER_MAP;
}

private Map<Metadata.Key<String>, String> constructHeadersAsMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,21 +737,21 @@ public void testLeaderAwareRoutingEnablement() {
}

@Test
public void testSpannerTracingEnablement() {
public void testEndToEndTracingEnablement() {
// Test that end to end tracing is disabled by default.
assertFalse(SpannerOptions.newBuilder().setProjectId("p").build().isSpannerTracingEnabled());
assertFalse(SpannerOptions.newBuilder().setProjectId("p").build().isEndToEndTracingEnabled());
assertTrue(
SpannerOptions.newBuilder()
.setProjectId("p")
.setEnableSpannerTracing(true)
.setEnableEndToEndTracing(true)
.build()
.isSpannerTracingEnabled());
.isEndToEndTracingEnabled());
assertFalse(
SpannerOptions.newBuilder()
.setProjectId("p")
.setEnableSpannerTracing(false)
.setEnableEndToEndTracing(false)
.build()
.isSpannerTracingEnabled());
.isEndToEndTracingEnabled());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class GapicSpannerRpcTest {
private static String defaultUserAgent;
private static Spanner spanner;
private static boolean isRouteToLeader;
private static boolean isSpannerTracing;
private static boolean isEndToEndTracing;
private static boolean isTraceContextPresent;

@Parameter public Dialect dialect;
Expand Down Expand Up @@ -215,16 +215,16 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
Key.of(
"x-goog-spanner-route-to-leader",
Metadata.ASCII_STRING_MARSHALLER));
String spannerTracingHeader =
String endToEndTracingHeader =
headers.get(
Key.of(
"x-goog-spanner-end-to-end-tracing",
Metadata.ASCII_STRING_MARSHALLER));
isRouteToLeader =
(routeToLeaderHeader != null && routeToLeaderHeader.equals("true"));
isSpannerTracing =
(spannerTracingHeader != null
&& spannerTracingHeader.equals("true"));
isEndToEndTracing =
(endToEndTracingHeader != null
&& endToEndTracingHeader.equals("true"));
}
return Contexts.interceptCall(Context.current(), call, headers, next);
}
Expand All @@ -248,7 +248,7 @@ public void reset() throws InterruptedException {
server.awaitTermination();
}
isRouteToLeader = false;
isSpannerTracing = false;
isEndToEndTracing = false;
isTraceContextPresent = false;
}

Expand Down Expand Up @@ -491,11 +491,11 @@ public void testNewCallContextWithRouteToLeaderHeaderAndLarDisabled() {
}

@Test
public void testNewCallContextWithSpannerTracingHeader() {
public void testNewCallContextWithEndToEndTracingHeader() {
SpannerOptions options =
SpannerOptions.newBuilder()
.setProjectId("some-project")
.setEnableSpannerTracing(true)
.setEnableEndToEndTracing(true)
.build();
GapicSpannerRpc rpc = new GapicSpannerRpc(options, false);
GrpcCallContext callContext =
Expand All @@ -515,11 +515,11 @@ public void testNewCallContextWithSpannerTracingHeader() {
}

@Test
public void testNewCallContextWithoutSpannerTracingHeader() {
public void testNewCallContextWithoutEndToEndTracingHeader() {
SpannerOptions options =
SpannerOptions.newBuilder()
.setProjectId("some-project")
.setEnableSpannerTracing(false)
.setEnableEndToEndTracing(false)
.build();
GapicSpannerRpc rpc = new GapicSpannerRpc(options, false);
GrpcCallContext callContext =
Expand All @@ -534,9 +534,9 @@ public void testNewCallContextWithoutSpannerTracingHeader() {
}

@Test
public void testSpannerTracingHeaderWithEnabledTracing() {
public void testEndToEndTracingHeaderWithEnabledTracing() {
final SpannerOptions options =
createSpannerOptions().toBuilder().setEnableSpannerTracing(true).build();
createSpannerOptions().toBuilder().setEnableEndToEndTracing(true).build();
try (Spanner spanner = options.getService()) {
final DatabaseClient databaseClient =
spanner.getDatabaseClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"));
Expand All @@ -547,13 +547,13 @@ public void testSpannerTracingHeaderWithEnabledTracing() {
return null;
});
}
assertTrue(isSpannerTracing);
assertTrue(isEndToEndTracing);
}

@Test
public void testSpannerTracingHeaderWithDisabledTracing() {
public void testEndToEndTracingHeaderWithDisabledTracing() {
final SpannerOptions options =
createSpannerOptions().toBuilder().setEnableSpannerTracing(false).build();
createSpannerOptions().toBuilder().setEnableEndToEndTracing(false).build();
try (Spanner spanner = options.getService()) {
final DatabaseClient databaseClient =
spanner.getDatabaseClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"));
Expand All @@ -564,7 +564,7 @@ public void testSpannerTracingHeaderWithDisabledTracing() {
return null;
});
}
assertFalse(isSpannerTracing);
assertFalse(isEndToEndTracing);
}

@Test
Expand Down Expand Up @@ -639,7 +639,7 @@ public void testCustomUserAgent() {
}

@Test
public void testTraceContextHeaderWithOpenTelemetryAndSpannerTracingEnabled() {
public void testTraceContextHeaderWithOpenTelemetryAndEndToEndTracingEnabled() {
OpenTelemetry openTelemetry =
OpenTelemetrySdk.builder()
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
Expand All @@ -650,7 +650,7 @@ public void testTraceContextHeaderWithOpenTelemetryAndSpannerTracingEnabled() {
createSpannerOptions()
.toBuilder()
.setOpenTelemetry(openTelemetry)
.setEnableSpannerTracing(true)
.setEnableEndToEndTracing(true)
.build();
try (Spanner spanner = options.getService()) {
final DatabaseClient databaseClient =
Expand All @@ -665,7 +665,7 @@ public void testTraceContextHeaderWithOpenTelemetryAndSpannerTracingEnabled() {
}

@Test
public void testTraceContextHeaderWithOpenTelemetryAndSpannerTracingDisabled() {
public void testTraceContextHeaderWithOpenTelemetryAndEndToEndTracingDisabled() {
OpenTelemetry openTelemetry =
OpenTelemetrySdk.builder()
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
Expand All @@ -676,7 +676,7 @@ public void testTraceContextHeaderWithOpenTelemetryAndSpannerTracingDisabled() {
createSpannerOptions()
.toBuilder()
.setOpenTelemetry(openTelemetry)
.setEnableSpannerTracing(false)
.setEnableEndToEndTracing(false)
.build();
try (Spanner spanner = options.getService()) {
final DatabaseClient databaseClient =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testNewRouteToLeaderHeader() {
public void testNewEndToEndTracingHeader() {
SpannerMetadataProvider metadataProvider =
SpannerMetadataProvider.create(ImmutableMap.of(), "header1");
Map<String, List<String>> extraHeaders = metadataProvider.newSpannerTracingHeader();
Map<String, List<String>> extraHeaders = metadataProvider.newEndToEndTracingHeader();
Map<String, List<String>> expectedHeaders =
ImmutableMap.<String, List<String>>of(
"x-goog-spanner-end-to-end-tracing", ImmutableList.of("true"));
Expand Down

0 comments on commit 117c279

Please sign in to comment.