Class HttpTracing
- java.lang.Object
-
- brave.http.HttpTracing
-
- All Implemented Interfaces:
Closeable
public class HttpTracing extends Object implements Closeable
Instances built viacreate(Tracing)
ornewBuilder(Tracing)
are registered automatically such that statically configured instrumentation like HTTP clients can usecurrent()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpTracing.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpTracing
clientOf(String serverName)
Scopes this component for a client of the indicated server.HttpClientParser
clientParser()
Deprecated.Since 5.10, useclientRequestParser()
andclientResponseParser()
HttpRequestParser
clientRequestParser()
Used byHttpClientHandler.handleSend(HttpClientRequest)
to add a span name and tags about the request before it is sent to the server.brave.sampler.SamplerFunction<HttpRequest>
clientRequestSampler()
Returns an overriding sampling decision for a new trace.HttpResponseParser
clientResponseParser()
Used byHttpClientHandler.handleReceive(HttpClientResponse, Span)
to add tags about the response received from the server.HttpSampler
clientSampler()
Deprecated.Since 5.8, useclientRequestSampler()
void
close()
static HttpTracing
create(brave.Tracing tracing)
static HttpTracing
current()
Returns the most recently created tracing component iff it hasn't been closed.static HttpTracing.Builder
newBuilder(brave.Tracing tracing)
brave.propagation.Propagation<String>
propagation()
Returns the propagation component used by HTTP instrumentation.String
serverName()
Used by http clients to indicate the name of the destination service.HttpServerParser
serverParser()
Deprecated.Since 5.10, useserverRequestParser()
andserverResponseParser()
HttpRequestParser
serverRequestParser()
Used byHttpServerHandler.handleReceive(HttpServerRequest)
to add a span name and tags about the request before the server processes it.brave.sampler.SamplerFunction<HttpRequest>
serverRequestSampler()
Returns an overriding sampling decision for a new trace.HttpResponseParser
serverResponseParser()
Used byHttpServerHandler.handleSend(Object, Throwable, Span)
to add tags about the response sent to the client.HttpSampler
serverSampler()
Deprecated.Since 5.8, useserverRequestSampler()
HttpTracing.Builder
toBuilder()
brave.Tracing
tracing()
-
-
-
Method Detail
-
create
public static HttpTracing create(brave.Tracing tracing)
-
newBuilder
public static HttpTracing.Builder newBuilder(brave.Tracing tracing)
-
tracing
public brave.Tracing tracing()
-
clientRequestParser
public HttpRequestParser clientRequestParser()
Used byHttpClientHandler.handleSend(HttpClientRequest)
to add a span name and tags about the request before it is sent to the server.- Since:
- 5.10
-
clientResponseParser
public HttpResponseParser clientResponseParser()
Used byHttpClientHandler.handleReceive(HttpClientResponse, Span)
to add tags about the response received from the server.- Since:
- 5.10
-
clientParser
@Deprecated public HttpClientParser clientParser()
Deprecated.Since 5.10, useclientRequestParser()
andclientResponseParser()
-
serverName
public String serverName()
Used by http clients to indicate the name of the destination service.Defaults to "", which will not show in the zipkin UI or end up in the dependency graph.
When present, a link from
Tracing.Builder.localServiceName(String)
to this name will increment for each traced client call.As this is endpoint-specific, it is typical to create a scoped instance of HttpTracing to assign this value.
For example:
github = TracingHttpClientBuilder.create(httpTracing.clientOf("github"));
- See Also:
HttpClientHandler
,Span.remoteServiceName(String)
-
clientOf
public HttpTracing clientOf(String serverName)
Scopes this component for a client of the indicated server.- See Also:
serverName()
-
serverRequestParser
public HttpRequestParser serverRequestParser()
Used byHttpServerHandler.handleReceive(HttpServerRequest)
to add a span name and tags about the request before the server processes it.- Since:
- 5.10
-
serverResponseParser
public HttpResponseParser serverResponseParser()
Used byHttpServerHandler.handleSend(Object, Throwable, Span)
to add tags about the response sent to the client.- Since:
- 5.10
-
serverParser
@Deprecated public HttpServerParser serverParser()
Deprecated.Since 5.10, useserverRequestParser()
andserverResponseParser()
-
clientSampler
@Deprecated public HttpSampler clientSampler()
Deprecated.Since 5.8, useclientRequestSampler()
-
clientRequestSampler
public brave.sampler.SamplerFunction<HttpRequest> clientRequestSampler()
Returns an overriding sampling decision for a new trace. Defaults to ignore the request and use thetrace ID instead
.This decision happens when a trace was not yet started in process. For example, you may be making an http request as a part of booting your application. You may want to opt-out of tracing client requests that did not originate from a server request.
- Since:
- 5.8
- See Also:
SamplerFunctions
-
serverSampler
@Deprecated public HttpSampler serverSampler()
Deprecated.Since 5.8, useserverRequestSampler()
-
serverRequestSampler
public brave.sampler.SamplerFunction<HttpRequest> serverRequestSampler()
Returns an overriding sampling decision for a new trace. Defaults to ignore the request and use thetrace ID instead
.This decision happens when trace IDs were not in headers, or a sampling decision has not yet been made. For example, if a trace is already in progress, this function is not called. You can implement this to skip paths that you never want to trace.
- Since:
- 5.8
- See Also:
SamplerFunctions
-
propagation
public brave.propagation.Propagation<String> propagation()
Returns the propagation component used by HTTP instrumentation.Typically, this is the same as
Tracing.propagation()
. Overrides will apply to all HTTP instrumentation in use. For example, Servlet and also OkHttp. If only trying to change B3 related headers, use the more efficientB3Propagation.FactoryBuilder.injectFormat(Span.Kind, B3Propagation.Format)
instead.Use caution when overriding
If overriding this viaHttpTracing.Builder.propagation(Propagation)
, take care to also delegate toTracing.propagation()
. Otherwise, you can break features something else may have set, such asBaggagePropagation
.Library-specific formats
HTTP instrumentation can localize propagation changes by callingtoBuilder()
, thenHttpTracing.Builder.propagation(Propagation)
. This allows library-specific formats.For example, cloud SDKs often use HTTP (or REST) APIs for communication. These endpoints may hemselves be traceable, in a cloud-specific or otherwise different format than what general applications use. SDK instrumentation can override the propagation component to solely use their format, and drop any
baggage
.- Since:
- 5.13
- See Also:
Tracing.propagation()
-
toBuilder
public HttpTracing.Builder toBuilder()
-
current
@Nullable public static HttpTracing current()
Returns the most recently created tracing component iff it hasn't been closed. null otherwise.This object should not be cached.
- Since:
- 5.9
-
-