All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.kristofa.brave.http.HttpClientRequestAdapter Maven / Gradle / Ivy

Go to download

Abstraction that makes it easier to implement brave in http clients and servers.

There is a newer version: 4.13.6
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy