Class HttpServerTracer<REQUEST,RESPONSE,CONNECTION,STORAGE>
- java.lang.Object
-
- io.opentelemetry.instrumentation.api.tracer.BaseTracer
-
- io.opentelemetry.instrumentation.api.tracer.HttpServerTracer<REQUEST,RESPONSE,CONNECTION,STORAGE>
-
- Type Parameters:
REQUEST- - The specific type for HTTP requestsRESPONSE- - The specific type for HTTP responsesCONNECTION- - The specific type of HTTP connection, used to get peer address information and HTTP flavor.STORAGE- - Implementation specific storage type for attaching/getting the server context. Use Void if your subclass does not have an implementation specific storage need.
public abstract class HttpServerTracer<REQUEST,RESPONSE,CONNECTION,STORAGE> extends BaseTracer
Base class for implementing Tracers for HTTP servers. It has 3 types that must be specified by subclasses:
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONTEXT_ATTRIBUTEprotected static StringUSER_AGENT
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpServerTracer()protectedHttpServerTracer(io.opentelemetry.api.OpenTelemetry openTelemetry)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidattachServerContext(io.opentelemetry.context.Context context, STORAGE storage)Stores given context in the given request-response-loop storage in implementation specific way.protected io.opentelemetry.context.ContextcustomizeContext(io.opentelemetry.context.Context context, REQUEST request)Override in subclass to customize context that is returned bystartSpan.voidend(io.opentelemetry.context.Context context, RESPONSE response)Convenience method.voidend(io.opentelemetry.context.Context context, RESPONSE response, long timestamp)voidendExceptionally(io.opentelemetry.context.Context context, Throwable throwable)Convenience method.voidendExceptionally(io.opentelemetry.context.Context context, Throwable throwable, RESPONSE response)Convenience method.voidendExceptionally(io.opentelemetry.context.Context context, Throwable throwable, RESPONSE response, long timestamp)Ifresponseisnull, thehttp.status_codewill be set to500and theSpanstatus will be set toStatusCode.ERROR.protected abstract Stringflavor(CONNECTION connection, REQUEST request)protected abstract io.opentelemetry.context.propagation.TextMapGetter<REQUEST>getGetter()abstract @Nullable io.opentelemetry.context.ContextgetServerContext(STORAGE storage)Returns context stored to the given request-response-loop storage byattachServerContext(Context, Object).io.opentelemetry.api.trace.SpangetServerSpan(STORAGE storage)protected booleanisRelativeUrl(String url)protected abstract Stringmethod(REQUEST request)protected voidonConnection(io.opentelemetry.api.trace.SpanBuilder spanBuilder, CONNECTION connection)protected voidonConnectionAndRequest(io.opentelemetry.api.trace.SpanBuilder spanBuilder, CONNECTION connection, REQUEST request)protected voidonRequest(io.opentelemetry.api.trace.SpanBuilder spanBuilder, REQUEST request)protected abstract @Nullable StringpeerHostIp(CONNECTION connection)protected abstract @Nullable IntegerpeerPort(CONNECTION connection)protected abstract @Nullable StringrequestHeader(REQUEST request, String name)protected abstract intresponseStatus(RESPONSE response)io.opentelemetry.context.ContextstartSpan(REQUEST request, CONNECTION connection, @Nullable STORAGE storage, String spanName, long startTimestamp)io.opentelemetry.context.ContextstartSpan(REQUEST request, CONNECTION connection, STORAGE storage, Method origin)io.opentelemetry.context.ContextstartSpan(REQUEST request, CONNECTION connection, STORAGE storage, String spanName)protected abstract Stringurl(REQUEST request)-
Methods inherited from class io.opentelemetry.instrumentation.api.tracer.BaseTracer
end, end, endExceptionally, extract, getInstrumentationName, getVersion, inject, onException, shouldStartSpan, spanBuilder, startSpan, startSpan, startSpan, unwrapThrowable, withClientSpan, withConsumerSpan, withServerSpan
-
-
-
-
Field Detail
-
CONTEXT_ATTRIBUTE
public static final String CONTEXT_ATTRIBUTE
-
USER_AGENT
protected static final String USER_AGENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
startSpan
public io.opentelemetry.context.Context startSpan(REQUEST request, CONNECTION connection, STORAGE storage, Method origin)
-
startSpan
public io.opentelemetry.context.Context startSpan(REQUEST request, CONNECTION connection, STORAGE storage, String spanName)
-
startSpan
public io.opentelemetry.context.Context startSpan(REQUEST request, CONNECTION connection, @Nullable STORAGE storage, String spanName, long startTimestamp)
-
customizeContext
protected io.opentelemetry.context.Context customizeContext(io.opentelemetry.context.Context context, REQUEST request)Override in subclass to customize context that is returned bystartSpan.
-
end
public void end(io.opentelemetry.context.Context context, RESPONSE response)
-
end
public void end(io.opentelemetry.context.Context context, RESPONSE response, long timestamp)
-
endExceptionally
public void endExceptionally(io.opentelemetry.context.Context context, Throwable throwable)Convenience method. Delegates toendExceptionally(Context, Throwable, Object), passingresponsevalue ofnull.- Overrides:
endExceptionallyin classBaseTracer- See Also:
BaseTracer.onException(Context, Throwable),BaseTracer.end(Context)
-
endExceptionally
public void endExceptionally(io.opentelemetry.context.Context context, Throwable throwable, RESPONSE response)Convenience method. Delegates toendExceptionally(Context, Throwable, Object, long), passingtimestampvalue of-1.
-
endExceptionally
public void endExceptionally(io.opentelemetry.context.Context context, Throwable throwable, RESPONSE response, long timestamp)Ifresponseisnull, thehttp.status_codewill be set to500and theSpanstatus will be set toStatusCode.ERROR.
-
getServerSpan
public io.opentelemetry.api.trace.Span getServerSpan(STORAGE storage)
-
getServerContext
public abstract @Nullable io.opentelemetry.context.Context getServerContext(STORAGE storage)
Returns context stored to the given request-response-loop storage byattachServerContext(Context, Object).
-
onConnection
protected void onConnection(io.opentelemetry.api.trace.SpanBuilder spanBuilder, CONNECTION connection)
-
onRequest
protected void onRequest(io.opentelemetry.api.trace.SpanBuilder spanBuilder, REQUEST request)
-
onConnectionAndRequest
protected void onConnectionAndRequest(io.opentelemetry.api.trace.SpanBuilder spanBuilder, CONNECTION connection, REQUEST request)
-
peerPort
protected abstract @Nullable Integer peerPort(CONNECTION connection)
-
peerHostIp
protected abstract @Nullable String peerHostIp(CONNECTION connection)
-
flavor
protected abstract String flavor(CONNECTION connection, REQUEST request)
-
getGetter
protected abstract io.opentelemetry.context.propagation.TextMapGetter<REQUEST> getGetter()
-
responseStatus
protected abstract int responseStatus(RESPONSE response)
-
attachServerContext
protected abstract void attachServerContext(io.opentelemetry.context.Context context, STORAGE storage)Stores given context in the given request-response-loop storage in implementation specific way.
-
isRelativeUrl
protected boolean isRelativeUrl(String url)
-
-