本文整理了Java中com.nike.wingtips.Tracer.startRequestWithRootSpan()
方法的一些代码示例,展示了Tracer.startRequestWithRootSpan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.startRequestWithRootSpan()
方法的具体详情如下:
包路径:com.nike.wingtips.Tracer
类名称:Tracer
方法名:startRequestWithRootSpan
[英]Starts new span stack (i.e. new incoming request) without a parent span by creating a root span with the given span name. If you have parent span info then you should call #startRequestWithChildSpan(Span,String) or #startRequestWithSpanInfo(String,String,String,boolean,String,SpanPurpose) instead). The newly created root span will have a span purpose of SpanPurpose#SERVER.
NOTE: This method will cause the returned span's Span#getUserId() to contain null. If you have a user ID you should use #startRequestWithRootSpan(String,String) instead.
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信息,那么您应该调用#startRequestWithChildSpan(span,String)或#startrequestwithspan信息(String,String,String,boolean,String,SpanPurpose)。新创建的根span的span purpose为span purpose#SERVER。
注意:此方法将导致返回的span的span#getUserId()包含null。如果您有用户ID,则应使用#startRequestWithRootSpan(String,String)。
警告:这将清除该线程的跨度堆栈上的所有现有跨度,并重新开始,因此,只有在预期跨度堆栈应为空时,才应在请求的入口点调用它。如果您需要在某个请求的中间启动一个子跨度,那么您应该调用SysString子String(String,SabVAIL)。
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void getCurrentSpan_should_return_current_span() throws Exception {
// given
Tracer tracer = Tracer.getInstance();
tracer.startRequestWithRootSpan("test-span");
// when
Span span = tracer.getCurrentSpan();
// then
assertThat(span).isNotNull();
assertThat(span.getSpanName()).isEqualTo("test-span");
}
代码示例来源:origin: Nike-Inc/wingtips
private TracingState generateTracingStateOnCurrentThread() {
Tracer.getInstance().startRequestWithRootSpan(UUID.randomUUID().toString());
Tracer.getInstance().startSubSpan(UUID.randomUUID().toString(), Span.SpanPurpose.LOCAL_ONLY);
return TracingState.getCurrentThreadTracingState();
}
代码示例来源:origin: Nike-Inc/wingtips
private TracingState generateTracingStateOnCurrentThread() {
Tracer.getInstance().startRequestWithRootSpan(UUID.randomUUID().toString());
Tracer.getInstance().startSubSpan(UUID.randomUUID().toString(), SpanPurpose.LOCAL_ONLY);
return TracingState.getCurrentThreadTracingState();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test(expected = IllegalArgumentException.class)
public void starting_a_request_with_null_span_name_should_throw_IllegalArgumentException() {
// expect
Tracer.getInstance().startRequestWithRootSpan(null);
fail("Expected IllegalArgumentException but no exception was thrown");
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void getCurrentTracerManagedSpanStatus_works_as_expected_for_managed_noncurrent() {
// given
Span nonCurrentRootSpan = Tracer.getInstance().startRequestWithRootSpan("root");
Span nonCurrentSubspan = Tracer.getInstance().startSubSpan("subspan1", SpanPurpose.LOCAL_ONLY);
Span currentSubspan = Tracer.getInstance().startSubSpan("subspan2", SpanPurpose.LOCAL_ONLY);
// expect
assertThat(nonCurrentRootSpan.getCurrentTracerManagedSpanStatus())
.isEqualTo(TracerManagedSpanStatus.MANAGED_NON_CURRENT_ROOT_SPAN);
assertThat(nonCurrentSubspan.getCurrentTracerManagedSpanStatus())
.isEqualTo(TracerManagedSpanStatus.MANAGED_NON_CURRENT_SUB_SPAN);
}
代码示例来源: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
@Test
public void getCurrentTracerManagedSpanStatus_works_as_expected_for_unmanaged() {
// given
Span manuallyCreatedSpan = Span.newBuilder("manuallyCreatedSpan", SpanPurpose.LOCAL_ONLY).build();
Span completedSpan = Tracer.getInstance().startRequestWithRootSpan("completedSpan");
Tracer.getInstance().completeRequestSpan();
// when
TracerManagedSpanStatus tmssManual = manuallyCreatedSpan.getCurrentTracerManagedSpanStatus();
TracerManagedSpanStatus tmssCompleted = completedSpan.getCurrentTracerManagedSpanStatus();
// then
assertThat(tmssManual).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
assertThat(tmssCompleted).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
}
代码示例来源: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
@Test
public void close_completes_the_span_as_expected_overall_request_span() {
// given
Span overallSpan = Tracer.getInstance().startRequestWithRootSpan("root");
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(overallSpan);
assertThat(overallSpan.isCompleted()).isFalse();
// when
overallSpan.close();
// then
assertThat(overallSpan.isCompleted()).isTrue();
assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
}
代码示例来源: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
@Test
public void handleSpanCloseMethod_completes_the_span_as_expected_overall_request_span() {
// given
Span overallSpan = Tracer.getInstance().startRequestWithRootSpan("root");
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(overallSpan);
assertThat(overallSpan.isCompleted()).isFalse();
// when
Tracer.getInstance().handleSpanCloseMethod(overallSpan);
// then
assertThat(overallSpan.isCompleted()).isTrue();
assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void getCurrentManagedStatusForSpan_works_as_expected_for_managed_noncurrent() {
// given
Span nonCurrentRootSpan = Tracer.getInstance().startRequestWithRootSpan("root");
Span nonCurrentSubspan = Tracer.getInstance().startSubSpan("subspan1", SpanPurpose.LOCAL_ONLY);
Span currentSubspan = Tracer.getInstance().startSubSpan("subspan2", SpanPurpose.LOCAL_ONLY);
// expect
assertThat(Tracer.getInstance().getCurrentManagedStatusForSpan(nonCurrentRootSpan))
.isEqualTo(TracerManagedSpanStatus.MANAGED_NON_CURRENT_ROOT_SPAN);
assertThat(Tracer.getInstance().getCurrentManagedStatusForSpan(nonCurrentSubspan))
.isEqualTo(TracerManagedSpanStatus.MANAGED_NON_CURRENT_SUB_SPAN);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void close_completes_the_span_as_expected_subspan() {
// given
Span parentSpan = Tracer.getInstance().startRequestWithRootSpan("root");
Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(subspan);
assertThat(subspan.isCompleted()).isFalse();
// when
subspan.close();
// then
assertThat(subspan.isCompleted()).isTrue();
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(parentSpan);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void getCurrentManagedStatusForSpan_works_as_expected_for_unmanaged() {
// given
Span manuallyCreatedSpan = Span.newBuilder("manuallyCreatedSpan", SpanPurpose.LOCAL_ONLY).build();
Span completedSpan = Tracer.getInstance().startRequestWithRootSpan("completedSpan");
Tracer.getInstance().completeRequestSpan();
// when
TracerManagedSpanStatus tmssManual = Tracer.getInstance().getCurrentManagedStatusForSpan(manuallyCreatedSpan);
TracerManagedSpanStatus tmssCompleted = Tracer.getInstance().getCurrentManagedStatusForSpan(completedSpan);
// then
assertThat(tmssManual).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
assertThat(tmssCompleted).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void handleSpanCloseMethod_completes_the_span_as_expected_subspan() {
// given
Span parentSpan = Tracer.getInstance().startRequestWithRootSpan("root");
Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(subspan);
assertThat(subspan.isCompleted()).isFalse();
// when
Tracer.getInstance().handleSpanCloseMethod(subspan);
// then
assertThat(subspan.isCompleted()).isTrue();
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(parentSpan);
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!