Class OkHttpContext

java.lang.Object
io.micrometer.observation.Observation.Context
io.micrometer.observation.transport.SenderContext<okhttp3.Request.Builder>
io.micrometer.observation.transport.RequestReplySenderContext<okhttp3.Request.Builder, okhttp3.Response>
io.micrometer.core.instrument.binder.okhttp3.OkHttpContext
All Implemented Interfaces:
io.micrometer.observation.Observation.ContextView, io.micrometer.observation.transport.ResponseContext<okhttp3.Response>, Supplier<OkHttpContext>

public class OkHttpContext extends io.micrometer.observation.transport.RequestReplySenderContext<okhttp3.Request.Builder, okhttp3.Response> implements Supplier<OkHttpContext>
A SenderContext for OkHttp3.
Since:
1.10.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    OkHttpContext(Function<okhttp3.Request, String> urlMapper, Iterable<io.micrometer.common.KeyValue> extraTags, Iterable<BiFunction<okhttp3.Request, @Nullable okhttp3.Response, io.micrometer.common.KeyValue>> contextSpecificTags, boolean includeHostTag, okhttp3.Request request)
     
    OkHttpContext(Function<okhttp3.Request, String> urlMapper, Iterable<io.micrometer.common.KeyValue> extraTags, Iterable<BiFunction<okhttp3.Request, @Nullable okhttp3.Response, io.micrometer.common.KeyValue>> contextSpecificTags, Iterable<io.micrometer.common.KeyValue> ignored, boolean includeHostTag, okhttp3.Request request)
    Deprecated.
    please use other constructor(s).
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
     
    okhttp3.Request.Builder
     
    Iterable<BiFunction<okhttp3.Request, @Nullable okhttp3.Response, io.micrometer.common.KeyValue>>
     
    Iterable<io.micrometer.common.KeyValue>
     
    okhttp3.Request
    Deprecated.
    Deprecated in favor of getRequest().
    okhttp3.Request
     
    Iterable<io.micrometer.common.KeyValue>
    Deprecated.
    The request cannot be null according to the OkHttp API
    Function<okhttp3.Request, String>
     
    boolean
     
    okhttp3.Request
    OkHttpContext being a RequestReplySenderContext means that during context-propagation, the request needs to be modified (extra headers are added).

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

    getResponse, setResponse

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

    getKind, getRemoteServiceAddress, getRemoteServiceName, getSetter, 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 Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface io.micrometer.observation.Observation.ContextView

    getOrDefault
  • Constructor Details

    • OkHttpContext

      public OkHttpContext(Function<okhttp3.Request, String> urlMapper, Iterable<io.micrometer.common.KeyValue> extraTags, Iterable<BiFunction<okhttp3.Request, @Nullable okhttp3.Response, io.micrometer.common.KeyValue>> contextSpecificTags, boolean includeHostTag, okhttp3.Request request)
      Since:
      1.17.0
    • OkHttpContext

      @Deprecated public OkHttpContext(Function<okhttp3.Request, String> urlMapper, Iterable<io.micrometer.common.KeyValue> extraTags, Iterable<BiFunction<okhttp3.Request, @Nullable okhttp3.Response, io.micrometer.common.KeyValue>> contextSpecificTags, Iterable<io.micrometer.common.KeyValue> ignored, boolean includeHostTag, okhttp3.Request request)
      Deprecated.
      please use other constructor(s).
  • Method Details

    • rebuildAndGetRequest

      public okhttp3.Request rebuildAndGetRequest()
      OkHttpContext being a RequestReplySenderContext means that during context-propagation, the request needs to be modified (extra headers are added). Since Request is immutable, OkHttpContext uses its builder as its "carrier" object (the builder is mutable). This means that after the builder mutation happens, the request stays the same unless this method is called which rebuilds the request using the modified builder (enhanced with the extra headers). It's unlikely that you need to call this method multiple times, once the builder was mutated, you can rebuild the request once and use getRequest() subsequently.
      Returns:
      request
      Since:
      1.17.0
    • getUrlMapper

      public Function<okhttp3.Request, String> getUrlMapper()
    • getExtraTags

      public Iterable<io.micrometer.common.KeyValue> getExtraTags()
    • getContextSpecificTags

      public Iterable<BiFunction<okhttp3.Request, @Nullable okhttp3.Response, io.micrometer.common.KeyValue>> getContextSpecificTags()
    • getUnknownRequestTags

      @Deprecated public Iterable<io.micrometer.common.KeyValue> getUnknownRequestTags()
      Deprecated.
      The request cannot be null according to the OkHttp API
    • isIncludeHostTag

      public boolean isIncludeHostTag()
    • getRequest

      public okhttp3.Request getRequest()
      Returns:
      request
      Since:
      1.17.0
    • getOriginalRequest

      @Deprecated public okhttp3.Request getOriginalRequest()
      Deprecated.
      Deprecated in favor of getRequest().
    • get

      public OkHttpContext get()
      Specified by:
      get in interface Supplier<OkHttpContext>
    • getCarrier

      public okhttp3.Request.Builder getCarrier()
      Overrides:
      getCarrier in class io.micrometer.observation.transport.SenderContext<okhttp3.Request.Builder>