-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes it possible to read commonly defined gRPC data
- Loading branch information
Adrian Cole
committed
Apr 28, 2020
1 parent
f3a6d98
commit 1959291
Showing
14 changed files
with
396 additions
and
256 deletions.
There are no files selected for viewing
This file contains 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 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
54 changes: 54 additions & 0 deletions
54
instrumentation/grpc/src/main/java/brave/grpc/GrpcRequest.java
This file contains 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,54 @@ | ||
/* | ||
* Copyright 2013-2020 The OpenZipkin Authors | ||
* | ||
* 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 | ||
* | ||
* http://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 brave.grpc; | ||
|
||
import brave.rpc.RpcTracing; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
|
||
/** | ||
* Allows access gRPC specific aspects of a client or server request during sampling and parsing. | ||
* | ||
* <p>Here's an example that adds default tags, and if gRPC, the {@linkplain | ||
* MethodDescriptor#getType() method type}: | ||
* <pre>{@code | ||
* Tag<GrpcRequest> methodType = new Tag<GrpcRequest>("grpc.method_type") { | ||
* @Override protected String parseValue(GrpcRequest input, TraceContext context) { | ||
* return input.methodDescriptor().getType().name(); | ||
* } | ||
* }; | ||
* | ||
* RpcRequestParser addMethodType = (req, context, span) -> { | ||
* RpcRequestParser.DEFAULT.parse(req, context, span); | ||
* if (req instanceof GrpcRequest) methodType.tag((GrpcRequest) req, span); | ||
* }; | ||
* | ||
* grpcTracing = GrpcTracing.create(RpcTracing.newBuilder(tracing) | ||
* .clientRequestParser(addMethodType) | ||
* .serverRequestParser(addMethodType).build()); | ||
* }</pre> | ||
* | ||
* @see GrpcResponse | ||
* @see GrpcClientRequest | ||
* @see GrpcServerRequest | ||
* @see RpcTracing#clientRequestParser() | ||
* @see RpcTracing#serverRequestParser() | ||
* @since 5.12 | ||
*/ | ||
// NOTE: gRPC is Java 1.7+, so we cannot add methods to this later | ||
public interface GrpcRequest { | ||
MethodDescriptor<?, ?> methodDescriptor(); | ||
|
||
Metadata headers(); | ||
} |
55 changes: 55 additions & 0 deletions
55
instrumentation/grpc/src/main/java/brave/grpc/GrpcResponse.java
This file contains 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,55 @@ | ||
/* | ||
* Copyright 2013-2020 The OpenZipkin Authors | ||
* | ||
* 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 | ||
* | ||
* http://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 brave.grpc; | ||
|
||
import brave.rpc.RpcTracing; | ||
import io.grpc.Metadata; | ||
import io.grpc.Status; | ||
|
||
/** | ||
* Allows access gRPC specific aspects of a client or server response for parsing. | ||
* | ||
* <p>Here's an example that adds default tags, and if gRPC, the response encoding: | ||
* <pre>{@code | ||
* Tag<GrpcResponse> responseEncoding = new Tag<GrpcResponse>("grpc.response_encoding") { | ||
* @Override protected String parseValue(GrpcResponse input, TraceContext context) { | ||
* return input.headers().get(GrpcUtil.MESSAGE_ENCODING_KEY); | ||
* } | ||
* }; | ||
* | ||
* RpcResponseParser addResponseEncoding = (res, context, span) -> { | ||
* RpcResponseParser.DEFAULT.parse(res, context, span); | ||
* if (res instanceof GrpcResponse) responseEncoding.tag((GrpcResponse) res, span); | ||
* }; | ||
* | ||
* grpcTracing = GrpcTracing.create(RpcTracing.newBuilder(tracing) | ||
* .clientResponseParser(addResponseEncoding); | ||
* .serverResponseParser(addResponseEncoding).build()); | ||
* }</pre> | ||
* | ||
* @see GrpcRequest | ||
* @see GrpcClientResponse | ||
* @see GrpcServerResponse | ||
* @see RpcTracing#clientResponseParser() | ||
* @see RpcTracing#serverResponseParser() | ||
* @since 5.12 | ||
*/ | ||
// NOTE: gRPC is Java 1.7+, so we cannot add methods to this later | ||
public interface GrpcResponse { | ||
Metadata headers(); | ||
|
||
Status status(); | ||
|
||
Metadata trailers(); | ||
} |
This file contains 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 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.