Class InstrumentationHelper

java.lang.Object
com.vaadin.extension.InstrumentationHelper

public class InstrumentationHelper extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final io.opentelemetry.instrumentation.api.instrumenter.Instrumenter<InstrumentationRequest,Void>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Determines whether a higher-level instrumentation, for example a servlet or application server instrumentation, has already created a root server span.
    static void
    endRootSpan(jakarta.servlet.http.HttpServletResponse servletResponse, io.opentelemetry.context.Context context, Throwable throwable)
    Ends the root span from the specified context.
    static void
    endSpan(io.opentelemetry.api.trace.Span span, Throwable throwable, io.opentelemetry.context.Scope scope)
    Ends the provided span.
    static io.opentelemetry.context.Context
    enhanceRootSpan(jakarta.servlet.http.HttpServletRequest servletRequest, io.opentelemetry.context.Context context)
    Enhances the root span with data from a servlet request adds additional data to the context, like session ID.
    getActiveRouteTemplate(com.vaadin.flow.component.UI ui)
    Get the route template for the currently active view.
    static String
    getRequestFilename(jakarta.servlet.http.HttpServletRequest request)
    Get the file name from the HTTP request.
    Get the route template for the provided location
    static io.opentelemetry.api.trace.Tracer
     
    static void
    handleException(io.opentelemetry.api.trace.Span span, Throwable throwable)
     
    static boolean
    isRequestType(jakarta.servlet.http.HttpServletRequest servletRequest, String requestType)
     
    static io.opentelemetry.context.Context
    startRootSpan(jakarta.servlet.http.HttpServletRequest servletRequest)
    Creates a server root span from the HTTP servlet request, and returns a context containing the created span
    static io.opentelemetry.api.trace.Span
    startSpan(String spanName)
    Creates and starts a new span with the provided name.
    static io.opentelemetry.api.trace.Span
    startSpan(String spanName, Instant startTimestamp)
    Creates and starts a new span with the provided name, at the provided start timestamp.
    static void
    updateHttpRoute(com.vaadin.flow.component.UI ui)
     

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • InstrumentationHelper

      public InstrumentationHelper()
  • Method Details

    • getTracer

      public static io.opentelemetry.api.trace.Tracer getTracer()
    • startSpan

      public static io.opentelemetry.api.trace.Span startSpan(String spanName)
      Creates and starts a new span with the provided name. Also adds common attributes provided by Vaadin contexts.
      Parameters:
      spanName - the name of the span
      Returns:
      the new span
    • startSpan

      public static io.opentelemetry.api.trace.Span startSpan(String spanName, Instant startTimestamp)
      Creates and starts a new span with the provided name, at the provided start timestamp. Also adds common attributes provided by Vaadin contexts.
      Parameters:
      spanName - the name of the span
      startTimestamp - the start timestamp of the span
      Returns:
      the new span
    • endSpan

      public static void endSpan(io.opentelemetry.api.trace.Span span, Throwable throwable, io.opentelemetry.context.Scope scope)
      Ends the provided span. If throwable is not null, then the error message and stacktrace will be added to the span, and the span status is set to StatusCode.ERROR. If a scope is provided, then the scope will be closed as well.
      Parameters:
      span - the span to end
      throwable - the throwable to record, or null
      scope - the scope to close, or null
    • startRootSpan

      public static io.opentelemetry.context.Context startRootSpan(jakarta.servlet.http.HttpServletRequest servletRequest)
      Creates a server root span from the HTTP servlet request, and returns a context containing the created span
      Parameters:
      servletRequest - the servlet request
      Returns:
      the context that was created
    • endRootSpan

      public static void endRootSpan(jakarta.servlet.http.HttpServletResponse servletResponse, io.opentelemetry.context.Context context, Throwable throwable)
      Ends the root span from the specified context.
      Parameters:
      servletResponse - the response for the current server root span
      context - the context that contains the root span
      throwable - the throwable to record, or null
    • enhanceRootSpan

      public static io.opentelemetry.context.Context enhanceRootSpan(jakarta.servlet.http.HttpServletRequest servletRequest, io.opentelemetry.context.Context context)
      Enhances the root span with data from a servlet request adds additional data to the context, like session ID.
      Parameters:
      servletRequest - the request
      Returns:
      the created context
    • checkRootSpan

      public static boolean checkRootSpan()
      Determines whether a higher-level instrumentation, for example a servlet or application server instrumentation, has already created a root server span.
      Returns:
      whether a server root span already exists
    • updateHttpRoute

      public static void updateHttpRoute(com.vaadin.flow.component.UI ui)
    • getActiveRouteTemplate

      public static Optional<String> getActiveRouteTemplate(com.vaadin.flow.component.UI ui)
      Get the route template for the currently active view.
      Parameters:
      ui - Current UI to get active view path for.
      Returns:
      view template if available, else Optional.empty()
    • getRouteTemplateForLocation

      public static Optional<String> getRouteTemplateForLocation(String location)
      Get the route template for the provided location
      Parameters:
      location - the location for which to get the route
      Returns:
      view template if available, else Optional.empty()
    • handleException

      public static void handleException(io.opentelemetry.api.trace.Span span, Throwable throwable)
    • getRequestFilename

      public static String getRequestFilename(jakarta.servlet.http.HttpServletRequest request)
      Get the file name from the HTTP request.
      Parameters:
      request - http request to get file name from
      Returns:
      file name
    • isRequestType

      public static boolean isRequestType(jakarta.servlet.http.HttpServletRequest servletRequest, String requestType)