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 ); } }
protected void handleWireSendFinishAnnotationIfNecessary() { if (alreadyHandledWireSendFinishAnnotation) { return; } alreadyHandledWireSendFinishAnnotation = true; // Add the wire-send-finish annotation if we have a span and the annotation is desired. if ((spanForDownstreamCall != null) && proxySpanTaggingStrategy.shouldAddWireSendFinishAnnotation()) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireSendFinishAnnotationName() ); } }
protected void handleWireSendFinishAnnotationIfNecessary() { if (alreadyHandledWireSendFinishAnnotation) { return; } alreadyHandledWireSendFinishAnnotation = true; // Add the wire-send-finish annotation if we have a span and the annotation is desired. if ((spanForDownstreamCall != null) && proxySpanTaggingStrategy.shouldAddWireSendFinishAnnotation()) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireSendFinishAnnotationName() ); } }
protected void addErrorAnnotationToOverallRequestSpan( @NotNull HttpProcessingState state, @NotNull ResponseInfo<ErrorResponseBody> responseInfo, @NotNull Throwable error ) { try { Span requestSpan = state.getOverallRequestSpan(); if ( requestSpan != null && spanNamingAndTaggingStrategy.shouldAddErrorAnnotationForCaughtException(responseInfo, error) ) { requestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.errorAnnotationName(responseInfo, error) ); } } catch (Throwable t) { logger.error( "An unexpected error occurred while trying to add an error annotation to the overall request span. " + "This should never happen.", t ); } }
protected void addErrorAnnotationToOverallRequestSpan( @NotNull HttpProcessingState state, @NotNull ResponseInfo<ErrorResponseBody> responseInfo, @NotNull Throwable error ) { try { Span requestSpan = state.getOverallRequestSpan(); if ( requestSpan != null && spanNamingAndTaggingStrategy.shouldAddErrorAnnotationForCaughtException(responseInfo, error) ) { requestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.errorAnnotationName(responseInfo, error) ); } } catch (Throwable t) { logger.error( "An unexpected error occurred while trying to add an error annotation to the overall request span. " + "This should never happen.", t ); } }
@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; }
endpointExecutionSpan.addTimestampedAnnotationForCurrentTime( spanTaggingStrategy.endpointStartAnnotationName() );
endpointExecutionSpan.addTimestampedAnnotationForCurrentTime( spanTaggingStrategy.endpointStartAnnotationName() );
verify(spanMock).addTimestampedAnnotationForCurrentTime( distributedTracingConfig.getServerSpanNamingAndTaggingStrategy().wireReceiveFinishAnnotationName() ); verify(spanMock, never()).addTimestampedAnnotationForCurrentTime(anyString());
@UseDataProvider("errorAnnotationScenarioDataProvider") @Test public void addErrorAnnotationToOverallRequestSpan_works_as_expected( ErrorAnnotationScenario scenario ) { // given HttpProcessingState stateSpy = spy(state); doReturn(scenario.overallRequestSpanMock).when(stateSpy).getOverallRequestSpan(); ResponseInfo<ErrorResponseBody> responseInfoMock = mock(ResponseInfo.class); Throwable errorMock = mock(Throwable.class); doReturn(scenario.addErrorAnnotationConfigValue) .when(serverSpanNamingAndTaggingStrategyMock).shouldAddErrorAnnotationForCaughtException(any(), any()); String annotationValueFromStrategy = UUID.randomUUID().toString(); doReturn(annotationValueFromStrategy) .when(serverSpanNamingAndTaggingStrategyMock).errorAnnotationName(any(), any()); // when handler.addErrorAnnotationToOverallRequestSpan(stateSpy, responseInfoMock, errorMock); // then if (scenario.expectAnnotation) { verify(scenario.overallRequestSpanMock).addTimestampedAnnotationForCurrentTime(annotationValueFromStrategy); verify(serverSpanNamingAndTaggingStrategyMock).errorAnnotationName(responseInfoMock, errorMock); } if (scenario.overallRequestSpanMock != null) { verify(serverSpanNamingAndTaggingStrategyMock) .shouldAddErrorAnnotationForCaughtException(responseInfoMock, errorMock); } }
? times(1) : never(); verify(spanMock, startAnnotationVerification).addTimestampedAnnotationForCurrentTime( scenario.startAnnotationName ); ? times(1) : never(); verify(spanMock, finishAnnotationVerification).addTimestampedAnnotationForCurrentTime( scenario.finishAnnotationName );
overallRequestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireSendStartAnnotationName() ); Span overallRequestSpan = state.getOverallRequestSpan(); if (overallRequestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireSendFinishAnnotation()) { overallRequestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireSendFinishAnnotationName() );
overallRequestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireSendStartAnnotationName() ); Span overallRequestSpan = state.getOverallRequestSpan(); if (overallRequestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireSendFinishAnnotation()) { overallRequestSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireSendFinishAnnotationName() );
currentSpan.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveFinishAnnotationName() ); && proxySpanTaggingStrategy.shouldAddWireReceiveStartAnnotation() ) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveStartAnnotationName() );
currentSpan.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveFinishAnnotationName() ); && proxySpanTaggingStrategy.shouldAddWireReceiveStartAnnotation() ) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveStartAnnotationName() );
span.addTimestampedAnnotationForCurrentTime(annotationValue); long nanoTimeAfterMethodCall = System.nanoTime();
newSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireReceiveStartAnnotationName() );
newSpan.addTimestampedAnnotationForCurrentTime( spanNamingAndTaggingStrategy.wireReceiveStartAnnotationName() );