-
Couldn't load subscription status.
- Fork 135
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 7 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
74 changes: 74 additions & 0 deletions
74
...-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,74 @@ | ||
| /* | ||
| * Copyright 2021 Google LLC | ||
nareshz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * 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.grpc.Status; | ||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.propagation.ContextPropagators; | ||
| import io.opentelemetry.context.propagation.TextMapSetter; | ||
|
|
||
nareshz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public class TraceContextInterceptor implements ClientInterceptor { | ||
nareshz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private final ContextPropagators propagators; | ||
|
|
||
| TraceContextInterceptor(OpenTelemetry openTelemetry) { | ||
| this.propagators = openTelemetry.getPropagators(); | ||
nareshz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
|
|
||
| @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(); | ||
|
|
||
nareshz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| propagators.getTextMapPropagator().inject(parentContext, headers, MetadataSetter.INSTANCE); | ||
nareshz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| super.start(new SimpleForwardingClientCallListener<RespT>(responseListener) { | ||
nareshz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Override | ||
| public void onHeaders(Metadata headers) { | ||
| super.onHeaders(headers); | ||
| } | ||
|
|
||
| @Override | ||
| public void onClose(Status status, Metadata trailers) { | ||
| super.onClose(status, trailers); | ||
| } | ||
| }, headers); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
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
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.