Class HttpClientHandler<Q,P,C>
java.lang.Object
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.
This helper class provides routine methods to instrument HTTP clients.
- Since:
- 0.19
-
Constructor Summary
ConstructorsConstructorDescriptionHttpClientHandler(Tracer tracer, HttpExtractor<Q, P> extractor, TextFormat textFormat, TextFormat.Setter<C> setter) Creates aHttpClientHandlerwith given parameters. -
Method Summary
Modifier and TypeMethodDescriptiongetSpanFromContext(HttpRequestContext context) RetrievesSpanfrom theHttpRequestContext.voidhandleEnd(HttpRequestContext context, Q request, P response, Throwable error) Close an HTTP span and records stats specific to the request.final voidhandleMessageReceived(HttpRequestContext context, long bytes) Instrument an HTTP span after a message is received.final voidhandleMessageSent(HttpRequestContext context, long bytes) Instrument an HTTP span after a message is sent.handleStart(Span parent, C carrier, Q request) Instrument a request for tracing and stats before it is sent.
-
Constructor Details
-
HttpClientHandler
public HttpClientHandler(Tracer tracer, HttpExtractor<Q, P> extractor, TextFormat textFormat, TextFormat.Setter<C> setter) Creates aHttpClientHandlerwith given parameters.- Parameters:
tracer- the Open Census tracing component.extractor- theHttpExtractorused to extract information from the request/response.textFormat- theTextFormatused in HTTP propagation.setter- the setter used when injecting information to thecarrier.- Since:
- 0.19
-
-
Method Details
-
handleStart
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(HttpRequestContext)to retrieve the span.- Parameters:
parent- the parentSpan.nullindicates using current span.carrier- the entity that holds the HTTP information.request- the request entity.- Returns:
- the
HttpRequestContextthat 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 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- theHttpRequestContextreturned fromhandleStart(Span, Object, Object)request- the HTTP request entity.response- the HTTP response entity.nullmeans invalid response.error- the error occurs when processing the response.- Since:
- 0.19
-
handleMessageSent
Instrument an HTTP span after a message is sent. Typically called for every chunk of request or response is sent.- Parameters:
context- request specificHttpRequestContextbytes- bytes sent.- Since:
- 0.19
-
handleMessageReceived
Instrument an HTTP span after a message is received. Typically called for every chunk of request or response is received.- Parameters:
context- request specificHttpRequestContextbytes- bytes received.- Since:
- 0.19
-
getSpanFromContext
RetrievesSpanfrom theHttpRequestContext.- Parameters:
context- request specificHttpRequestContext- Returns:
Spanassociated with the request.- Since:
- 0.19
-