@Test public void finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread_completes_span_even_if_highly_improbable_exception_occurs() { Span rootSpan = Tracer.getInstance().startRequestWithRootSpan("fooRootSpan"); RuntimeException improbableException = new RuntimeException("Intentional test exception"); @SuppressWarnings("unchecked") Pair<String, String> explodingTag = mock(Pair.class); doThrow(improbableException).when(explodingTag).getKey(); Throwable ex = catchThrowable( () -> WingtipsSpringWebfluxWebFilter.finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread( exchange, mock(Throwable.class), tagAndNamingStrategy, tagAndNamingAdapterMock, explodingTag ) ); assertThat(ex).isSameAs(improbableException); assertThat(rootSpan.isCompleted()).isTrue(); assertThat(spanRecorder.completedSpans).isEqualTo(singletonList(rootSpan)); assertThat(Tracer.getInstance().getCurrentSpan()).isNull(); }
@SafeVarargs protected static void finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread( @NotNull ServerWebExchange exchange, @Nullable Throwable error, @NotNull HttpTagAndSpanNamingStrategy<ServerWebExchange, ServerHttpResponse> tagAndNamingStrategy, @NotNull HttpTagAndSpanNamingAdapter<ServerWebExchange, ServerHttpResponse> tagAndNamingAdapter, Pair<String, String>... extraCustomTags ) { Span span = Tracer.getInstance().getCurrentSpan(); if (span == null) { return; } if (span.isCompleted()) { return; } try { if (extraCustomTags != null) { for (Pair<String, String> tag : extraCustomTags) { span.putTag(tag.getKey(), tag.getValue()); } } tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( span, exchange, exchange.getResponse(), error, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } }
WingtipsSpringWebfluxWebFilter implements WebFilter, Ordered { @SafeVarargs protected static void finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread( @NotNull ServerWebExchange exchange, @Nullable Throwable error, @NotNull HttpTagAndSpanNamingStrategy<ServerWebExchange, ServerHttpResponse> tagAndNamingStrategy, @NotNull HttpTagAndSpanNamingAdapter<ServerWebExchange, ServerHttpResponse> tagAndNamingAdapter, Pair<String, String>... extraCustomTags ) { Span span = Tracer.getInstance().getCurrentSpan(); if (span == null) { return; } if (span.isCompleted()) { return; } try { if (extraCustomTags != null) { for (Pair<String, String> tag : extraCustomTags) { span.putTag(tag.getKey(), tag.getValue()); } } tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( span, exchange, exchange.getResponse(), error, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } }
WingtipsSpringWebfluxWebFilter implements WebFilter, Ordered { @SafeVarargs protected static void finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread( @NotNull ServerWebExchange exchange, @Nullable Throwable error, @NotNull HttpTagAndSpanNamingStrategy<ServerWebExchange, ServerHttpResponse> tagAndNamingStrategy, @NotNull HttpTagAndSpanNamingAdapter<ServerWebExchange, ServerHttpResponse> tagAndNamingAdapter, Pair<String, String>... extraCustomTags ) { Span span = Tracer.getInstance().getCurrentSpan(); if (span == null) { return; } if (span.isCompleted()) { return; } try { if (extraCustomTags != null) { for (Pair<String, String> tag : extraCustomTags) { span.putTag(tag.getKey(), tag.getValue()); } } tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( span, exchange, exchange.getResponse(), error, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } WingtipsSpringWebfluxWebFilter();  WingtipsSpringWebfluxWebFilter(Builder builder); }
WingtipsSpringWebfluxWebFilter implements WebFilter, Ordered { @SafeVarargs protected static void finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread( @NotNull ServerWebExchange exchange, @Nullable Throwable error, @NotNull HttpTagAndSpanNamingStrategy<ServerWebExchange, ServerHttpResponse> tagAndNamingStrategy, @NotNull HttpTagAndSpanNamingAdapter<ServerWebExchange, ServerHttpResponse> tagAndNamingAdapter, Pair<String, String>... extraCustomTags ) { Span span = Tracer.getInstance().getCurrentSpan(); if (span == null) { return; } if (span.isCompleted()) { return; } try { if (extraCustomTags != null) { for (Pair<String, String> tag : extraCustomTags) { span.putTag(tag.getKey(), tag.getValue()); } } tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( span, exchange, exchange.getResponse(), error, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } WingtipsSpringWebfluxWebFilter();  WingtipsSpringWebfluxWebFilter(Builder builder); static Builder newBuilder(); @Override @NotNull Mono<Void> filter(@NotNull ServerWebExchange exchange, @NotNull WebFilterChain chain); @Override int getOrder(); void setOrder(int order); }
WingtipsSpringWebfluxWebFilter implements WebFilter, Ordered { @SafeVarargs protected static void finalizeAndCompleteOverallRequestSpanAttachedToCurrentThread( @NotNull ServerWebExchange exchange, @Nullable Throwable error, @NotNull HttpTagAndSpanNamingStrategy<ServerWebExchange, ServerHttpResponse> tagAndNamingStrategy, @NotNull HttpTagAndSpanNamingAdapter<ServerWebExchange, ServerHttpResponse> tagAndNamingAdapter, Pair<String, String>... extraCustomTags ) { Span span = Tracer.getInstance().getCurrentSpan(); if (span == null) { return; } if (span.isCompleted()) { return; } try { if (extraCustomTags != null) { for (Pair<String, String> tag : extraCustomTags) { span.putTag(tag.getKey(), tag.getValue()); } } tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( span, exchange, exchange.getResponse(), error, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } WingtipsSpringWebfluxWebFilter();  WingtipsSpringWebfluxWebFilter(Builder builder); static Builder newBuilder(); @Override @NotNull Mono<Void> filter(@NotNull ServerWebExchange exchange, @NotNull WebFilterChain chain); @Override int getOrder(); void setOrder(int order);  }