本文整理了Java中com.nike.wingtips.Span.close()
方法的一些代码示例,展示了Span.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.close()
方法的具体详情如下:
包路径:com.nike.wingtips.Span
类名称:Span
方法名:close
[英]Handles the implementation of Closeable#close() for spans to allow them to be used in try-with-resources statements or other libraries that work with Closeable objects.
If this span is already completed ( #isCompleted() returns true) then an error will be logged and nothing will be done.
If this span is the current span ( Tracer#getCurrentSpan() equals the given span), then Tracer#completeRequestSpan() or Tracer#completeSubSpan() will be called, whichever is appropriate.
If this span is not the current span ( Tracer#getCurrentSpan() does not equal this span), then this may or may not be an error depending on whether this span is managed by Tracer or not.
If this span is managed by Tracer (i.e. it is contained in the span stack somewhere even though it's not the current span) then this is a wingtips usage error - this span should not be completed yet - and an error will be logged and this span will be completed and logged to the "invalid span logger".
代码示例来源:origin: Nike-Inc/wingtips
@Override
public void process(HttpResponse response, HttpContext context) {
// See if there's a subspan passed to us from the request interceptor.
Span spanToClose = (Span) context.getAttribute(SPAN_TO_CLOSE_HTTP_CONTEXT_ATTR_KEY);
if (spanToClose != null) {
// There was a subspan. Finalize and close it.
try {
// Handle response/error tagging and final span name.
// The request should be found in the context attributes - try to extract it from there.
// We have no access to any error, so we pass null for the error arg.
HttpRequest request = null;
Object requestRawObj = context.getAttribute(HttpCoreContext.HTTP_REQUEST);
if (requestRawObj instanceof HttpRequest) {
request = (HttpRequest) requestRawObj;
}
tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName(
spanToClose, request, response, null, tagAndNamingAdapter
);
} finally {
// Span.close() contains the logic we want - if the spanToClose was an overall span (new trace)
// then tracer.completeRequestSpan() will be called, otherwise it's a subspan and
// tracer.completeSubSpan() will be called.
spanToClose.close();
}
}
}
代码示例来源:origin: com.nike.wingtips/wingtips-spring
@Override
public void run() {
Span span = Tracer.getInstance().getCurrentSpan();
//noinspection TryFinallyCanBeTryWithResources
try {
// Add the tags from the response.
tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName(
span, request, response, error, tagAndNamingAdapter
);
}
finally {
// Span.close() contains the logic we want - if the spanAroundCall was an overall span
// (new trace) then tracer.completeRequestSpan() will be called, otherwise it's
// a subspan and tracer.completeSubSpan() will be called.
span.close();
}
}
},
代码示例来源:origin: Nike-Inc/wingtips
@Override
public void run() {
Span span = Tracer.getInstance().getCurrentSpan();
//noinspection TryFinallyCanBeTryWithResources
try {
// Add the tags from the response.
tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName(
span, request, response, error, tagAndNamingAdapter
);
}
finally {
// Span.close() contains the logic we want - if the spanAroundCall was an overall span
// (new trace) then tracer.completeRequestSpan() will be called, otherwise it's
// a subspan and tracer.completeSubSpan() will be called.
span.close();
}
}
},
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void process_response_closes_span_no_matter_what() {
// given
Span spanMock = mock(Span.class);
httpContext = spy(httpContext);
httpContext.setAttribute(SPAN_TO_CLOSE_HTTP_CONTEXT_ATTR_KEY, spanMock);
RuntimeException expectedEx = new RuntimeException("boom");
doThrow(expectedEx).when(httpContext).getAttribute(HttpCoreContext.HTTP_REQUEST);
// when
Throwable ex = catchThrowable(() -> interceptor.process(responseMock, httpContext));
// then
assertThat(ex).isSameAs(expectedEx);
verify(httpContext).getAttribute(HttpCoreContext.HTTP_REQUEST);
verify(spanMock).close();
}
代码示例来源:origin: Nike-Inc/riposte
spanAroundCall.close();
代码示例来源:origin: Nike-Inc/riposte
spanAroundCall.close();
代码示例来源:origin: Nike-Inc/wingtips
);
verify(spanMock).close();
代码示例来源: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
@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
spanAroundCall.close();
代码示例来源:origin: Nike-Inc/wingtips
parent.close();
代码示例来源:origin: Nike-Inc/wingtips
spanAroundCall.close();
代码示例来源:origin: com.nike.wingtips/wingtips-spring
spanAroundCall.close();
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void close_does_nothing_if_span_is_already_completed() {
// given
Span rootSpan = Tracer.getInstance().startRequestWithRootSpan("root");
Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
Tracer.getInstance().completeSubSpan();
assertThat(subspan.isCompleted()).isTrue();
assertThat(rootSpan.isCompleted()).isFalse();
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(rootSpan);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(singletonList(rootSpan));
// when
subspan.close();
// then
assertThat(rootSpan.isCompleted()).isFalse();
assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(rootSpan);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(singletonList(rootSpan));
}
代码示例来源:origin: Nike-Inc/wingtips
parent.close();
代码示例来源:origin: Nike-Inc/wingtips
parent.close();
代码示例来源:origin: Nike-Inc/wingtips
parent.close();
代码示例来源:origin: Nike-Inc/wingtips
parentSpan.close();
subspan1.close();
代码示例来源:origin: Nike-Inc/wingtips
invalidSpan.close();
内容来源于网络,如有侵权,请联系作者删除!