本文整理汇总了Java中io.opentracing.ActiveSpan类的典型用法代码示例。如果您正苦于以下问题:Java ActiveSpan类的具体用法?Java ActiveSpan怎么用?Java ActiveSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActiveSpan类属于io.opentracing包,在下文中一共展示了ActiveSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithStartTimestamp
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testWithStartTimestamp() throws InterruptedException {
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
long start = System.currentTimeMillis() * 687;
Thread.sleep(100);
ActiveSpan parent = metricsTracer.buildSpan("parent")
.withStartTimestamp(start)
.startActive();
parent.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(1, spans.size());
MockSpan span = spans.get(0);
long started = span.startMicros();
assertEquals(start, started);
}
示例2: start
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Override
@SuppressWarnings("try")
public ServiceHost start() throws Throwable {
// Trace the local startup process
try (ActiveSpan activeSpan = this.getTracer().buildSpan("TestTracingHost.start").startActive()) {
// Will nest under our span
super.start();
// Start core services, must be done once - note that this traces internally
startDefaultCoreServicesSynchronously();
// Start the root namespace service: this will list all available factory services for
// queries to the root (/)
try (ActiveSpan nsSpan = this.getTracer().buildSpan("startNamespace").startActive()) {
super.startService(new RootNamespaceService());
}
try (ActiveSpan exampleSpan = this.getTracer().buildSpan("startExampleServices").startActive()) {
// Start example services
//startFactory(new ExampleService());
//startFactory(new ExampleTaskService());
startFactory(new TestStatefulService());
startService(new TestStatelessService());
}
}
return this;
}
示例3: afterConcurrentHandlingStarted
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Override
public void afterConcurrentHandlingStarted (
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler)
throws Exception {
if (!isTraced(httpServletRequest)) {
return;
}
Deque<ActiveSpan> activeSpanStack = getActiveSpanStack(httpServletRequest);
ActiveSpan activeSpan = activeSpanStack.pop();
for (HandlerInterceptorSpanDecorator decorator : decorators) {
decorator.onAfterConcurrentHandlingStarted(httpServletRequest, httpServletResponse, handler, activeSpan);
}
activeSpan.deactivate();
httpServletRequest.setAttribute(CONTINUATION_FROM_ASYNC_STARTED, activeSpan.capture());
}
示例4: afterCompletion
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Override
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
Object handler, Exception ex) throws Exception {
if (!isTraced(httpServletRequest)) {
return;
}
Deque<ActiveSpan> activeSpanStack = getActiveSpanStack(httpServletRequest);
ActiveSpan activeSpan = activeSpanStack.pop();
for (HandlerInterceptorSpanDecorator decorator : decorators) {
decorator.onAfterCompletion(httpServletRequest, httpServletResponse, handler, ex, activeSpan);
}
activeSpan.deactivate();
}
示例5: testParentSpan
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testParentSpan() {
{
ActiveSpan parent = mockTracer.buildSpan("parent").startActive();
String url = "http://localhost/foo";
mockServer.expect(MockRestRequestMatchers.requestTo(url))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess());
client.getForEntity(url, String.class);
parent.deactivate();
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
Assert.assertEquals(mockSpans.get(0).parentId(), mockSpans.get(1).context().spanId());
Assert.assertEquals(mockSpans.get(0).context().traceId(), mockSpans.get(1).context().traceId());
}
示例6: async
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@RequestMapping("/async")
public Callable<String> async() {
verifyActiveSpan();
final ActiveSpan.Continuation cont = tracer.activeSpan().capture();
return new Callable<String>() {
public String call() throws Exception {
try (ActiveSpan span = cont.activate()) {
if (tracer.activeSpan() == null) {
throw new RuntimeException("No active span");
}
Thread.sleep(1000);
return "async";
}
}
};
}
示例7: testActiveSpanPropagation
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testActiveSpanPropagation() {
ActiveSpan activeParent = tracer.buildSpan("active-span").startActive();
tracer.buildSpan("child-active-span").startActive().deactivate();
Assert.assertEquals("Haven't closed the parent", 1, dispatcher.getReportedSpans().size());
Assert.assertEquals(activeParent, tracer.activeSpan());
activeParent.close();
Assert.assertEquals("Parent closed", 2, dispatcher.getReportedSpans().size());
Span child = dispatcher.getReportedSpans().get(0);
Span parent = dispatcher.getReportedSpans().get(1);
Assert.assertEquals("Child should have a reference", 1, child.getReferences().size());
Assert.assertEquals(References.CHILD_OF, child.getReferences().get(0).getReferenceType());
Assert.assertEquals(parent.context(), child.getReferences().get(0).getContext());
Assert.assertEquals(parent.context().getTraceId(), child.context().getTraceId());
Assert.assertEquals(parent.context().getSpanId(), child.context().getParentId());
}
示例8: testActiveSpanIgnorePropagation
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testActiveSpanIgnorePropagation() {
try (ActiveSpan span = tracer.buildSpan("active-span").startActive()) {
tracer.buildSpan("independent-active-span").ignoreActiveSpan().startActive().deactivate();
}
Assert.assertEquals(dispatcher.getReportedSpans().size(), 2);
Span secondSpan = dispatcher.getReportedSpans().get(0);
Span firstSpan = dispatcher.getReportedSpans().get(1);
Assert.assertEquals(0, secondSpan.getReferences().size());
Assert.assertEquals(0, firstSpan.getReferences().size());
Assert.assertNotEquals(firstSpan.context().getTraceId(), secondSpan.context().getTraceId());
Assert.assertEquals(new UUID(0l, 0l), secondSpan.context().getParentId());
}
示例9: testActiveSpanPreSeeded
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testActiveSpanPreSeeded() {
ActiveSpan activeParent = tracer.buildSpan("active").startActive();
tracer.buildSpan("child").asChildOf(span).startActive().deactivate();
activeParent.close();
span.finish();
Assert.assertEquals("All spans closed", 3, dispatcher.getReportedSpans().size());
Span child = dispatcher.getReportedSpans().get(0);
Span active = dispatcher.getReportedSpans().get(1);
Span parent = dispatcher.getReportedSpans().get(2);
Assert.assertEquals("Child should have a reference", 1, child.getReferences().size());
Assert.assertEquals(References.CHILD_OF, child.getReferences().get(0).getReferenceType());
Assert.assertEquals(parent.context(), child.getReferences().get(0).getContext());
Assert.assertEquals(parent.context().getTraceId(), child.context().getTraceId());
Assert.assertEquals(parent.context().getSpanId(), child.context().getParentId());
Assert.assertTrue(parent.getReferences().isEmpty());
Assert.assertEquals(new UUID(0l, 0l), parent.context().getParentId());
Assert.assertTrue(active.getReferences().isEmpty());
Assert.assertEquals(new UUID(0l, 0l), active.context().getParentId());
}
示例10: testActiveParentSpan
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testActiveParentSpan() throws IOException {
{
ActiveSpan parentSpan = mockTracer.buildSpan("parent")
.startActive();
CloseableHttpClient client = clientBuilder.build();
client.execute(new HttpGet(serverUrl("/echo/a")));
parentSpan.deactivate();
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(3, mockSpans.size());
Assert.assertEquals(mockSpans.get(0).context().traceId(), mockSpans.get(1).context().traceId());
Assert.assertEquals(mockSpans.get(0).parentId(), mockSpans.get(1).context().spanId());
assertLocalSpan(mockSpans.get(1));
}
开发者ID:opentracing-contrib,项目名称:java-apache-httpclient,代码行数:21,代码来源:TracingHttpClientBuilderTest.java
示例11: testManualParentSpan
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testManualParentSpan() throws IOException {
MockSpan parent = mockTracer.buildSpan("parent")
.startManual();
{
ActiveSpan parentSpan = mockTracer.buildSpan("parent")
.startActive();
HttpContext context = new BasicHttpContext();
context.setAttribute(Constants.PARENT_CONTEXT, parent.context());
CloseableHttpClient client = clientBuilder.build();
client.execute(new HttpGet(serverUrl("/echo/a")), context);
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
Assert.assertEquals(parent.context().traceId(), mockSpans.get(1).context().traceId());
Assert.assertEquals(parent.context().spanId(), mockSpans.get(1).parentId());
assertLocalSpan(mockSpans.get(1));
}
开发者ID:opentracing-contrib,项目名称:java-apache-httpclient,代码行数:25,代码来源:TracingHttpClientBuilderTest.java
示例12: traceBackgroundThread
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
// operation name is method name
ActiveSpan activeSpan = tracer.buildSpan(pjp.getSignature().getName())
.withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
.withTag(ExtensionTags.CLASS_TAG.getKey(), pjp.getTarget().getClass().getSimpleName())
.withTag(ExtensionTags.METHOD_TAG.getKey(), pjp.getSignature().getName())
.startActive();
try {
return pjp.proceed();
} catch (Exception ex) {
SpanUtils.captureException(activeSpan, ex);
throw ex;
} finally {
activeSpan.close();
}
}
示例13: testWithoutCircuitBreaker
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testWithoutCircuitBreaker() throws Exception {
try (ActiveSpan span = mockTracer.buildSpan("test_without_circuit_breaker")
.startActive()) {
String response = greetingService.sayHello();
assertThat(response).isNotNull();
}
/**
* 2 spans totally
* <ul>
* <li>one that's started in test</li>
* <li>one that's added in sayHello method of Greeting Service</li>
* </ul>
*/
await().atMost(3, TimeUnit.SECONDS).until(() -> mockTracer.finishedSpans().size() == 2);
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertEquals(2, mockSpans.size());
TestUtils.assertSameTraceId(mockSpans);
MockSpan hystrixSpan = mockSpans.get(1);
assertThat(hystrixSpan.tags()).isEmpty();
}
示例14: testWithCircuitBreaker
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testWithCircuitBreaker() {
try (ActiveSpan span = mockTracer.buildSpan("test_with_circuit_breaker")
.startActive()) {
String response = greetingService.alwaysFail();
assertThat(response).isNotNull();
}
/**
* 3 spans totally
* <ul>
* <li>one thats started in test</li>
* <li>one thats added in alwaysFail method of Greeting Service</li>
* <li>one thats added in the defaultGreeting method which is a fallback</li>
* </ul>
*/
await().atMost(3, TimeUnit.SECONDS).until(() -> mockTracer.finishedSpans().size() == 3);
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertEquals(3, mockSpans.size());
TestUtils.assertSameTraceId(mockSpans);
MockSpan hystrixSpan = mockSpans.get(1);
assertThat(hystrixSpan.tags()).isNotEmpty();
//one thats added in the defaultGreeting method which is a fallback should have the custom tag added
assertThat(hystrixSpan.tags().get("fallback")).isEqualTo("yes");
}
示例15: testAsyncTraceAndSpans
import io.opentracing.ActiveSpan; //导入依赖的package包/类
@Test
public void testAsyncTraceAndSpans() throws Exception {
try (ActiveSpan span = mockTracer.buildSpan("bar")
.startActive()) {
Future<String> fut = asyncService.fooAsync();
await().until(() -> fut.isDone());
assertThat(fut.get()).isNotNull();
}
await().until(() -> mockTracer.finishedSpans().size() == 3);
List<MockSpan> mockSpans = mockTracer.finishedSpans();
// parent span from test, span modelling @Async, span inside @Async
assertEquals(3, mockSpans.size());
TestUtils.assertSameTraceId(mockSpans);
MockSpan asyncSpan = mockSpans.get(1);
assertEquals(3, asyncSpan.tags().size());
assertEquals(TraceAsyncAspect.TAG_COMPONENT, asyncSpan.tags().get(Tags.COMPONENT.getKey()));
assertEquals("fooAsync", asyncSpan.tags().get(ExtensionTags.METHOD_TAG.getKey()));
assertEquals(AsyncService.class.getSimpleName(),
asyncSpan.tags().get(ExtensionTags.CLASS_TAG.getKey()));
}