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

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

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

Tracer.unconfigureMDC介绍

[英]Removes the MDC parameters.
[中]删除MDC参数。

代码示例

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

/**
 * "Unregisters" the current span stack from this thread, removes span-related info from the logging MDC, and returns the span stack that was unregistered so it
 * can be stored and re-registered later (if desired). This is used in asynchronous projects/frameworks where multiple in-progress requests might be handled by the same thread
 * before any of the requests can finish (e.g. Netty, where the worker I/O threads might process a portion of request A, flip over to request B to do some work, then go back
 * to request A, etc). This method lets you unregister the tracing info from the current thread when it is about to switch to processing a different request so the tracing
 * info can be stored in some kind of request context state that follows the request, and won't pollute the thread's span stack and MDC info when the new request starts being
 * processed.
 * <br/>
 * When processing switches back to the original request, you can call {@link #registerWithThread(java.util.Deque)} to set the thread's span stack and MDC info back to the
 * way it was when you first called this unregister method for the original request.
 * <p/>
 * <b>WARNING:</b> This method should NOT be called if you're in an environment where a single thread is guaranteed to process a request from start to finish without jumping
 * to a different request in the middle. In that case just use the normal start and complete span methods and ignore this method.
 */
public Deque<Span> unregisterFromThread() {
  Deque<Span> currentValue = currentSpanStackThreadLocal.get();
  currentSpanStackThreadLocal.remove();
  unconfigureMDC();
  return currentValue;
}

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

unconfigureMDC();

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

unconfigureMDC();
else
  configureMDC(newStackLatestSpan);

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

@Test
public void unconfigureMDC_should_unset_span_values_on_MDC() throws Exception {
  // given
  Span span = Span.newBuilder("test-span", SpanPurpose.LOCAL_ONLY).withParentSpanId("3").build();
  Tracer.configureMDC(span);
  // when
  Tracer.unconfigureMDC();
  // then
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
}

相关文章