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

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

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

Tracer.getCurrentSpanStackCopy介绍

[英]IMPORTANT: This method is not for typical thread-per-request application usage - most of the time you just want #getCurrentSpan(). This method is here to facilitate complex asynchronous threading situations.

Returns a COPY of the current span stack. A copy is returned instead of the original to prevent you from directly modifying the stack - you should use the start/complete request span/sub-span methods to manipulate the stack. But sometimes you need to see what the stack looks like, or store it at a certain state so you can reconstitute it later (you can sort of do this with #unregisterFromThread() which also returns the span stack, but that unregisters everything and sometimes you need to store for later without interrupting current state).

This method may return null or an empty stack, depending on its current state.
[中]重要提示:此方法不适用于典型的每请求线程应用程序使用——大多数情况下,您只需要#getCurrentSpan()。此方法用于简化复杂的异步线程情况。
返回当前跨度堆栈的副本。将返回一个副本而不是原始副本,以防止您直接修改堆栈-您应该使用start/complete request span/sub span方法来操作堆栈。但有时需要查看堆栈的外观,或者将其存储在特定状态,以便以后可以重新构建它(可以使用#unregisterFromThread()执行此操作,它也会返回跨度堆栈,但这会注销所有内容,有时需要在不中断当前状态的情况下为以后存储)。
此方法可能返回null或空堆栈,具体取决于其当前状态。

代码示例

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

/**
 * @return A *copy* of the current thread's tracing information. Since this creates copies of the span stack and MDC
 * info it can 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 TracingState getCurrentTracingStateCopy() {
  return new TracingState(getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link BiFunctionWithTracing#BiFunctionWithTracing(BiFunction, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public BiFunctionWithTracing(BiFunction<T, U, R> origBiFunction) {
  this(origBiFunction, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link SupplierWithTracing#SupplierWithTracing(Supplier, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public SupplierWithTracing(Supplier<U> origSupplier) {
  this(origSupplier, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link SuccessCallbackWithTracing#SuccessCallbackWithTracing(SuccessCallback, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public SuccessCallbackWithTracing(SuccessCallback<T> origSuccessCallback) {
  this(origSuccessCallback, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

代码示例来源:origin: com.nike.wingtips/wingtips-spring

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link FailureCallbackWithTracing#FailureCallbackWithTracing(FailureCallback, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 * 
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public FailureCallbackWithTracing(FailureCallback origFailureCallback) {
  this(origFailureCallback, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link ConsumerWithTracing#ConsumerWithTracing(Consumer, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public ConsumerWithTracing(Consumer<T> origConsumer) {
  this(origConsumer, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link BiPredicateWithTracing#BiPredicateWithTracing(BiPredicate, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public BiPredicateWithTracing(BiPredicate<T, U> origBiPredicate) {
  this(origBiPredicate, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

/**
 * Constructor that extracts the current tracing and MDC information from the current thread using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}, and forwards the information to
 * the {@link RunnableWithTracing#RunnableWithTracing(Runnable, Deque, Map)}
 * constructor. That tracing and MDC information will be associated with the thread when the given operation is
 * executed.
 * 
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 */
public RunnableWithTracing(Runnable origRunnable) {
  this(origRunnable, Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

@Override
  public Object answer(InvocationOnMock invocation) throws Throwable {
    currentSpanStackWhenCallableWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
    currentMdcInfoWhenCallableWasCalled.add(MDC.getCopyOfContextMap());
    if (throwExceptionDuringCall)
      throw new RuntimeException("kaboom");
    return null;
  }
}).when(callableMock).call();

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

@Override
  public Object answer(InvocationOnMock invocation) throws Throwable {
    currentSpanStackWhenRunnableWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
    currentMdcInfoWhenRunnableWasCalled.add(MDC.getCopyOfContextMap());
    if (throwExceptionDuringCall)
      throw new RuntimeException("kaboom");
    return null;
  }
}).when(runnableMock).run();

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

@Test
public void getCurrentSpanStackCopy_returns_null_if_original_is_null() {
  // given
  Tracer tracer = Tracer.getInstance();
  assertThat(getSpanStackSize()).isEqualTo(0);
  // expect
  assertThat(tracer.getCurrentSpanStackCopy()).isNull();
}

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

@Test
public void linkTracingAndMdcToCurrentThread_should_clear_mdc_if_state_is_available_but_state_mdc_info_is_null() {
  // given
  MDC.put("foo", "bar");
  Tracer.getInstance().startRequestWithRootSpan("blahtrace");
  assertThat(MDC.getCopyOfContextMap().isEmpty(), is(false));
  assertThat(Tracer.getInstance().getCurrentSpan(), notNullValue());
  // when
  handler.linkTracingAndMdcToCurrentThread(ctxMock);
  // then
  assertThat(MDC.getCopyOfContextMap().isEmpty(), is(true));
  assertThat(Tracer.getInstance().getCurrentSpanStackCopy(), nullValue());
}

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

private Pair<Deque<Span>, Map<String, String>> setupCurrentThreadWithTracingInfo() {
  resetTracing();
  Tracer.getInstance().startRequestWithRootSpan("request-" + UUID.randomUUID().toString());
  return Pair.of(Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

private Pair<Deque<Span>, Map<String, String>> setupCurrentThreadWithTracingInfo() {
  resetTracing();
  Tracer.getInstance().startRequestWithRootSpan("request-" + UUID.randomUUID().toString());
  return Pair.of(Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

private Pair<Deque<Span>, Map<String, String>> setupCurrentThreadWithTracingInfo() {
  resetTracing();
  Tracer.getInstance().startRequestWithRootSpan("request-" + UUID.randomUUID().toString());
  return Pair.of(Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap());
}

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

public static ChannelHandlerContextMocks mockChannelHandlerContextWithTraceInfo(String userId) {
  if (Tracer.getInstance().getCurrentSpan() == null) {
    Tracer.getInstance().startRequestWithRootSpan("mockChannelHandlerContext", userId);
  }
  ChannelHandlerContextMocks channelHandlerMocks = mockChannelHandlerContext();
  when(channelHandlerMocks.mockHttpProcessingState.getLoggerMdcContextMap()).thenReturn(MDC.getCopyOfContextMap());
  when(channelHandlerMocks.mockHttpProcessingState.getDistributedTraceStack()).thenReturn(Tracer.getInstance().getCurrentSpanStackCopy());
  return channelHandlerMocks;
}

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

private Pair<Deque<Span>, Map<String, String>> generateTracingInfo() {
  resetTracing();
  Tracer.getInstance().startRequestWithRootSpan("someSpan");
  Pair<Deque<Span>, Map<String, String>> result = Pair.of(
    Tracer.getInstance().getCurrentSpanStackCopy(), new HashMap<>(MDC.getCopyOfContextMap())
  );
  resetTracing();
  return result;
}

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

private Pair<Deque<Span>, Map<String, String>> generateTracingInfo() {
  resetTracing();
  Tracer.getInstance().startRequestWithRootSpan("someSpan");
  Pair<Deque<Span>, Map<String, String>> result = Pair.of(
    Tracer.getInstance().getCurrentSpanStackCopy(), new HashMap<>(MDC.getCopyOfContextMap())
  );
  resetTracing();
  return result;
}

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

private Pair<Deque<Span>, Map<String, String>> generateTracingAndMdcInfo() {
  resetTracingAndMdc();
  Tracer.getInstance().startRequestWithRootSpan("someSpan");
  Pair<Deque<Span>, Map<String, String>> result = Pair.of(
    Tracer.getInstance().getCurrentSpanStackCopy(), new HashMap<>(MDC.getCopyOfContextMap())
  );
  resetTracingAndMdc();
  return result;
}

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

private Pair<Deque<Span>, Map<String, String>> generateTracingInfo() {
  resetTracing();
  Tracer.getInstance().startRequestWithRootSpan("someSpan");
  Pair<Deque<Span>, Map<String, String>> result = Pair.of(
    Tracer.getInstance().getCurrentSpanStackCopy(),
    (Map<String, String>)new HashMap<>(MDC.getCopyOfContextMap())
  );
  resetTracing();
  return result;
}

相关文章