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

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

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

Tracer.addSpanLifecycleListener介绍

[英]Adds the given listener to the #spanLifecycleListeners list using java.util.List#add(Object). This method will do nothing if you pass in null.

WARNING: It's important that any SpanLifecycleListener you add is extremely lightweight or you risk distributed tracing becoming a major bottleneck for high throughput services. If any expensive work needs to be done in a SpanLifecycleListener then it should be done asynchronously on a thread or threadpool separate from the application worker threads.
[中]使用java将给定的侦听器添加到#spanLifecycleListeners列表中。util。列表#添加(对象)。如果传入null,此方法将不起任何作用。
警告:添加的任何SpanLifecycleListener都必须非常轻量级,否则分布式跟踪可能会成为高吞吐量服务的主要瓶颈。如果需要在SpanLifecycleListener中完成任何昂贵的工作,那么应该在与应用程序工作线程分离的线程或线程池中异步完成。

代码示例

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

@Test
public void spanLifecycleListener_spanStarted_is_called_when_new_request_span_is_started() {
  // given
  SpanLifecycleListener listener1 = mock(SpanLifecycleListener.class);
  SpanLifecycleListener listener2 = mock(SpanLifecycleListener.class);
  Tracer tracer = Tracer.getInstance();
  tracer.addSpanLifecycleListener(listener1);
  tracer.addSpanLifecycleListener(listener2);
  // when
  Span span = tracer.startRequestWithRootSpan("newspan");
  // then
  verify(listener1).spanStarted(span);
  verify(listener1, times(0)).spanCompleted(span);
  verify(listener2).spanStarted(span);
  verify(listener2, times(0)).spanCompleted(span);
}

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

@Test
public void spanLifecycleListener_spanStarted_is_called_when_subspan_is_started() {
  // given
  SpanLifecycleListener listener1 = mock(SpanLifecycleListener.class);
  SpanLifecycleListener listener2 = mock(SpanLifecycleListener.class);
  Tracer tracer = Tracer.getInstance();
  tracer.addSpanLifecycleListener(listener1);
  tracer.addSpanLifecycleListener(listener2);
  tracer.startRequestWithRootSpan("newspan");
  // when
  Span subspan = tracer.startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  // then
  verify(listener1).spanStarted(subspan);
  verify(listener1, times(0)).spanCompleted(subspan);
  verify(listener2).spanStarted(subspan);
  verify(listener2, times(0)).spanCompleted(subspan);
}

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

@Test
public void getSpanLifecycleListeners_returns_unmodifiable_list() {
  // given
  SpanLifecycleListener listener = mock(SpanLifecycleListener.class);
  Tracer.getInstance().addSpanLifecycleListener(listener);
  // when
  List<SpanLifecycleListener> returnedList = Tracer.getInstance().getSpanLifecycleListeners();
  // then
  Exception caughtEx = null;
  try {
    returnedList.add(mock(SpanLifecycleListener.class));
  }
  catch(Exception ex) {
    caughtEx = ex;
  }
  assertThat(caughtEx).isNotNull();
  assertThat(caughtEx).isInstanceOf(UnsupportedOperationException.class);
}

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

/**
 * Initialize configuration.
 * Add Zipkin listener if our {@link WingtipsZipkinProperties} indicates it has the necessary properties specified.
 */
private void init() {
  if (wingtipsZipkinProperties.shouldApplyWingtipsToZipkinLifecycleListener()) {
    Tracer.getInstance().addSpanLifecycleListener(
      new WingtipsToZipkinLifecycleListener(
        wingtipsZipkinProperties.getServiceName(),
        wingtipsZipkinProperties.getLocalComponentNamespace(),
        wingtipsZipkinProperties.getBaseUrl()
      )
    );
  }
}

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

@Test
public void addSpanLifecycleListener_should_work_as_advertised() {
  // given
  SpanLifecycleListener listener = mock(SpanLifecycleListener.class);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).isEmpty();
  // when
  Tracer.getInstance().addSpanLifecycleListener(listener);
  // then
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).hasSize(1);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners().get(0)).isEqualTo(listener);
}

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

@Test
public void removeSpanLifecycleListener_should_work_as_advertised() {
  // given
  SpanLifecycleListener listener = mock(SpanLifecycleListener.class);
  Tracer.getInstance().addSpanLifecycleListener(listener);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).hasSize(1);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners().get(0)).isEqualTo(listener);
  // when
  boolean result = Tracer.getInstance().removeSpanLifecycleListener(listener);
  // then
  assertThat(result).isTrue();
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).isEmpty();
}

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

@Test
public void removeSpanLifecycleListener_should_return_false_and_do_nothing_if_passed_null() {
  // given
  SpanLifecycleListener listener = mock(SpanLifecycleListener.class);
  Tracer.getInstance().addSpanLifecycleListener(listener);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).hasSize(1);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners().get(0)).isEqualTo(listener);
  // when
  boolean result = Tracer.getInstance().removeSpanLifecycleListener(null);
  // then
  assertThat(result).isFalse();
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).hasSize(1);
  assertThat(Tracer.getInstance().getSpanLifecycleListeners().get(0)).isEqualTo(listener);
}

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

@Before
public void beforeMethod() {
  clearTracerSpanLifecycleListeners();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  resetTracing();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  removeSpanRecorderLifecycleListener();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  clearTracerSpanLifecycleListeners();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  resetTracing();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  clearTracerSpanLifecycleListeners();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  clearTracerSpanLifecycleListeners();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  clearTracerSpanLifecycleListeners();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  clearTracerSpanLifecycleListeners();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Before
public void beforeMethod() {
  resetTracing();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

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

@Test
public void addSpanLifecycleListener_should_do_nothing_if_passed_null() {
  // given
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).isEmpty();
  // when
  Tracer.getInstance().addSpanLifecycleListener(null);
  // then
  assertThat(Tracer.getInstance().getSpanLifecycleListeners()).isEmpty();
}

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

@Before
public void beforeMethod() {
  resetTracing();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
  dtConfigAdjustments = new DtConfigAdjustments();
  adjustableServerTaggingStrategy.config = dtConfigAdjustments;
  adjustableProxyTaggingStrategy.config = dtConfigAdjustments;
}

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

private void resetTracing() {
  MDC.clear();
  Tracer.getInstance().unregisterFromThread();
  removeSpanRecorderLifecycleListener();
  spanRecorder = new SpanRecorder();
  Tracer.getInstance().addSpanLifecycleListener(spanRecorder);
}

相关文章