-
Notifications
You must be signed in to change notification settings - Fork 305
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
Add x-client-trace-id Header to All Requests #59
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on what I saw in the official interceptor docs as well as this Java sample |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on what I saw in the official interceptor docs as well as this Java sample |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package utility; | ||
|
||
import java.util.UUID; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.grpc.*; | ||
|
||
public class XClientTraceIdClientInterceptor implements ClientInterceptor { | ||
private static final Logger logger = LoggerFactory.getLogger(XClientTraceIdClientInterceptor.class.getClass()); | ||
private static final Metadata.Key<String> X_CLIENT_TRACE_ID = Metadata.Key.of("x-client-trace-id", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, | ||
CallOptions callOptions, Channel next) { | ||
return new ForwardingClientCall.SimpleForwardingClientCall<>(next.newCall(method, callOptions)) { | ||
|
||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
String xClientTraceId = UUID.randomUUID().toString(); | ||
headers.put(X_CLIENT_TRACE_ID, xClientTraceId); | ||
logger.info("sending request for xClientTraceId {}", xClientTraceId); | ||
|
||
super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener<>(responseListener) { | ||
@Override | ||
public void onClose(Status status, Metadata trailers) { | ||
logger.info("request completed for xClientTraceId {} with status {}", xClientTraceId, status); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This differs slightly from the Java example (linked above), but the intention here is to basically just log the example log for a successful call:
example log for a failed call:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice find. Curious, how did you generate the RST_STREAM error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the Subscribe example to open a subscription then killed the backend server that was serving the subscription |
||
super.onClose(status, trailers); | ||
} | ||
}, headers); | ||
} | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing the
x-client-trace-id
from this class as it's now being populated elsewhere