@Test public void default_annotation_method_implementations_return_expected_values() { // given ProxyRouterSpanNamingAndTaggingStrategy<?> defaultImpl = new DefaultProxyRouterSpanNamingAndTaggingStrategy(); HttpResponse responseMock = mock(HttpResponse.class); Throwable errorMock = mock(Throwable.class); // expect assertThat(defaultImpl.shouldAddConnStartAnnotation()).isTrue(); assertThat(defaultImpl.connStartAnnotationName()).isEqualTo("conn.start"); assertThat(defaultImpl.shouldAddConnFinishAnnotation()).isTrue(); assertThat(defaultImpl.connFinishAnnotationName()).isEqualTo("conn.finish"); verifyZeroInteractions(responseMock, errorMock); }
/** * Returns the name that should be used for the span surrounding the downstream call. Defaults to whatever {@link * ProxyRouterSpanNamingAndTaggingStrategy#getInitialSpanName(Object)} returns, with a fallback * of {@link HttpRequestTracingUtils#getFallbackSpanNameForHttpRequest(String, String)} if the naming strategy * returned null or blank string. * * @param downstreamRequest The Netty {@link HttpRequest} for the downstream call. * @param namingStrategy The {@link ProxyRouterSpanNamingAndTaggingStrategy} being used. * @return The name that should be used for the span surrounding the downstream call. */ protected @NotNull String getSubspanSpanName( @NotNull HttpRequest downstreamRequest, @NotNull ProxyRouterSpanNamingAndTaggingStrategy<Span> namingStrategy ) { String spanNameFromStrategy = namingStrategy.getInitialSpanName(downstreamRequest); if (StringUtils.isNotBlank(spanNameFromStrategy)) { return spanNameFromStrategy; } // The naming strategy didn't have anything for us. Fall back to something reasonable. return getFallbackSpanName(downstreamRequest); }
public void handleTracingResponseTaggingAndFinalSpanNameIfNotAlreadyDone(Span spanAroundProxyCall) { if ( tracingResponseTaggingAndFinalSpanNameCompleted || (distributedTracingConfig == null) || (spanAroundProxyCall == null) ) { return; } tracingResponseTaggingAndFinalSpanNameCompleted = true; try { distributedTracingConfig .getProxyRouterSpanNamingAndTaggingStrategy() .handleResponseTaggingAndFinalSpanName( spanAroundProxyCall, getProxyHttpRequest(), getProxyHttpResponse(), getProxyError() ); } catch (Throwable t) { logger.error( "Unexpected error occurred while trying to set final span name and proxy response tagging. This " + "exception will be ignored, but should be investigated - it should not happen.", t ); } } }
proxySpanTaggingStrategy.handleRequestTagging(subspan, initialRequestChunk); if (proxySpanTaggingStrategy.shouldAddConnStartAnnotation()) { subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicrosWithNanoOffset( subspan.getSpanStartTimeEpochMicros(), -connectionSetupTimeNanos, proxySpanTaggingStrategy.connStartAnnotationName() )); if (proxySpanTaggingStrategy.shouldAddConnFinishAnnotation()) { subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicros( subspan.getSpanStartTimeEpochMicros(), proxySpanTaggingStrategy.connFinishAnnotationName() )); && proxySpanTaggingStrategy.shouldAddWireSendStartAnnotation() ) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireSendStartAnnotationName() );
if (proxySpanTaggingStrategy.shouldAddWireReceiveFinishAnnotation()) { currentSpan.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveFinishAnnotationName() ); && proxySpanTaggingStrategy.shouldAddWireReceiveStartAnnotation() ) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveStartAnnotationName() );
if ( currentSpan != null && proxySpanTaggingStrategy.shouldAddErrorAnnotationForCaughtException(proxyHttpResponseObj, cause) ) { currentSpan.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.errorAnnotationName(proxyHttpResponseObj, cause) );
proxySpanTaggingStrategy.handleRequestTagging(subspan, initialRequestChunk); if (proxySpanTaggingStrategy.shouldAddConnStartAnnotation()) { subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicrosWithNanoOffset( subspan.getSpanStartTimeEpochMicros(), -connectionSetupTimeNanos, proxySpanTaggingStrategy.connStartAnnotationName() )); if (proxySpanTaggingStrategy.shouldAddConnFinishAnnotation()) { subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicros( subspan.getSpanStartTimeEpochMicros(), proxySpanTaggingStrategy.connFinishAnnotationName() )); && proxySpanTaggingStrategy.shouldAddWireSendStartAnnotation() ) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireSendStartAnnotationName() );
if (proxySpanTaggingStrategy.shouldAddWireReceiveFinishAnnotation()) { currentSpan.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveFinishAnnotationName() ); && proxySpanTaggingStrategy.shouldAddWireReceiveStartAnnotation() ) { spanForDownstreamCall.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.wireReceiveStartAnnotationName() );
if ( currentSpan != null && proxySpanTaggingStrategy.shouldAddErrorAnnotationForCaughtException(proxyHttpResponseObj, cause) ) { currentSpan.addTimestampedAnnotationForCurrentTime( proxySpanTaggingStrategy.errorAnnotationName(proxyHttpResponseObj, cause) );
/** * Returns the name that should be used for the span surrounding the downstream call. Defaults to whatever {@link * ProxyRouterSpanNamingAndTaggingStrategy#getInitialSpanName(Object)} returns, with a fallback * of {@link HttpRequestTracingUtils#getFallbackSpanNameForHttpRequest(String, String)} if the naming strategy * returned null or blank string. * * @param downstreamRequest The Netty {@link HttpRequest} for the downstream call. * @param namingStrategy The {@link ProxyRouterSpanNamingAndTaggingStrategy} being used. * @return The name that should be used for the span surrounding the downstream call. */ protected @NotNull String getSubspanSpanName( @NotNull HttpRequest downstreamRequest, @NotNull ProxyRouterSpanNamingAndTaggingStrategy<Span> namingStrategy ) { String spanNameFromStrategy = namingStrategy.getInitialSpanName(downstreamRequest); if (StringUtils.isNotBlank(spanNameFromStrategy)) { return spanNameFromStrategy; } // The naming strategy didn't have anything for us. Fall back to something reasonable. return getFallbackSpanName(downstreamRequest); }
public void handleTracingResponseTaggingAndFinalSpanNameIfNotAlreadyDone(Span spanAroundProxyCall) { if ( tracingResponseTaggingAndFinalSpanNameCompleted || (distributedTracingConfig == null) || (spanAroundProxyCall == null) ) { return; } tracingResponseTaggingAndFinalSpanNameCompleted = true; try { distributedTracingConfig .getProxyRouterSpanNamingAndTaggingStrategy() .handleResponseTaggingAndFinalSpanName( spanAroundProxyCall, getProxyHttpRequest(), getProxyHttpResponse(), getProxyError() ); } catch (Throwable t) { logger.error( "Unexpected error occurred while trying to set final span name and proxy response tagging. This " + "exception will be ignored, but should be investigated - it should not happen.", t ); } } }