com.github.kristofa.brave.ClientRequestInterceptor Maven / Gradle / Ivy
package com.github.kristofa.brave;
import static com.github.kristofa.brave.internal.Util.checkNotNull;
/**
* Contains logic for handling an outgoing client request.
* This means it will:
*
* - Start a new span
* - Make sure span parameters are added to outgoing request
* - Set client service name
* - Submit client sent annotation
*
*
* The only thing you have to do is implement a ClientRequestAdapter.
*
* @see ClientRequestAdapter
*
*/
public class ClientRequestInterceptor {
private final ClientTracer clientTracer;
public ClientRequestInterceptor(ClientTracer clientTracer) {
this.clientTracer = checkNotNull(clientTracer, "Null clientTracer");
}
/**
* Handles outgoing request.
*
* @param adapter The adapter deals with implementation specific details.
*/
public void handle(ClientRequestAdapter adapter) {
SpanId spanId = clientTracer.startNewSpan(adapter.getSpanName());
if (spanId == null) {
// We will not trace this request.
adapter.addSpanIdToRequest(null);
} else {
adapter.addSpanIdToRequest(spanId);
clientTracer.setCurrentClientServiceName(adapter.getClientServiceName());
for(KeyValueAnnotation annotation : adapter.requestAnnotations()) {
clientTracer.submitBinaryAnnotation(annotation.getKey(), annotation.getValue());
}
clientTracer.setClientSent();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy