Class OcHttpServletUtil

java.lang.Object
org.nuxeo.ecm.platform.web.common.tracing.OcHttpServletUtil

public class OcHttpServletUtil extends Object
Implementation Note:
Copied from io.opencensus:opencensus-contrib-http-servlet to make it Jakarta compatible
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.opencensus.common.Scope
    withScope(jakarta.servlet.ServletRequest request)
    Enters the scope of code where the given ServletRequest will be processed and returns an object that represents the scope.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • withScope

      @MustBeClosed public static io.opencensus.common.Scope withScope(jakarta.servlet.ServletRequest request)
      Enters the scope of code where the given ServletRequest 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 the ServletRequest 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 - The ServletRequest 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:
      NullPointerException - if request is null.
      Since:
      0.20.0