public EndpointSpanInfoDto(HttpServletRequest request, Span endpoint_execution_span, List<String> userIdHeaderKeys) { this.parent_span_info = new SpanInfoDto( request.getHeader(TraceHeaders.TRACE_ID), request.getHeader(TraceHeaders.SPAN_ID), request.getHeader(TraceHeaders.PARENT_SPAN_ID), request.getHeader(TraceHeaders.TRACE_SAMPLED), HttpSpanFactory.getUserIdFromHttpServletRequest(request, userIdHeaderKeys) ); this.endpoint_execution_span_info = new SpanInfoDto( endpoint_execution_span.getTraceId(), endpoint_execution_span.getSpanId(), endpoint_execution_span.getParentSpanId(), String.valueOf(endpoint_execution_span.isSampleable()), endpoint_execution_span.getUserId() ); }
public EndpointSpanInfoDto(HttpServletRequest request, Span endpoint_execution_span, List<String> userIdHeaderKeys) { this.parent_span_info = new SpanInfoDto( request.getHeader(TraceHeaders.TRACE_ID), request.getHeader(TraceHeaders.SPAN_ID), request.getHeader(TraceHeaders.PARENT_SPAN_ID), request.getHeader(TraceHeaders.TRACE_SAMPLED), HttpSpanFactory.getUserIdFromHttpServletRequest(request, userIdHeaderKeys) ); this.endpoint_execution_span_info = new SpanInfoDto( endpoint_execution_span.getTraceId(), endpoint_execution_span.getSpanId(), endpoint_execution_span.getParentSpanId(), String.valueOf(endpoint_execution_span.isSampleable()), endpoint_execution_span.getUserId() ); }
@Test public void getUserIdFromHttpServletRequest_returns_null_if_passed_null_request() { // when String nullUserId = HttpSpanFactory.getUserIdFromHttpServletRequest(null, USER_ID_HEADER_KEYS); // then //noinspection ConstantConditions assertThat(nullUserId).isNull(); }
/** * @return A {@link Span} object created from the headers if they exist (see {@link #fromHttpServletRequest(HttpServletRequest, List)} for details), or if the headers don't * have enough information then this will return a new root span with a span name based on the results of {@link #getSpanName(HttpServletRequest)} and user ID based * on the result of {@link #getUserIdFromHttpServletRequest(HttpServletRequest, List)}. Since this method is for a server receiving a request * the returned span's {@link Span#getSpanPurpose()} will be {@link SpanPurpose#SERVER}. */ public static Span fromHttpServletRequestOrCreateRootSpan(HttpServletRequest servletRequest, List<String> userIdHeaderKeys) { Span span = fromHttpServletRequest(servletRequest, userIdHeaderKeys); if (span == null) { span = Span .generateRootSpanForNewTrace(getSpanName(servletRequest), SpanPurpose.SERVER) .withUserId(getUserIdFromHttpServletRequest(servletRequest, userIdHeaderKeys)) .build(); } return span; }
/** * @param request The incoming request. * @return A new {@link Span} for the overall request. This inspects the incoming request's headers to determine * if it should continue an existing trace with a child span, or whether a brand new trace needs to be started. * {@link #getInitialSpanName(HttpServletRequest, HttpTagAndSpanNamingStrategy, HttpTagAndSpanNamingAdapter)} * is used to generate the initial span name. */ protected Span createNewSpanForRequest(HttpServletRequest request) { // See if there's trace info in the incoming request's headers. If so it becomes the parent trace. Tracer tracer = Tracer.getInstance(); final Span parentSpan = HttpSpanFactory.fromHttpServletRequest(request, getUserIdHeaderKeys()); Span newSpan; if (parentSpan != null) { logger.debug("Found parent Span {}", parentSpan); newSpan = tracer.startRequestWithChildSpan( parentSpan, getInitialSpanName(request, tagAndNamingStrategy, tagAndNamingAdapter) ); } else { newSpan = tracer.startRequestWithRootSpan( getInitialSpanName(request, tagAndNamingStrategy, tagAndNamingAdapter), HttpSpanFactory.getUserIdFromHttpServletRequest(request, getUserIdHeaderKeys()) ); logger.debug("Parent span not found, starting a new span {}", newSpan); } return newSpan; }