com.nike.wingtips.Tracer.serializeSpanToDesiredStringRepresentation()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中com.nike.wingtips.Tracer.serializeSpanToDesiredStringRepresentation()方法的一些代码示例,展示了Tracer.serializeSpanToDesiredStringRepresentation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.serializeSpanToDesiredStringRepresentation()方法的具体详情如下:
包路径:com.nike.wingtips.Tracer
类名称:Tracer
方法名:serializeSpanToDesiredStringRepresentation

Tracer.serializeSpanToDesiredStringRepresentation介绍

[英]Uses #spanLoggingRepresentation to decide how to serialize the given span, and then returns the result of the serialization.
[中]使用#spanLoggingRepresentation决定如何序列化给定的跨度,然后返回序列化的结果。

代码示例

代码示例来源:origin: Nike-Inc/wingtips

/**
 * Pushes the given span onto the {@link #currentSpanStackThreadLocal} stack. If the stack is null it will create a new one. Also pushes the span info into the logging
 * {@link org.slf4j.MDC} so it is available there.
 */
protected void pushSpanOntoCurrentSpanStack(Span pushMe) {
  Deque<Span> currentStack = currentSpanStackThreadLocal.get();
  if (currentStack == null) {
    currentStack = new LinkedList<>();
    currentSpanStackThreadLocal.set(currentStack);
  }
  currentStack.push(pushMe);
  configureMDC(pushMe);
  classLogger.debug("** starting sample for span {}", serializeSpanToDesiredStringRepresentation(pushMe));
}

代码示例来源:origin: Nike-Inc/wingtips

/**
 * Calls {@link Span#complete()} to complete the span and logs it (but only if the span's {@link Span#isSampleable()} returns true). If the span is valid then it will
 * be logged to {@link #validSpanLogger}, and if it is invalid then it will be logged to {@link #invalidSpanLogger}.
 *
 * @param span The span to complete and log
 * @param containsIncorrectTimingInfo Pass in true if you know the given span contains incorrect timing information (e.g. a child sub-span that wasn't completed normally
 *                                    when it was supposed to have been completed), pass in false if the span's timing info is good. This affects how the span is logged.
 */
protected void completeAndLogSpan(Span span, boolean containsIncorrectTimingInfo) {
  // Complete the span.
  if (span.isCompleted()) {
    classLogger.error(
      "WINGTIPS USAGE ERROR - An attempt was made to complete a span that was already completed. This call will be ignored. "
      + "wingtips_usage_error=true, already_completed_span=true, trace_id={}, span_id={}",
      span.getTraceId(), span.getSpanId(), new Exception("Stack trace for debugging purposes")
    );
    return;
  }
  else
    span.complete();
  // Log the span if it was sampleable.
  if (span.isSampleable()) {
    String infoTag = containsIncorrectTimingInfo ? "[INCORRECT_TIMING] " : "";
    Logger loggerToUse = containsIncorrectTimingInfo ? invalidSpanLogger : validSpanLogger;
    loggerToUse.info("{}[DISTRIBUTED_TRACING] {}", infoTag, serializeSpanToDesiredStringRepresentation(span));
  }
  // Notify listeners.
  notifySpanCompleted(span);
}

代码示例来源:origin: Nike-Inc/wingtips

@DataProvider(value = {
  "JSON",
  "KEY_VALUE"
}, splitBy = "\\|")
@Test
public void verify_span_serialization_methods(Tracer.SpanLoggingRepresentation serializationOption) {
  // given
  Span span = Span.generateRootSpanForNewTrace(UUID.randomUUID().toString(), SpanPurpose.LOCAL_ONLY).build();
  String expectedOutput;
  switch(serializationOption) {
    case JSON:
      expectedOutput = span.toJSON();
      break;
    case KEY_VALUE:
      expectedOutput = span.toKeyValueString();
      break;
    default:
      throw new IllegalArgumentException("Unhandled option: " + serializationOption);
  }
  Tracer.getInstance().setSpanLoggingRepresentation(serializationOption);
  // then
  assertThat(Tracer.getInstance().getSpanLoggingRepresentation()).isEqualTo(serializationOption);
  // and when
  String serializedString = Tracer.getInstance().serializeSpanToDesiredStringRepresentation(span);
  // then
  assertThat(serializedString).isEqualTo(expectedOutput);
}

相关文章