本文整理汇总了Java中io.opentracing.ActiveSpan.deactivate方法的典型用法代码示例。如果您正苦于以下问题:Java ActiveSpan.deactivate方法的具体用法?Java ActiveSpan.deactivate怎么用?Java ActiveSpan.deactivate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.opentracing.ActiveSpan
的用法示例。
在下文中一共展示了ActiveSpan.deactivate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
}
示例3: 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();
}
示例4: 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());
}
示例5: 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
示例6: testWithTags
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
@Test
public void testWithTags() {
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
ActiveSpan parent = metricsTracer.buildSpan("parent")
.withTag("booleanTag", true)
.withTag("numericTag", new Integer(100))
.startActive();
parent.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(1, spans.size());
MockSpan span = spans.get(0);
Map<String, Object> tags = span.tags();
Object booleanTag = tags.get("booleanTag");
assertNotNull("Expected a tag named 'booleanTag'", booleanTag);
assertTrue("booleanTag should be a Boolean", booleanTag instanceof Boolean);
assertEquals("booleanTag should be true", true, booleanTag);
Object numericTag = tags.get("numericTag");
assertNotNull("Expected a tag named 'numericTag'", numericTag);
assertTrue("numericTag should be a Number", numericTag instanceof Number);
assertEquals("numericTag should be 100", 100, numericTag);
}
示例7: testAsChildOf
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
@Test
public void testAsChildOf() {
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
ActiveSpan parentSpan = metricsTracer.buildSpan("parent")
.withTag("spanName","parent")
.startActive();
parentSpan.setTag("additionalTag", "parent");
ActiveSpan childSpan = metricsTracer.buildSpan("child")
.asChildOf(parentSpan)
.withTag("spanName","child")
.startActive();
childSpan.setTag("additionalTag", "child");
childSpan.deactivate();
parentSpan.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(2, spans.size());
MockSpan span1 = spans.get(0);
MockSpan span2 = spans.get(1);
MockSpan parent, child;
if (span1.operationName().equals("parent")) {
parent = span1;
child = span2;
} else {
parent = span2;
child = span1;
}
assertEquals("Child's parent id should be spanId of parent", child.parentId(), parent.context().spanId());
assertEquals(0, parent.parentId());
}
示例8: execute
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
@Override
public CloseableHttpResponse execute(
HttpRoute route,
HttpRequestWrapper request,
HttpClientContext clientContext,
HttpExecutionAware execAware) throws IOException, HttpException {
ActiveSpan localSpan = clientContext.getAttribute(ACTIVE_SPAN, ActiveSpan.class);
CloseableHttpResponse response = null;
try {
if (localSpan == null) {
localSpan = handleLocalSpan(request, clientContext);
}
return (response = handleNetworkProcessing(localSpan, route, request, clientContext, execAware));
} catch (Exception e) {
localSpan.deactivate();
throw e;
} finally {
if (response != null) {
/**
* This exec runs after {@link org.apache.http.impl.execchain.RedirectExec} which loops
* until there is no redirect or reaches max redirect count.
* {@link RedirectStrategy} is used to decide whether localSpan should be finished or not.
* If there is a redirect localSpan is not finished and redirect is logged.
*/
Integer redirectCount = clientContext.getAttribute(REDIRECT_COUNT, Integer.class);
if (!redirectHandlingDisabled &&
clientContext.getRequestConfig().isRedirectsEnabled() &&
redirectStrategy.isRedirected(request, response, clientContext) &&
++redirectCount < clientContext.getRequestConfig().getMaxRedirects()) {
clientContext.setAttribute(REDIRECT_COUNT, redirectCount);
} else {
localSpan.deactivate();
}
}
}
}
示例9: deactivateWithoutFinish
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
private void deactivateWithoutFinish() {
ActiveSpan activeSpan = tracer.activeSpan();
// for async requests this is executed in a different thread than requestFilter
if (activeSpan != null) {
// hack capture to prevent finish - it's finished in filter
activeSpan.capture();
activeSpan.deactivate();
}
}
示例10: testStandardUsage
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
@Test
public void testStandardUsage() {
Map<String,Object> sysTags = new HashMap<String,Object>();
sysTags.put("service", "TestService");
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
ActiveSpan parent = metricsTracer.buildSpan("parent").withTag("spanName","parent").startActive();
parent.setTag("additionalTag", "parent");
ActiveSpan child = metricsTracer.buildSpan("child").withTag("spanName","child").startActive();
child.setTag("additionalTag", "child");
// Test ref counting works fine
ActiveSpan child2 = child.capture().activate();
child2.deactivate();
// Still should be ref to child span
assertEquals(0, tracer.finishedSpans().size());
child.deactivate();
assertEquals(1, tracer.finishedSpans().size());
parent.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(2, spans.size());
Mockito.verify(reporter, Mockito.times(2)).reportSpan(spanDataCaptor.capture());
List<SpanData> captured = spanDataCaptor.getAllValues();
assertEquals(captured.size(), spans.size());
for (int i=0; i < spans.size(); i++) {
MockSpan span = spans.get(i);
assertEquals(span.operationName(), span.tags().get("spanName"));
assertEquals(span.operationName(), span.tags().get("additionalTag"));
}
assertTrue(captured.get(0).getDuration() < captured.get(1).getDuration());
assertEquals("child", captured.get(0).getOperationName());
assertEquals("parent", captured.get(1).getOperationName());
assertEquals(tracer.finishedSpans().get(0).tags(), captured.get(0).getTags());
assertEquals(tracer.finishedSpans().get(1).tags(), captured.get(1).getTags());
}
示例11: testStandardUsage
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
@Test
public void testStandardUsage() {
Map<String,Object> sysTags = new HashMap<String,Object>();
sysTags.put("service", "TestService");
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
ActiveSpan parent = metricsTracer.buildSpan("parent").withTag("spanName","parent").startActive();
parent.setTag("additionalTag", "parent");
ActiveSpan child = metricsTracer.buildSpan("child").withTag("spanName","child").startActive();
child.setTag("additionalTag", "child");
// Test ref counting works fine
ActiveSpan child2 = child.capture().activate();
child2.deactivate();
// Still should be ref to child span
assertEquals(0, tracer.finishedSpans().size());
child.deactivate();
assertEquals(1, tracer.finishedSpans().size());
parent.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(2, spans.size());
Mockito.verify(reporter, Mockito.times(2)).reportSpan(spanCaptor.capture(), operationCaptor.capture(),
tagsCaptor.capture(), durationCaptor.capture());
List<BaseSpan<?>> capturedSpans = spanCaptor.getAllValues();
assertEquals(capturedSpans.size(), spans.size());
for (int i=0; i < spans.size(); i++) {
MockSpan span = spans.get(i);
assertEquals(span.operationName(), span.tags().get("spanName"));
assertEquals(span.operationName(), span.tags().get("additionalTag"));
assertEquals(span.context(), capturedSpans.get(i).context());
}
assertEquals(Arrays.asList("child","parent"), operationCaptor.getAllValues());
assertTrue(durationCaptor.getAllValues().get(0) < durationCaptor.getAllValues().get(1));
assertEquals(tracer.finishedSpans().get(0).tags(), tagsCaptor.getAllValues().get(0));
assertEquals(tracer.finishedSpans().get(1).tags(), tagsCaptor.getAllValues().get(1));
}
示例12: sayHello
import io.opentracing.ActiveSpan; //导入方法依赖的package包/类
public void sayHello(String name) throws SQLException {
Tracer tracer = TracerFactory.getTracer();
ActiveSpan span = tracer.buildSpan("GreetService/sayHello/" + name).startActive();
String remoteResponse = new RestTemplate().getForObject("http://localhost:18081/project-B/remote/" + name, String.class);
logger.info("remote response: {}", remoteResponse);
span.deactivate();
}