-
Notifications
You must be signed in to change notification settings - Fork 3
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 support for traceparent headers in DefaultRestClient #261
Comments
Some new observations - there are two tracing properties that are of interest for us:
|
Final testing report: Based on a discussion with @zcgandcomp, I have tested the multi-threaded environment using JMeter to verify the correct propagation of The test set up was as follows:
import java.security.SecureRandom
// Generate a 16-byte (128-bit) array
byte[] bytes = new byte[16]
new SecureRandom().nextBytes(bytes)
// Convert bytes to hex string
def hexString = bytes.collect { String.format('%02x', it) }.join()
// Store the hex string in a JMeter variable
vars.put("TRACE_ID", hexString)
private ClientRequest addTraceparentHeader(final ClientRequest request) {
final Span currentSpan = Span.current();
if (currentSpan != null) {
final SpanContext spanContext = currentSpan.getSpanContext();
if (spanContext != null) {
final String traceId = spanContext.getTraceId();
/* The parentId of the next server Span will be the current spanId */
final String parentId = spanContext.getSpanId();
final TraceFlags traceFlags = spanContext.getTraceFlags();
if (traceId != null && parentId != null && traceFlags != null) {
final String headerValue = String.format("00-%s-%s-%s",
traceId,
parentId,
traceFlags.asHex());
return ClientRequest.from(request)
.headers(headers -> headers.set(TRACEPARENT_HEADER_KEY, headerValue))
.build();
}
}
}
return request;
} The server retrieves the current final Span currentSpan = Span.current();
final SimpleMdcContextResponse simpleMdcContextResponse = new SimpleMdcContextResponse();
simpleMdcContextResponse.setTraceId(currentSpan.getSpanContext().getTraceId());
return new ObjectResponse<>(simpleMdcContextResponse);
|
No description provided.
The text was updated successfully, but these errors were encountered: