com.github.kristofa.brave.http.HttpClientRequestAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brave-http Show documentation
Show all versions of brave-http Show documentation
Abstraction that makes it easier to implement brave in http clients and servers.
package com.github.kristofa.brave.http;
import com.github.kristofa.brave.ClientRequestAdapter;
import com.github.kristofa.brave.IdConversion;
import com.github.kristofa.brave.KeyValueAnnotation;
import com.github.kristofa.brave.SpanId;
import com.github.kristofa.brave.internal.Nullable;
import com.twitter.zipkin.gen.Endpoint;
import java.util.Collection;
import java.util.Collections;
import zipkin.TraceKeys;
/**
* @deprecated Replaced by {@code HttpClientParser} from brave-http
*/
@Deprecated
public class HttpClientRequestAdapter implements ClientRequestAdapter {
private final HttpClientRequest request;
private final SpanNameProvider spanNameProvider;
public HttpClientRequestAdapter(HttpClientRequest request, SpanNameProvider spanNameProvider) {
this.request = request;
this.spanNameProvider = spanNameProvider;
}
@Override
public String getSpanName() {
return spanNameProvider.spanName(request);
}
@Override
public void addSpanIdToRequest(@Nullable SpanId spanId) {
if (spanId == null) {
request.addHeader(BraveHttpHeaders.Sampled.getName(), "0");
} else {
request.addHeader(BraveHttpHeaders.Sampled.getName(), "1");
request.addHeader(BraveHttpHeaders.TraceId.getName(), spanId.traceIdString());
request.addHeader(BraveHttpHeaders.SpanId.getName(), IdConversion.convertToString(spanId.spanId));
if (spanId.nullableParentId() != null) {
request.addHeader(BraveHttpHeaders.ParentSpanId.getName(), IdConversion.convertToString(spanId.parentId));
}
}
}
@Override
public Collection requestAnnotations() {
return Collections.singleton(KeyValueAnnotation.create(
TraceKeys.HTTP_URL, request.getUri().toString()));
}
@Override
public Endpoint serverAddress() {
return null;
}
}