WingtipsSpringWebfluxWebFilter implements WebFilter, Ordered { protected @NotNull Span createNewSpanForRequest(@NotNull ServerWebExchange exchange) { Tracer tracer = Tracer.getInstance(); RequestWithHeadersServerWebExchangeAdapter requestWithHeadersAdapter = new RequestWithHeadersServerWebExchangeAdapter(exchange); final Span parentSpan = HttpRequestTracingUtils.fromRequestWithHeaders( requestWithHeadersAdapter, userIdHeaderKeys ); Span newSpan; if (parentSpan == null) { newSpan = tracer.startRequestWithRootSpan( getInitialSpanName(exchange, tagAndNamingStrategy, tagAndNamingAdapter), HttpRequestTracingUtils.getUserIdFromRequestWithHeaders(requestWithHeadersAdapter, userIdHeaderKeys) ); logger.debug("Parent span not found, starting a new span {}", newSpan); } else { logger.debug("Found parent Span {}", parentSpan); newSpan = tracer.startRequestWithChildSpan( parentSpan, getInitialSpanName(exchange, tagAndNamingStrategy, tagAndNamingAdapter) ); } return newSpan; } 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);  }
@UseDataProvider("createNewSpanForRequestScenarioDataProvider") @Test public void createNewSpanForRequest_works_as_expected(CreateNewSpanForRequestScenario scenario) { doReturn(scenario.incomingTraceIdHeader).when(requestHeadersMock).getFirst(TraceHeaders.TRACE_ID); doReturn(scenario.incomingSpanIdHeader).when(requestHeadersMock).getFirst(TraceHeaders.SPAN_ID); doReturn(scenario.incomingSampledHeader).when(requestHeadersMock).getFirst(TraceHeaders.TRACE_SAMPLED); doReturn(scenario.incomingUserIdHeader).when(requestHeadersMock).getFirst("user-id"); doReturn(scenario.incomingAltUserIdHeader).when(requestHeadersMock).getFirst("alt-user-id"); assertThat(Tracer.getInstance().getCurrentSpan()).isNull(); Span result = filterSpy.createNewSpanForRequest(exchange); if (scenario.incomingTraceIdHeader != null) { assertThat(result.getTraceId()).isEqualTo(scenario.incomingTraceIdHeader); } assertThat(result.getParentSpanId()).isEqualTo(scenario.expectedParentSpanId); assertThat(result.isSampleable()).isEqualTo(scenario.expectedSampleableValue); assertThat(result.getUserId()).isEqualTo(scenario.expectedUserId); if (scenario.incomingTraceIdHeader != null && scenario.incomingSpanIdHeader == null) { assertThat(HttpRequestTracingUtils.hasInvalidParentIdBecauseCallerDidNotSendSpanId(result)).isTrue(); assertThat(result.getTags().get(CHILD_OF_SPAN_FROM_HEADERS_WHERE_CALLER_DID_NOT_SEND_SPAN_ID_TAG_KEY)) .isEqualTo("true"); } assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(result); }