@Test public void doFilterInternal_should_set_request_attributes_to_new_span_info() throws ServletException, IOException { RequestTracingFilter filter = getBasicFilter(); filter.doFilterInternal(requestMock, responseMock, spanCapturingFilterChain); assertThat(spanCapturingFilterChain.capturedSpan).isNotNull(); Span newSpan = spanCapturingFilterChain.capturedSpan; verify(requestMock).setAttribute(TraceHeaders.TRACE_SAMPLED, newSpan.isSampleable()); verify(requestMock).setAttribute(TraceHeaders.TRACE_ID, newSpan.getTraceId()); verify(requestMock).setAttribute(TraceHeaders.SPAN_ID, newSpan.getSpanId()); verify(requestMock).setAttribute(TraceHeaders.PARENT_SPAN_ID, newSpan.getParentSpanId()); verify(requestMock).setAttribute(TraceHeaders.SPAN_NAME, newSpan.getSpanName()); verify(requestMock).setAttribute(Span.class.getName(), newSpan); }
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { TracingState originalThreadInfo = TracingState.getCurrentThreadTracingState(); try { Span overallRequestSpan = createNewSpanForRequest(request); addTracingInfoToRequestAttributes(overallRequestSpan, request); response.setHeader(TraceHeaders.TRACE_ID, overallRequestSpan.getTraceId()); TracingState originalRequestTracingState = TracingState.getCurrentThreadTracingState(); Throwable errorForTagging = null; try { tagAndNamingStrategy.handleRequestTagging(overallRequestSpan, request, tagAndNamingAdapter); filterChain.doFilter(request, response); } catch(Throwable t) { errorForTagging = t; throw t; } finally { if (isAsyncRequest(request)) { setupTracingCompletionWhenAsyncRequestCompletes( request, response, originalRequestTracingState, tagAndNamingStrategy, tagAndNamingAdapter ); } else { try { tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( overallRequestSpan, request, response, errorForTagging, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } } } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } }
RequestTracingFilter implements Filter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { TracingState originalThreadInfo = TracingState.getCurrentThreadTracingState(); try { Span overallRequestSpan = createNewSpanForRequest(request); addTracingInfoToRequestAttributes(overallRequestSpan, request); response.setHeader(TraceHeaders.TRACE_ID, overallRequestSpan.getTraceId()); TracingState originalRequestTracingState = TracingState.getCurrentThreadTracingState(); Throwable errorForTagging = null; try { tagAndNamingStrategy.handleRequestTagging(overallRequestSpan, request, tagAndNamingAdapter); filterChain.doFilter(request, response); } catch(Throwable t) { errorForTagging = t; throw t; } finally { if (isAsyncRequest(request)) { setupTracingCompletionWhenAsyncRequestCompletes( request, response, originalRequestTracingState, tagAndNamingStrategy, tagAndNamingAdapter ); } else { try { tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( overallRequestSpan, request, response, errorForTagging, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } } } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } }
RequestTracingFilter implements Filter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { TracingState originalThreadInfo = TracingState.getCurrentThreadTracingState(); try { Span overallRequestSpan = createNewSpanForRequest(request); addTracingInfoToRequestAttributes(overallRequestSpan, request); response.setHeader(TraceHeaders.TRACE_ID, overallRequestSpan.getTraceId()); TracingState originalRequestTracingState = TracingState.getCurrentThreadTracingState(); Throwable errorForTagging = null; try { tagAndNamingStrategy.handleRequestTagging(overallRequestSpan, request, tagAndNamingAdapter); filterChain.doFilter(request, response); } catch(Throwable t) { errorForTagging = t; throw t; } finally { if (isAsyncRequest(request)) { setupTracingCompletionWhenAsyncRequestCompletes( request, response, originalRequestTracingState, tagAndNamingStrategy, tagAndNamingAdapter ); } else { try { tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( overallRequestSpan, request, response, errorForTagging, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } } } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } }  }
RequestTracingFilter implements Filter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { TracingState originalThreadInfo = TracingState.getCurrentThreadTracingState(); try { Span overallRequestSpan = createNewSpanForRequest(request); addTracingInfoToRequestAttributes(overallRequestSpan, request); response.setHeader(TraceHeaders.TRACE_ID, overallRequestSpan.getTraceId()); TracingState originalRequestTracingState = TracingState.getCurrentThreadTracingState(); Throwable errorForTagging = null; try { tagAndNamingStrategy.handleRequestTagging(overallRequestSpan, request, tagAndNamingAdapter); filterChain.doFilter(request, response); } catch(Throwable t) { errorForTagging = t; throw t; } finally { if (isAsyncRequest(request)) { setupTracingCompletionWhenAsyncRequestCompletes( request, response, originalRequestTracingState, tagAndNamingStrategy, tagAndNamingAdapter ); } else { try { tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( overallRequestSpan, request, response, errorForTagging, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } } } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } }  @Override @SuppressWarnings("RedundantThrows") void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain filterChain); }
RequestTracingFilter implements Filter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { TracingState originalThreadInfo = TracingState.getCurrentThreadTracingState(); try { Span overallRequestSpan = createNewSpanForRequest(request); addTracingInfoToRequestAttributes(overallRequestSpan, request); response.setHeader(TraceHeaders.TRACE_ID, overallRequestSpan.getTraceId()); TracingState originalRequestTracingState = TracingState.getCurrentThreadTracingState(); Throwable errorForTagging = null; try { tagAndNamingStrategy.handleRequestTagging(overallRequestSpan, request, tagAndNamingAdapter); filterChain.doFilter(request, response); } catch(Throwable t) { errorForTagging = t; throw t; } finally { if (isAsyncRequest(request)) { setupTracingCompletionWhenAsyncRequestCompletes( request, response, originalRequestTracingState, tagAndNamingStrategy, tagAndNamingAdapter ); } else { try { tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( overallRequestSpan, request, response, errorForTagging, tagAndNamingAdapter ); } finally { Tracer.getInstance().completeRequestSpan(); } } } } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } }  @Override @SuppressWarnings("RedundantThrows") void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain filterChain); static final String FILTER_HAS_ALREADY_EXECUTED_ATTRIBUTE; @Deprecated
    static final String ERROR_REQUEST_URI_ATTRIBUTE; static final String USER_ID_HEADER_KEYS_LIST_INIT_PARAM_NAME; static final String TAG_AND_SPAN_NAMING_STRATEGY_INIT_PARAM_NAME; static final String TAG_AND_SPAN_NAMING_ADAPTER_INIT_PARAM_NAME; }