@Test public void doChannelRead_does_not_propagate_exception_if_startTrace_throws_an_error() { // given DTraceStartHandler handlerSpy = spy(handler); doThrow(new RuntimeException("intentional exception")).when(handlerSpy).startTrace(any(), any()); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, httpRequest); // then verify(handlerSpy).startTrace(any(), any()); assertThat(result, is(PipelineContinuationBehavior.CONTINUE)); }
@Test public void doChannelRead_does_not_call_startTrace_if_msg_is_not_HttpRequest_but_it_does_return_CONTINUE() throws Exception { // given DTraceStartHandler handlerSpy = spy(handler); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, new Object()); // then verify(handlerSpy, times(0)).startTrace(any(), any()); assertThat(result, is(PipelineContinuationBehavior.CONTINUE)); }
@Test public void doChannelRead_calls_startTrace_if_msg_is_HttpRequest_and_then_returns_CONTINUE() throws Exception { // given DTraceStartHandler handlerSpy = spy(handler); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, httpRequest); // then verify(handlerSpy).startTrace(httpRequest, ctxMock); assertThat(result, is(PipelineContinuationBehavior.CONTINUE)); }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) { // We may get multiple messages for a single HTTP request since riposte handles each individual HTTP message // object (including individual payload content messages). // We only do the processing for HttpRequest which is the first message in a request chain. if (shouldHandleDoChannelReadMessage(msg)) { try { startTrace((HttpRequest) msg, ctx); } catch (Throwable t) { logger.error( "An unexpected error occurred while starting the distributed tracing overall request span. This " + "exception will be swallowed to avoid breaking the Netty pipeline, but it should be " + "investigated as it shouldn't ever happen.", t ); } } if (msg instanceof LastHttpContent) { HttpProcessingState httpProcessingState = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get(); // Add the "we received the last bytes of the request on the wire" annotation to the span if possible // and desired. Span requestSpan = handlerUtils.getOverallRequestSpan(httpProcessingState); if (requestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireReceiveFinishAnnotation()) { requestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireReceiveFinishAnnotationName() ); } } return PipelineContinuationBehavior.CONTINUE; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) { // We may get multiple messages for a single HTTP request since riposte handles each individual HTTP message // object (including individual payload content messages). // We only do the processing for HttpRequest which is the first message in a request chain. if (shouldHandleDoChannelReadMessage(msg)) { try { startTrace((HttpRequest) msg, ctx); } catch (Throwable t) { logger.error( "An unexpected error occurred while starting the distributed tracing overall request span. This " + "exception will be swallowed to avoid breaking the Netty pipeline, but it should be " + "investigated as it shouldn't ever happen.", t ); } } if (msg instanceof LastHttpContent) { HttpProcessingState httpProcessingState = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get(); // Add the "we received the last bytes of the request on the wire" annotation to the span if possible // and desired. Span requestSpan = handlerUtils.getOverallRequestSpan(httpProcessingState); if (requestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireReceiveFinishAnnotation()) { requestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireReceiveFinishAnnotationName() ); } } return PipelineContinuationBehavior.CONTINUE; }
handler.startTrace(httpRequest, ctxMock); long nanosAfter = System.nanoTime();
handlerSpy.startTrace(httpRequest, ctxMock); long nanosAfter = System.nanoTime();