protected void addEndpointFinishAnnotation(Span span, ServerSpanNamingAndTaggingStrategy<Span> strategy) { // Don't allow the annotation addition to cause the endpoint execution future to fail if it // fails, by surrounding with try/catch. This should never actually happen, but better // safe than sorry. try { span.addTimestampedAnnotationForCurrentTime( strategy.endpointFinishAnnotationName() ); } catch(Throwable t) { logger.error( "Unexpected error while annotating Span with endpoint finish timestamp.", t ); } }
protected void addEndpointFinishAnnotation(Span span, ServerSpanNamingAndTaggingStrategy<Span> strategy) { // Don't allow the annotation addition to cause the endpoint execution future to fail if it // fails, by surrounding with try/catch. This should never actually happen, but better // safe than sorry. try { span.addTimestampedAnnotationForCurrentTime( strategy.endpointFinishAnnotationName() ); } catch(Throwable t) { logger.error( "Unexpected error while annotating Span with endpoint finish timestamp.", t ); } }
@Test public void default_annotation_method_implementations_return_expected_values() { // given ServerSpanNamingAndTaggingStrategy<?> defaultImpl = new DefaultServerSpanNamingAndTaggingStrategy(); ResponseInfo<?> responseMock = mock(ResponseInfo.class); Throwable errorMock = mock(Throwable.class); // expect assertThat(defaultImpl.shouldAddEndpointStartAnnotation()).isTrue(); assertThat(defaultImpl.endpointStartAnnotationName()).isEqualTo("endpoint.start"); assertThat(defaultImpl.shouldAddEndpointFinishAnnotation()).isTrue(); assertThat(defaultImpl.endpointFinishAnnotationName()).isEqualTo("endpoint.finish"); verifyZeroInteractions(responseMock, errorMock); }
@Test public void doChannelRead_does_not_propagate_errors_if_unexpected_exceptions_occur_during_endpoint_timing_annotations() { // given Span spanMock = mock(Span.class); Tracer.getInstance().registerWithThread(new ArrayDeque<>(Collections.singleton(spanMock))); assertThat(Tracer.getInstance().getCurrentSpan()).isEqualTo(spanMock); TracingState tracingStateForTest = TracingState.getCurrentThreadTracingState(); doReturn(tracingStateForTest.getLeft()).when(stateMock).getDistributedTraceStack(); doReturn(tracingStateForTest.getRight()).when(stateMock).getLoggerMdcContextMap(); doReturn(true).when(taggingStrategySpy).shouldAddEndpointStartAnnotation(); doThrow(new RuntimeException("intentional exception")).when(taggingStrategySpy).endpointStartAnnotationName(); doReturn(true).when(taggingStrategySpy).shouldAddEndpointFinishAnnotation(); doThrow(new RuntimeException("intentional exception")).when(taggingStrategySpy).endpointFinishAnnotationName(); ResponseInfo<?> responseInfoMock = mock(ResponseInfo.class); // when handlerSpy.doChannelRead(ctxMock, msg); futureThatWillBeAttachedToSpy.complete(responseInfoMock); Object result = futureThatWillBeAttachedToSpy.join(); // then verify(taggingStrategySpy).endpointStartAnnotationName(); verify(taggingStrategySpy).endpointFinishAnnotationName(); assertThat(result).isSameAs(responseInfoMock); // We verified that the methods were called that would have thrown exceptions, and nothing propagated. So // we're good. }
doReturn(scenario.finishAnnotationName).when(taggingStrategySpy).endpointFinishAnnotationName();