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

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

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

Tracer.startRequestWithChildSpan介绍

[英]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 #startRequestWithRootSpan(String) or #startRequestWithRootSpan(String,String) instead). The newly created child span will have a span purpose of SpanPurpose#SERVER.

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.
[中]启动一个新的span堆栈(即新的传入请求),将给定的span作为新的子span的父span(如果没有父span,则应调用#startRequestWithRootSpan(String)或#startRequestWithRootSpan(String,String)。新创建的子span的span purpose为span purpose#SERVER。
警告:这将清除该线程的跨度堆栈上的所有现有跨度,并重新开始,因此,只有在预期跨度堆栈应为空时,才应在请求的入口点调用它。如果您需要在某个请求的中间启动一个子跨度,那么您应该调用SysString子String(String,SabVAIL)。

代码示例

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

/**
 * @param request The incoming request.
 * @return A new {@link Span} for the overall request. This inspects the incoming request's headers to determine
 * if it should continue an existing trace with a child span, or whether a brand new trace needs to be started.
 * {@link #getInitialSpanName(HttpServletRequest, HttpTagAndSpanNamingStrategy, HttpTagAndSpanNamingAdapter)}
 * is used to generate the initial span name.
 */
protected Span createNewSpanForRequest(HttpServletRequest request) {
  // See if there's trace info in the incoming request's headers. If so it becomes the parent trace.
  Tracer tracer = Tracer.getInstance();
  final Span parentSpan = HttpSpanFactory.fromHttpServletRequest(request, getUserIdHeaderKeys());
  Span newSpan;
  if (parentSpan != null) {
    logger.debug("Found parent Span {}", parentSpan);
    newSpan = tracer.startRequestWithChildSpan(
      parentSpan,
      getInitialSpanName(request, tagAndNamingStrategy, tagAndNamingAdapter)
    );
  }
  else {
    newSpan = tracer.startRequestWithRootSpan(
      getInitialSpanName(request, tagAndNamingStrategy, tagAndNamingAdapter),
      HttpSpanFactory.getUserIdFromHttpServletRequest(request, getUserIdHeaderKeys())
    );
    logger.debug("Parent span not found, starting a new span {}", newSpan);
  }
  return newSpan;
}

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

@Test(expected = IllegalArgumentException.class)
public void startRequestWithChildSpan_throws_IllegalArgumentException_if_passed_null_parent() {
  // expect
  Tracer.getInstance().startRequestWithChildSpan(null, "somechildspan");
  fail("Expected IllegalArgumentException but no exception was thrown");
}

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

@Test
public void startRequestWithChildSpan_wipes_out_any_existing_spans_on_the_stack() {
  // given: Tracer already has some Spans on the stack, and we have a parent span we're going to use
  Tracer.getInstance().startRequestWithRootSpan("span1");
  Tracer.getInstance().startSubSpan("span2", SpanPurpose.LOCAL_ONLY);
  assertThat(getSpanStackSize()).isEqualTo(2);
  Span newSpanParent = Span.generateRootSpanForNewTrace("parentspan", SpanPurpose.CLIENT).build();
  // when: Tracer.startRequestWithChildSpan(Span, String) is called to start a span with a parent
  Tracer.getInstance().startRequestWithChildSpan(newSpanParent, "childspan");
  // then: a new span is started that has the given parent, and the other spans on the stack are removed
  assertThat(getSpanStackSize()).isEqualTo(1);
  Span span = Tracer.getInstance().getCurrentSpan();
  assertThat(span).isNotNull();
  assertThat(span.getSpanName()).isEqualTo("childspan");
}

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

Tracer.getInstance().startRequestWithChildSpan(parentSpan, "childspan");
long afterNanoTime = System.nanoTime();
long afterEpochMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());

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

Tracer.getInstance().startRequestWithChildSpan(parentSpan, "childspan");
long afterNanoTime = System.nanoTime();
long afterEpochMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());

代码示例来源:origin: com.nike.riposte/riposte-core

if (parentSpan != null) {
  logger.debug("Found Parent Span {}", parentSpan.toString());
  newSpan = tracer.startRequestWithChildSpan(
    parentSpan,
    getFallbackSpanName(nettyRequest)

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

if (parentSpan != null) {
  logger.debug("Found Parent Span {}", parentSpan.toString());
  newSpan = tracer.startRequestWithChildSpan(
    parentSpan,
    getFallbackSpanName(nettyRequest)

相关文章