Class AsyncOperationEndSupport<REQUEST,​RESPONSE>


  • public final class AsyncOperationEndSupport<REQUEST,​RESPONSE>
    extends Object
    A wrapper over Instrumenter that is able to defer Instrumenter.end(Context, Object, Object, Throwable) until asynchronous computation finishes.
    • Method Detail

      • create

        public static <REQUEST,​RESPONSE> AsyncOperationEndSupport<REQUEST,​RESPONSE> create​(io.opentelemetry.instrumentation.api.instrumenter.Instrumenter<REQUEST,​RESPONSE> syncInstrumenter,
                                                                                                       Class<RESPONSE> responseType,
                                                                                                       Class<?> asyncType)
        Returns a new AsyncOperationEndSupport that wraps over passed syncInstrumenter, configured for usage with asynchronous computations that are instances of asyncType. If the result of the async computation ends up being an instance of responseType it will be passed as the response to the syncInstrumenter call; otherwise null value will be used as the response.
      • asyncEnd

        @Nullable
        public <ASYNC> ASYNC asyncEnd​(io.opentelemetry.context.Context context,
                                      REQUEST request,
                                      @Nullable
                                      ASYNC asyncValue,
                                      @Nullable
                                      Throwable throwable)
        Attempts to compose over passed asyncValue and delay the Instrumenter.end(Context, Object, Object, Throwable) call until the async operation completes.

        This method will end the operation immediately if throwable is passed, if there is no AsyncOperationEndStrategy for the asyncType used, or if there is a type mismatch between passed asyncValue and the asyncType that was used to create this object.

        If the passed asyncValue is recognized as an asynchronous computation, the operation won't be ended until asyncValue completes.

      • tryToGetResponse

        @Nullable
        public static <RESPONSE> RESPONSE tryToGetResponse​(Class<RESPONSE> responseType,
                                                           @Nullable
                                                           Object asyncValue)