Package io.opencensus.contrib.http
Class HttpClientHandler<Q,P,C>
- java.lang.Object
-
- io.opencensus.contrib.http.AbstractHttpHandler<Q,P>
-
- io.opencensus.contrib.http.HttpClientHandler<Q,P,C>
-
- Type Parameters:
Q
- the HTTP request entity.P
- the HTTP response entity.C
- the type of the carrier.
@ExperimentalApi public class HttpClientHandler<Q,P,C> extends AbstractHttpHandler<Q,P>
This helper class provides routine methods to instrument HTTP clients.- Since:
- 0.19
-
-
Field Summary
Fields Modifier and Type Field Description private TextFormat.Setter<C>
setter
private StatsRecorder
statsRecorder
private Tagger
tagger
private TextFormat
textFormat
private Tracer
tracer
-
Fields inherited from class io.opencensus.contrib.http.AbstractHttpHandler
extractor
-
-
Constructor Summary
Constructors Constructor Description HttpClientHandler(Tracer tracer, HttpExtractor<Q,P> extractor, TextFormat textFormat, TextFormat.Setter<C> setter)
Creates aHttpClientHandler
with given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handleEnd(HttpRequestContext context, Q request, P response, java.lang.Throwable error)
Close an HTTP span and records stats specific to the request.HttpRequestContext
handleStart(Span parent, C carrier, Q request)
Instrument a request for tracing and stats before it is sent.private void
recordStats(HttpRequestContext context, Q request, int httpCode)
-
Methods inherited from class io.opencensus.contrib.http.AbstractHttpHandler
addSpanRequestAttributes, getNewContext, getSpanFromContext, getSpanName, handleMessageReceived, handleMessageSent, recordMessageEvent, spanEnd
-
-
-
-
Field Detail
-
setter
private final TextFormat.Setter<C> setter
-
textFormat
private final TextFormat textFormat
-
tracer
private final Tracer tracer
-
statsRecorder
private final StatsRecorder statsRecorder
-
tagger
private final Tagger tagger
-
-
Constructor Detail
-
HttpClientHandler
public HttpClientHandler(Tracer tracer, HttpExtractor<Q,P> extractor, TextFormat textFormat, TextFormat.Setter<C> setter)
Creates aHttpClientHandler
with given parameters.- Parameters:
tracer
- the Open Census tracing component.extractor
- theHttpExtractor
used to extract information from the request/response.textFormat
- theTextFormat
used in HTTP propagation.setter
- the setter used when injecting information to thecarrier
.- Since:
- 0.19
-
-
Method Detail
-
handleStart
public HttpRequestContext handleStart(@Nullable Span parent, C carrier, Q request)
Instrument a request for tracing and stats before it is sent.This method will create a span in current context to represent the HTTP call. The created span will be serialized and propagated to the server.
The generated span will NOT be set as current context. User can control when to enter the scope of this span. Use
AbstractHttpHandler.getSpanFromContext(io.opencensus.contrib.http.HttpRequestContext)
to retrieve the span.- Parameters:
parent
- the parentSpan
.null
indicates using current span.carrier
- the entity that holds the HTTP information.request
- the request entity.- Returns:
- the
HttpRequestContext
that contains stats and trace data associated with the request. - Since:
- 0.19
-
handleEnd
public void handleEnd(HttpRequestContext context, @Nullable Q request, @Nullable P response, @Nullable java.lang.Throwable error)
Close an HTTP span and records stats specific to the request.This method will set status of the span and end it. Additionally it will record measurements associated with the request.
- Parameters:
context
- theHttpRequestContext
returned fromhandleStart(Span, Object, Object)
request
- the HTTP request entity.response
- the HTTP response entity.null
means invalid response.error
- the error occurs when processing the response.- Since:
- 0.19
-
recordStats
private void recordStats(HttpRequestContext context, @Nullable Q request, int httpCode)
-
-