Package io.opencensus.contrib.http
Class HttpServerHandler<Q,P,C>
java.lang.Object
io.opencensus.contrib.http.AbstractHttpHandler<Q,P>
io.opencensus.contrib.http.HttpServerHandler<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 servers.
- Since:
- 0.19
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TextFormat.Getter
<C> private final Boolean
private final StatsRecorder
private final Tagger
private final TextFormat
private final Tracer
Fields inherited from class io.opencensus.contrib.http.AbstractHttpHandler
extractor
-
Constructor Summary
ConstructorsConstructorDescriptionHttpServerHandler
(Tracer tracer, HttpExtractor<Q, P> extractor, TextFormat textFormat, TextFormat.Getter<C> getter, Boolean publicEndpoint) Creates aHttpServerHandler
with given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
handleEnd
(HttpRequestContext context, Q request, P response, Throwable error) Close an HTTP span and records stats specific to the request.handleStart
(C carrier, Q request) Instrument an incoming request before it is handled.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 Details
-
getter
-
textFormat
-
tracer
-
publicEndpoint
-
statsRecorder
-
tagger
-
-
Constructor Details
-
HttpServerHandler
public HttpServerHandler(Tracer tracer, HttpExtractor<Q, P> extractor, TextFormat textFormat, TextFormat.Getter<C> getter, Boolean publicEndpoint) Creates aHttpServerHandler
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.getter
- the getter used when extracting information from thecarrier
.publicEndpoint
- set to true for publicly accessible HTTP(S) server. If true then incoming tracecontext will be added as a link instead of as a parent.- Since:
- 0.19
-
-
Method Details
-
handleStart
Instrument an incoming request before it is handled.This method will create a span under the deserialized propagated parent context. If the parent context is not present, the span will be created under the current context.
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:
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, 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 message events for the span and record measurements associated with the request.
- Parameters:
context
- theHttpRequestContext
used withhandleStart(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
-