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

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

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

Tracer.startRequestWithSpanInfo介绍

[英]Starts a new span stack (i.e. new incoming request) with the given span info used to create the new span. This method is agnostic on whether the span is a root span or child span - the arguments you pass in (specifically the value of parentSpanId) will determine root vs child. The other startRequestWith...() methods should be preferred to this where it makes sense, but if your use case doesn't match those methods then this method allows maximum flexibility in creating a span for a new request.

WARNING: This wipes out any existing spans on the span stack for this thread and starts fresh, therefore this should only be called at the request's entry point when it's expected that the span stack should be empty. If you need to start a child span in the middle of a request somewhere then you should call #startSubSpan(String,SpanPurpose) instead.
[中]使用用于创建新跨度的给定跨度信息启动新的跨度堆栈(即新的传入请求)。该方法不确定跨度是根跨度还是子跨度——您传入的参数(特别是parentSpanId的值)将决定根跨度还是子跨度。另一位明星问。。。()在有意义的情况下,应该优先使用方法,但如果您的用例与这些方法不匹配,那么这种方法允许在为新请求创建范围时具有最大的灵活性。
警告:这将清除该线程的跨度堆栈上的所有现有跨度,并重新开始,因此,只有在预期跨度堆栈应为空时,才应在请求的入口点调用它。如果您需要在某个请求的中间启动一个子跨度,那么您应该调用SysString子String(String,SabVAIL)。

代码示例

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

/**
 * Starts a new span stack (i.e. new incoming request) with the given span as the new child span's parent (if you do not have a parent then you should call
 * {@link #startRequestWithRootSpan(String)} or {@link #startRequestWithRootSpan(String, String)} instead). The newly created child span will have a
 * span purpose of {@link SpanPurpose#SERVER}.
 * <p/>
 * <b>WARNING:</b> This wipes out any existing spans on the span stack for this thread and starts fresh, therefore this should only be called at the request's
 * entry point when it's expected that the span stack should be empty. If you need to start a child span in the middle of a request somewhere then you should call
 * {@link #startSubSpan(String, SpanPurpose)} instead.
 *
 * @param parentSpan The span to use as the parent span - should never be null (if you need to start a span without a parent then call
 *                   {@link #startRequestWithRootSpan(String)} instead).
 * @param childSpanName The span name to use for the new child span - should never be null.
 * @return The new child span (which is now also the current one that will be returned by {@link #getCurrentSpan()}).
 */
public Span startRequestWithChildSpan(Span parentSpan, String childSpanName) {
  if (parentSpan == null) {
    throw new IllegalArgumentException("parentSpan cannot be null. " +
            "If you don't have a parent span then you should call one of the startRequestWithRootSpan(...) methods instead.");
  }
  return startRequestWithSpanInfo(parentSpan.getTraceId(), parentSpan.getSpanId(), childSpanName, parentSpan.isSampleable(), parentSpan.getUserId(),
                  SpanPurpose.SERVER);
}

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

return startRequestWithSpanInfo(null, null, spanName, sampleable, null, spanPurpose);

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

@Test
public void spanLifecycleListener_spanSampled_is_not_called_when_new_request_span_is_started_if_span_is_not_sampleable() {
  // 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.startRequestWithSpanInfo("t", "p", "n", false, "u", SpanPurpose.LOCAL_ONLY);
  // then
  verify(listener1).spanStarted(span);
  verify(listener1, times(0)).spanSampled(span);
  verify(listener1, times(0)).spanCompleted(span);
  verify(listener2).spanStarted(span);
  verify(listener2, times(0)).spanSampled(span);
  verify(listener2, times(0)).spanCompleted(span);
}

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

@Test
public void spanLifecycleListener_spanSampled_is_not_called_when_subspan_is_started_if_subspan_is_not_sampleable() {
  // given
  SpanLifecycleListener listener1 = mock(SpanLifecycleListener.class);
  SpanLifecycleListener listener2 = mock(SpanLifecycleListener.class);
  Tracer tracer = Tracer.getInstance();
  tracer.addSpanLifecycleListener(listener1);
  tracer.addSpanLifecycleListener(listener2);
  tracer.startRequestWithSpanInfo("t", "p", "n", false, "u", SpanPurpose.LOCAL_ONLY);
  // when
  Span subspan = tracer.startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  // then
  verify(listener1).spanStarted(subspan);
  verify(listener1, times(0)).spanSampled(subspan);
  verify(listener1, times(0)).spanCompleted(subspan);
  verify(listener2).spanStarted(subspan);
  verify(listener2, times(0)).spanSampled(subspan);
  verify(listener2, times(0)).spanCompleted(subspan);
}

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

@Test
public void spanLifecycleListener_spanSampled_is_called_when_new_request_span_is_started_if_span_is_sampleable() {
  // 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.startRequestWithSpanInfo("t", "p", "n", true, "u", SpanPurpose.LOCAL_ONLY);
  // then
  verify(listener1).spanStarted(span);
  verify(listener1).spanSampled(span);
  verify(listener1, times(0)).spanCompleted(span);
  verify(listener2).spanStarted(span);
  verify(listener2).spanSampled(span);
  verify(listener2, times(0)).spanCompleted(span);
}

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

@Test
public void spanLifecycleListener_spanSampled_is_called_when_subspan_is_started_if_subspan_is_sampleable() {
  // given
  SpanLifecycleListener listener1 = mock(SpanLifecycleListener.class);
  SpanLifecycleListener listener2 = mock(SpanLifecycleListener.class);
  Tracer tracer = Tracer.getInstance();
  tracer.addSpanLifecycleListener(listener1);
  tracer.addSpanLifecycleListener(listener2);
  tracer.startRequestWithSpanInfo("t", "p", "n", true, "u", SpanPurpose.LOCAL_ONLY);
  // when
  Span subspan = tracer.startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  // then
  verify(listener1).spanStarted(subspan);
  verify(listener1).spanSampled(subspan);
  verify(listener1, times(0)).spanCompleted(subspan);
  verify(listener2).spanStarted(subspan);
  verify(listener2).spanSampled(subspan);
  verify(listener2, times(0)).spanCompleted(subspan);
}

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

long beforeEpochMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
@SuppressWarnings("ConstantConditions")
Span span = Tracer.getInstance().startRequestWithSpanInfo(traceId, parentSpanId, spanName, sampleable, userId, spanPurpose);
long afterNanoTime = System.nanoTime();
long afterEpochMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());

相关文章