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

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

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

Tracer.getCurrentTracingStateCopy介绍

暂无

代码示例

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

/**
 * @return A *copy* of the current thread's tracing information - retrieved by calling {@link
 * Tracer#getCurrentTracingStateCopy()}. Since this creates copies of the span stack and MDC info it can be
 * have a noticeable performance impact if used too many times (i.e. tens or hundreds of times per request for high
 * throughput services). NOTE: This is usually not needed unless you're doing asynchronous processing and need to
 * pass tracing state across thread boundaries.
 */
public static TracingState getCurrentThreadTracingState() {
  return Tracer.getInstance().getCurrentTracingStateCopy();
}

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

@Test
public void getCurrentTracingStateCopy_works_as_expected() {
  // given
  Tracer tracer = Tracer.getInstance();
  tracer.startRequestWithRootSpan("request-" + UUID.randomUUID().toString());
  Deque<Span> currentSpanStack = tracer.getCurrentSpanStackCopy();
  Map<String, String> currentMdcInfo = MDC.getCopyOfContextMap();
  assertThat(currentSpanStack.size()).isGreaterThanOrEqualTo(1);
  assertThat(currentMdcInfo).isNotEmpty();
  // when
  TracingState currentTracingState = tracer.getCurrentTracingStateCopy();
  // then
  assertThat(currentTracingState.spanStack).isEqualTo(currentSpanStack);
  assertThat(currentTracingState.mdcInfo).isEqualTo(currentMdcInfo);
}

相关文章