Add shouldStart() call to gRPC instrumentation (#6356)

This commit is contained in:
Sam Xie 2022-07-22 16:38:53 +08:00 committed by GitHub
parent 11e46f5694
commit fcda760ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -45,6 +45,10 @@ final class TracingClientInterceptor implements ClientInterceptor {
MethodDescriptor<REQUEST, RESPONSE> method, CallOptions callOptions, Channel next) {
GrpcRequest request = new GrpcRequest(method, null, null);
Context parentContext = Context.current();
if (!instrumenter.shouldStart(parentContext, request)) {
return next.newCall(method, callOptions);
}
Context context = instrumenter.start(parentContext, request);
ClientCall<REQUEST, RESPONSE> result;
try (Scope ignored = context.makeCurrent()) {

View File

@ -46,7 +46,12 @@ final class TracingServerInterceptor implements ServerInterceptor {
call.getMethodDescriptor(),
headers,
call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
Context context = instrumenter.start(Context.current(), request);
Context parentContext = Context.current();
if (!instrumenter.shouldStart(parentContext, request)) {
return next.startCall(call, headers);
}
Context context = instrumenter.start(parentContext, request);
try (Scope ignored = context.makeCurrent()) {
return new TracingServerCall<>(call, context, request).start(headers, next);