-
Notifications
You must be signed in to change notification settings - Fork 132
feat: Add opt-in flag and ClientInterceptor to propagate trace context for Spanner end to end tracing #3162
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
rahul2393
merged 33 commits into
googleapis:main
from
nareshz:grpc-telemetry-client-interceptor
Sep 27, 2024
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
df54343
feat(spanner): Add x-goog-spanner-end-to-end-tracing header for reque…
nareshz b4864da
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 290f01e
Add Grpc Telemetry client interceptor for trace context propagation
nareshz 3c92b26
Remove print statement
nareshz 3671173
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 9379106
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 5033b1b
copy grpc telemetry client interceptor code
nareshz d7c778a
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 4613e29
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 7c39b82
rename spanner option for end to end tracing
nareshz d2ac8b4
add test for custom client interceptor code
nareshz 3eb5e47
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 233acd2
resolve comments
nareshz 71a8f39
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 1883fed
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 01aa679
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz be7d426
Merge branch 'e2e-tracing-header' into grpc-telemetry-client-interceptor
nareshz ab71745
Make trace context interceptor conditional based on client opt-in
nareshz 2035d59
resolve comments
nareshz 6af5e04
reformat code
nareshz 0aa51ff
resolve comments
nareshz 39269c0
fix clirr build failure
nareshz d2fd1c8
fix lint errors
nareshz 2b9409b
combine enable/disable fn into single fn
nareshz b62b3c0
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz e12cd0f
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 0446fb5
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz aa729a0
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz 0febebc
Merge branch 'main' of https://github.com/googleapis/java-spanner int…
nareshz b3a6d31
Rename server side tracing to spanner tracing
nareshz 117c279
Rename spanner tracing to end to end tracing
nareshz a982c69
fix comments
nareshz 0a2622d
Fix lint error
nareshz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/TraceContextInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.spanner.spi.v1; | ||
|
||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.ClientCall; | ||
import io.grpc.ClientInterceptor; | ||
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; | ||
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.context.propagation.TextMapSetter; | ||
|
||
/** | ||
* Intercepts all gRPC calls and injects trace context related headers to propagate trace context to | ||
* Spanner. This class takes reference from OpenTelemetry's JAVA instrumentation library for gRPC. | ||
* https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/9ecf7965aa455d41ea8cc0761b6c6b6eeb106324/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java#L27 | ||
*/ | ||
class TraceContextInterceptor implements ClientInterceptor { | ||
|
||
private final TextMapPropagator textMapPropagator; | ||
|
||
TraceContextInterceptor(OpenTelemetry openTelemetry) { | ||
this.textMapPropagator = openTelemetry.getPropagators().getTextMapPropagator(); | ||
} | ||
|
||
enum MetadataSetter implements TextMapSetter<Metadata> { | ||
INSTANCE; | ||
|
||
@SuppressWarnings("null") | ||
@Override | ||
public void set(Metadata carrier, String key, String value) { | ||
carrier.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value); | ||
} | ||
} | ||
|
||
private static final class NoopSimpleForwardingClientCallListener<RespT> | ||
extends SimpleForwardingClientCallListener<RespT> { | ||
public NoopSimpleForwardingClientCallListener(ClientCall.Listener<RespT> responseListener) { | ||
super(responseListener); | ||
} | ||
} | ||
|
||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | ||
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { | ||
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { | ||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
Context parentContext = Context.current(); | ||
textMapPropagator.inject(parentContext, headers, MetadataSetter.INSTANCE); | ||
super.start(new NoopSimpleForwardingClientCallListener<RespT>(responseListener), headers); | ||
} | ||
}; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner; | ||
|
||
/** Helper to configure SpannerOptions for tests. */ | ||
public class SpannerOptionsHelper { | ||
|
||
/** | ||
* Resets the activeTracingFramework. This variable is used for internal testing, and is not a | ||
* valid production scenario. | ||
*/ | ||
public static void resetActiveTracingFramework() { | ||
SpannerOptions.resetActiveTracingFramework(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.