Class ServerRequestObservationContext

java.lang.Object
io.micrometer.observation.Observation.Context
io.micrometer.observation.transport.ReceiverContext<C>
io.micrometer.observation.transport.RequestReplyReceiverContext<ServerHttpRequest,ServerHttpResponse>
org.springframework.http.server.reactive.observation.ServerRequestObservationContext
All Implemented Interfaces:
io.micrometer.observation.Observation.ContextView, io.micrometer.observation.transport.ResponseContext<ServerHttpResponse>

public class ServerRequestObservationContext extends io.micrometer.observation.transport.RequestReplyReceiverContext<ServerHttpRequest,ServerHttpResponse>
Context that holds information for metadata collection regarding reactive HTTP requests observations.

This context also extends RequestReplyReceiverContext for propagating tracing information during HTTP request processing.

Since:
6.0
Author:
Brian Clozel
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the request attribute holding the context for the current observation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new ServerRequestObservationContext instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the current observation context from the given attributes, if available.
    Return an immutable map of the current request attributes.
    Return the path pattern for the handler that matches the current request.
    boolean
    Whether the current connection was aborted by the client, resulting in a cancel signal on the reactive chain, or an AbortedException when reading the request.
    void
    setConnectionAborted(boolean connectionAborted)
    Set whether the current connection was aborted by the client, resulting in a cancel signal on the reactive chain, or an AbortedException when reading the request.
    void
    setPathPattern(String pathPattern)
    Set the path pattern for the handler that matches the current request.

    Methods inherited from class io.micrometer.observation.transport.RequestReplyReceiverContext

    getResponse, setResponse

    Methods inherited from class io.micrometer.observation.transport.ReceiverContext

    getCarrier, getGetter, getKind, getRemoteServiceAddress, getRemoteServiceName, setCarrier, setRemoteServiceAddress, setRemoteServiceName

    Methods inherited from class io.micrometer.observation.Observation.Context

    addHighCardinalityKeyValue, addHighCardinalityKeyValues, addLowCardinalityKeyValue, addLowCardinalityKeyValues, clear, computeIfAbsent, containsKey, get, getAllKeyValues, getContextualName, getError, getHighCardinalityKeyValue, getHighCardinalityKeyValues, getLowCardinalityKeyValue, getLowCardinalityKeyValues, getName, getOrDefault, getParentObservation, getRequired, put, remove, removeHighCardinalityKeyValue, removeHighCardinalityKeyValues, removeLowCardinalityKeyValue, removeLowCardinalityKeyValues, setContextualName, setError, setName, setParentObservation, toString

    Methods inherited from class java.lang.Object

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

    • CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE

      public static final String CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE
      Name of the request attribute holding the context for the current observation.
      Since:
      6.1
  • Constructor Details

    • ServerRequestObservationContext

      public ServerRequestObservationContext(ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> attributes)
      Create a new ServerRequestObservationContext instance.
      Parameters:
      request - the current request
      response - the current response
      attributes - the current attributes
  • Method Details

    • getAttributes

      public Map<String,Object> getAttributes()
      Return an immutable map of the current request attributes.
    • getPathPattern

      @Nullable public String getPathPattern()
      Return the path pattern for the handler that matches the current request. For example, "/projects/{name}".

      Path patterns must have a low cardinality for the entire application.

      Returns:
      the path pattern, or null if none found
    • setPathPattern

      public void setPathPattern(@Nullable String pathPattern)
      Set the path pattern for the handler that matches the current request.

      Path patterns must have a low cardinality for the entire application.

      Parameters:
      pathPattern - the path pattern, for example "/projects/{name}".
    • isConnectionAborted

      public boolean isConnectionAborted()
      Whether the current connection was aborted by the client, resulting in a cancel signal on the reactive chain, or an AbortedException when reading the request.
      Returns:
      if the connection has been aborted
    • setConnectionAborted

      public void setConnectionAborted(boolean connectionAborted)
      Set whether the current connection was aborted by the client, resulting in a cancel signal on the reactive chain, or an AbortedException when reading the request.
      Parameters:
      connectionAborted - if the connection has been aborted
    • findCurrent

      public static Optional<ServerRequestObservationContext> findCurrent(Map<String,Object> attributes)
      Get the current observation context from the given attributes, if available.
      Parameters:
      attributes - the current exchange attributes
      Returns:
      the current observation context
      Since:
      6.1