コード例 #1
0
  public static Message<?> addSpanHeaders(TraceKeys traceKeys, Message<?> message, Span span) {
    if (span == null) {
      if (!message.getHeaders().containsKey(Span.NOT_SAMPLED_NAME)) {
        return MessageBuilder.fromMessage(message).setHeader(Span.NOT_SAMPLED_NAME, "").build();
      }
      return message;
    }

    Map<String, String> headers = new HashMap<>();
    addHeader(headers, Span.TRACE_ID_NAME, Span.toHex(span.getTraceId()));
    addHeader(headers, Span.SPAN_ID_NAME, Span.toHex(span.getSpanId()));

    if (span.isExportable()) {
      addAnnotations(traceKeys, message, span);
      Long parentId = getFirst(span.getParents());
      if (parentId != null) {
        addHeader(headers, Span.PARENT_ID_NAME, Span.toHex(parentId));
      }
      addHeader(headers, Span.SPAN_NAME_NAME, span.getName());
      addHeader(headers, Span.PROCESS_ID_NAME, span.getProcessId());
    } else {
      addHeader(headers, Span.NOT_SAMPLED_NAME, "");
    }
    return MessageBuilder.fromMessage(message).copyHeaders(headers).build();
  }
 private MvcResult sendPingWithTraceId(String headerName, Long correlationId, boolean sampling)
     throws Exception {
   MockHttpServletRequestBuilder request =
       MockMvcRequestBuilders.get("/ping")
           .accept(MediaType.TEXT_PLAIN)
           .header(headerName, Span.toHex(correlationId))
           .header(Span.SPAN_ID_NAME, Span.toHex(new Random().nextLong()));
   if (!sampling) {
     request.header(Span.NOT_SAMPLED_NAME, "true");
   }
   return this.mockMvc.perform(request).andReturn();
 }
コード例 #3
0
 private static void addHeader(Map<String, String> headers, String name, Long value) {
   if (value != null) {
     addHeader(headers, name, Span.toHex(value));
   }
 }