/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public RunnableWithTracingAndMdcSupport(Runnable origRunnable, ChannelHandlerContext ctx) { this(origRunnable, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public RunnableWithTracingAndMdcSupport(Runnable origRunnable, ChannelHandlerContext ctx) { this(origRunnable, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Constructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public BiConsumerWithTracingAndMdcSupport(BiConsumer<T, U> origBiConsumer, ChannelHandlerContext ctx) { this(origBiConsumer, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public ConsumerWithTracingAndMdcSupport(Consumer<T> origConsumer, ChannelHandlerContext ctx) { this(origConsumer, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public BiFunctionWithTracingAndMdcSupport(BiFunction<T, U, R> origBiFunction, ChannelHandlerContext ctx) { this(origBiFunction, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public ConsumerWithTracingAndMdcSupport(Consumer<T> origConsumer, ChannelHandlerContext ctx) { this(origConsumer, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public BiFunctionWithTracingAndMdcSupport(BiFunction<T, U, R> origBiFunction, ChannelHandlerContext ctx) { this(origBiFunction, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public CallableWithTracingAndMdcSupport(Callable<U> origCallable, ChannelHandlerContext ctx) { this(origCallable, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public FunctionWithTracingAndMdcSupport(Function<T, U> origFunction, ChannelHandlerContext ctx) { this(origFunction, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public SupplierWithTracingAndMdcSupport(Supplier<U> origSupplier, ChannelHandlerContext ctx) { this(origSupplier, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public CallableWithTracingAndMdcSupport(Callable<U> origCallable, ChannelHandlerContext ctx) { this(origCallable, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Constructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public BiConsumerWithTracingAndMdcSupport(BiConsumer<T, U> origBiConsumer, ChannelHandlerContext ctx) { this(origBiConsumer, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public FunctionWithTracingAndMdcSupport(Function<T, U> origFunction, ChannelHandlerContext ctx) { this(origFunction, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public SupplierWithTracingAndMdcSupport(Supplier<U> origSupplier, ChannelHandlerContext ctx) { this(origSupplier, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
/** * Contructor that extracts the trace and MDC info from the given {@link ChannelHandlerContext}'s {@link * com.nike.riposte.server.http.HttpProcessingState} so that it can be associated with the thread when the given * operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link ChannelHandlerContext} can be null (or the state inside can be null) but if you pass null it means * there won't be any trace or MDC info associated with the thread when the given operation is executed. */ public ChannelFutureListenerWithTracingAndMdc(Consumer<ChannelFuture> postCompleteOperation, ChannelHandlerContext ctx) { this(postCompleteOperation, AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx)); }
@SuppressWarnings("SameParameterValue") protected void logErrorWithTracing(String msg, Throwable ex, ChannelHandlerContext ctx) { Pair<Deque<Span>, Map<String, String>> tracingState = AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx); Deque<Span> distributedTraceStackToLink = null; Map<String, String> mdcContextMapToLink = null; if (tracingState != null) { distributedTraceStackToLink = tracingState.getLeft(); mdcContextMapToLink = tracingState.getRight(); } logErrorWithTracing(msg, ex, distributedTraceStackToLink, mdcContextMapToLink); }
@SuppressWarnings("SameParameterValue") protected void logErrorWithTracing(String msg, Throwable ex, ChannelHandlerContext ctx) { Pair<Deque<Span>, Map<String, String>> tracingState = AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx); Deque<Span> distributedTraceStackToLink = null; Map<String, String> mdcContextMapToLink = null; if (tracingState != null) { distributedTraceStackToLink = tracingState.getLeft(); mdcContextMapToLink = tracingState.getRight(); } logErrorWithTracing(msg, ex, distributedTraceStackToLink, mdcContextMapToLink); }
@Test public void extractTracingAndMdcInfoFromChannelHandlerContext_returns_null_if_state_is_null() { // given doReturn(null).when(stateAttributeMock).get(); // expect assertThat(AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctxMock)).isNull(); }
@Test public void extractTracingAndMdcInfoFromChannelHandlerContext_does_what_it_says_it_does() { // given Pair<Deque<Span>, Map<String, String>> expected = setupStateWithTracingAndMdcInfo(); // when Pair<Deque<Span>, Map<String, String>> result = AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctxMock); // then assertThat(result).isEqualTo(expected); }
@Test public void extractTracingAndMdcInfoFromChannelHandlerContext_returns_null_if_passed_null() { // expect assertThat(AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(null)).isNull(); }