Class OcHttpServletUtil
- java.lang.Object
-
- io.opencensus.contrib.http.servlet.OcHttpServletUtil
-
public class OcHttpServletUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
CONTENT_LENGTH
(package private) static java.lang.String
OPENCENSUS_SERVLET_LISTENER
-
Constructor Summary
Constructors Modifier Constructor Description private
OcHttpServletUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static void
recordMessageSentEvent(HttpServerHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,javax.servlet.http.HttpServletRequest> handler, HttpRequestContext context, javax.servlet.http.HttpServletResponse response)
static Scope
withScope(javax.servlet.ServletRequest request)
Enters the scope of code where the givenServletRequest
will be processed and returns an object that represents the scope.
-
-
-
Field Detail
-
CONTENT_LENGTH
static final java.lang.String CONTENT_LENGTH
- See Also:
- Constant Field Values
-
OPENCENSUS_SERVLET_LISTENER
static final java.lang.String OPENCENSUS_SERVLET_LISTENER
- See Also:
- Constant Field Values
-
-
Method Detail
-
recordMessageSentEvent
static void recordMessageSentEvent(HttpServerHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,javax.servlet.http.HttpServletRequest> handler, HttpRequestContext context, javax.servlet.http.HttpServletResponse response)
-
withScope
@MustBeClosed public static Scope withScope(javax.servlet.ServletRequest request)
Enters the scope of code where the givenServletRequest
will be processed and returns an object that represents the scope. The scope is exited when the returned object is closed. A span created for theServletRequest
is set to the current Context.Supports try-with-resource idiom.
Example of usage:
void AsyncRequestProcessor(AsyncContext asyncCtx) { try (Scope ws = OcHttpServletUtil.withScope(asyncCtx.getRequest) { tracer.getCurrentSpan().addAnnotation("my annotation"); doSomeOtherWork(); // Here "span" is the current Span. } }
Prior to Java SE 7, you can use a finally block to ensure that a resource is closed regardless of whether the try statement completes normally or abruptly.
Example of usage prior to Java SE7:
void AsyncRequestProcessor(AsyncContext asyncCtx) { Scope ws = OcHttpServletUtil.withScope(asyncCtx.getRequest) try { tracer.getCurrentSpan().addAnnotation("my annotation"); doSomeOtherWork(); // Here "span" is the current Span. } finally { ws.close(); } }
- Parameters:
request
- TheServletRequest
request that is about to be processed.- Returns:
- an object that defines a scope where the span associated with the given
ServletRequest
will be set to the current Context. - Throws:
java.lang.NullPointerException
- ifrequest
isnull
.- Since:
- 0.20.0
-
-