本文整理汇总了Java中io.opentracing.References类的典型用法代码示例。如果您正苦于以下问题:Java References类的具体用法?Java References怎么用?Java References使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
References类属于io.opentracing包,在下文中一共展示了References类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAndFinishChildSpan
import io.opentracing.References; //导入依赖的package包/类
private void buildAndFinishChildSpan(ConsumerRecord<K, V> record) {
SpanContext parentContext = TracingKafkaUtils.extract(record.headers(), tracer);
if (parentContext != null) {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan("receive")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
spanBuilder.addReference(References.FOLLOWS_FROM, parentContext);
Span span = spanBuilder.start();
SpanDecorator.onResponse(record, span);
span.finish();
// Inject created span context into record headers for extraction by client to continue span chain
TracingKafkaUtils.injectSecond(span.context(), record.headers(), tracer);
}
}
示例2: buildChildSpan
import io.opentracing.References; //导入依赖的package包/类
static Scope buildChildSpan(AMQP.BasicProperties props, Tracer tracer) {
SpanContext context = TracingUtils.extract(props, tracer);
if (context != null) {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan("receive")
.ignoreActiveSpan()
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER);
spanBuilder.addReference(References.FOLLOWS_FROM, context);
Scope scope = spanBuilder.startActive(true);
SpanDecorator.onResponse(scope.span());
return scope;
}
return null;
}
示例3: testActiveSpanPropagation
import io.opentracing.References; //导入依赖的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());
}
示例4: testActiveSpanPreSeeded
import io.opentracing.References; //导入依赖的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());
}
示例5: testReferences
import io.opentracing.References; //导入依赖的package包/类
@Test
public void testReferences() {
Span parent = tracer.buildSpan("parent").startManual();
Span following = tracer.buildSpan("following").startManual();
Span child = tracer.buildSpan("child")
.asChildOf(parent)
.addReference(References.FOLLOWS_FROM, following.context())
.startManual();
Assert.assertEquals(2, child.getReferences().size());
Assert.assertEquals(parent.context(), child.getReferences().get(0).getContext());
Assert.assertEquals(References.CHILD_OF, child.getReferences().get(0).getReferenceType());
Assert.assertEquals(following.context(), child.getReferences().get(1).getContext());
Assert.assertEquals(References.FOLLOWS_FROM, child.getReferences().get(1).getReferenceType());
}
示例6: testSingleExtractedFollowsFrom
import io.opentracing.References; //导入依赖的package包/类
@Test
public void testSingleExtractedFollowsFrom() {
APMTracerTest.TestTraceRecorder testTraceReporter = new APMTracerTest.TestTraceRecorder();
Tracer tracer = new APMTracer(testTraceReporter);
SpanContext spanCtx = extractedTraceState(tracer, TEST_APM_ID1);
Span span = tracer.buildSpan("root")
.addReference(References.FOLLOWS_FROM, spanCtx)
.start();
span.finish();
assertEquals(1, testTraceReporter.getTraces().size());
Trace trace = testTraceReporter.getTraces().get(0);
assertEquals(1, trace.getNodes().size());
assertEquals(Consumer.class, trace.getNodes().get(0).getClass());
assertEquals(((Consumer) trace.getNodes().get(0)).getCorrelationIds().get(0),
new CorrelationIdentifier(Scope.Interaction, TEST_APM_ID1));
assertEquals(0, ((Consumer) trace.getNodes().get(0)).getNodes().size());
}
示例7: testFindPrimaryReferenceSingleChildOfSpanContextWithOtherRefs
import io.opentracing.References; //导入依赖的package包/类
@Test
public void testFindPrimaryReferenceSingleChildOfSpanContextWithOtherRefs() {
Tracer tracer = new APMTracer();
SpanContext spanCtx1 = extractSpanContext(tracer, TEST_APM_ID1);
Reference ref1 = new Reference(References.CHILD_OF, spanCtx1);
Span span2 = tracer.buildSpan("test2").start();
Reference ref2 = new Reference(References.FOLLOWS_FROM, span2.context());
Span span3 = tracer.buildSpan("test3").start();
Reference ref3 = new Reference(References.CHILD_OF, span3.context());
Span span4 = tracer.buildSpan("test4").start();
Reference ref4 = new Reference(References.CHILD_OF, span4.context());
assertEquals(ref1, APMSpan.findPrimaryReference(Arrays.asList(ref1, ref2, ref3, ref4)));
}
示例8: testFollowFromReference
import io.opentracing.References; //导入依赖的package包/类
@Test
public void testFollowFromReference() {
MockTracer tracer = new MockTracer(MockTracer.Propagator.TEXT_MAP);
final MockSpan precedent = tracer.buildSpan("precedent").startManual();
final MockSpan followingSpan = tracer.buildSpan("follows")
.addReference(References.FOLLOWS_FROM, precedent.context())
.startManual();
assertEquals(precedent.context().spanId(), followingSpan.parentId());
assertEquals(1, followingSpan.references().size());
final MockSpan.Reference followsFromRef = followingSpan.references().get(0);
assertEquals(new MockSpan.Reference(precedent.context(), References.FOLLOWS_FROM), followsFromRef);
}
示例9: testMultiReferences
import io.opentracing.References; //导入依赖的package包/类
@Test
public void testMultiReferences() {
MockTracer tracer = new MockTracer(MockTracer.Propagator.TEXT_MAP);
final MockSpan parent = tracer.buildSpan("parent").startManual();
final MockSpan precedent = tracer.buildSpan("precedent").startManual();
final MockSpan followingSpan = tracer.buildSpan("follows")
.addReference(References.FOLLOWS_FROM, precedent.context())
.asChildOf(parent.context())
.startManual();
assertEquals(parent.context().spanId(), followingSpan.parentId());
assertEquals(2, followingSpan.references().size());
final MockSpan.Reference followsFromRef = followingSpan.references().get(0);
final MockSpan.Reference parentRef = followingSpan.references().get(1);
assertEquals(new MockSpan.Reference(precedent.context(), References.FOLLOWS_FROM), followsFromRef);
assertEquals(new MockSpan.Reference(parent.context(), References.CHILD_OF), parentRef);
}
示例10: testMultiReferencesBaggage
import io.opentracing.References; //导入依赖的package包/类
@Test
public void testMultiReferencesBaggage() {
MockTracer tracer = new MockTracer(MockTracer.Propagator.TEXT_MAP);
final MockSpan parent = tracer.buildSpan("parent").startManual();
parent.setBaggageItem("parent", "foo");
final MockSpan precedent = tracer.buildSpan("precedent").startManual();
precedent.setBaggageItem("precedent", "bar");
final MockSpan followingSpan = tracer.buildSpan("follows")
.addReference(References.FOLLOWS_FROM, precedent.context())
.asChildOf(parent.context())
.startManual();
assertEquals("foo", followingSpan.getBaggageItem("parent"));
assertEquals("bar", followingSpan.getBaggageItem("precedent"));
}
示例11: success
import io.opentracing.References; //导入依赖的package包/类
public void success(final T result) {
for (final SuccessCallback<T> callback : successCallbacks) {
context.submit(
new Runnable() {
@Override
public void run() {
try (Scope child =
tracer
.buildSpan("success")
.addReference(References.FOLLOWS_FROM, parentScope.span().context())
.withTag(Tags.COMPONENT.getKey(), "success")
.startActive(true)) {
callback.accept(result);
}
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
}
});
}
}
示例12: tell
import io.opentracing.References; //导入依赖的package包/类
public void tell(final String message) {
final Span parent = tracer.scopeManager().active().span();
phaser.register();
executor.submit(
new Runnable() {
@Override
public void run() {
try (Scope child =
tracer
.buildSpan("received")
.addReference(References.FOLLOWS_FROM, parent.context())
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.startActive(true)) {
phaser.arriveAndAwaitAdvance(); // child tracer started
child.span().log("received " + message);
phaser.arriveAndAwaitAdvance(); // assert size
}
phaser.arriveAndAwaitAdvance(); // child tracer finished
phaser.arriveAndAwaitAdvance(); // assert size
}
});
}
示例13: ask
import io.opentracing.References; //导入依赖的package包/类
public Future<String> ask(final String message) {
final Span parent = tracer.scopeManager().active().span();
phaser.register();
Future<String> future =
executor.submit(
new Callable<String>() {
@Override
public String call() throws Exception {
try (Scope child =
tracer
.buildSpan("received")
.addReference(References.FOLLOWS_FROM, parent.context())
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.startActive(true)) {
phaser.arriveAndAwaitAdvance(); // child tracer started
phaser.arriveAndAwaitAdvance(); // assert size
return "received " + message;
} finally {
phaser.arriveAndAwaitAdvance(); // child tracer finished
phaser.arriveAndAwaitAdvance(); // assert size
}
}
});
return future;
}
示例14: preHandle
import io.opentracing.References; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler)
throws Exception {
if (!isTraced(httpServletRequest)) {
return true;
}
/**
* 1. check if there is an active span, it has been activated in servlet filter or in this interceptor (forward)
* 2. if there is no active span then it can be handling of an async request or spring boot default error handling
*/
ActiveSpan serverSpan = tracer.activeSpan();
if (serverSpan != null) {
serverSpan = serverSpan.capture().activate();
} else if (httpServletRequest.getAttribute(CONTINUATION_FROM_ASYNC_STARTED) != null) {
ActiveSpan.Continuation contd = (ActiveSpan.Continuation) httpServletRequest.getAttribute(CONTINUATION_FROM_ASYNC_STARTED);
serverSpan = contd.activate();
httpServletRequest.removeAttribute(CONTINUATION_FROM_ASYNC_STARTED);
} else {
// spring boot default error handling, executes interceptor after processing in the filter (ugly huh?)
serverSpan = tracer.buildSpan(httpServletRequest.getMethod())
.addReference(References.FOLLOWS_FROM, TracingFilter.serverSpanContext(httpServletRequest))
.startActive();
}
for (HandlerInterceptorSpanDecorator decorator : decorators) {
decorator.onPreHandle(httpServletRequest, handler, serverSpan);
}
Deque<ActiveSpan> activeSpanStack = getActiveSpanStack(httpServletRequest);
activeSpanStack.push(serverSpan);
return true;
}
示例15: asChildOf
import io.opentracing.References; //导入依赖的package包/类
@Override
public SpanBuilder asChildOf(BaseSpan<?> parent) {
if (parent == null) {
return this;
}
return this.addReference(References.CHILD_OF, parent.context());
}