Java Code Examples for brave.handler.SpanHandler#begin()

The following examples show how to use brave.handler.SpanHandler#begin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NoopAwareSpanHandlerTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void multiple_callInSequence() {
  SpanHandler[] handlers = new SpanHandler[2];
  handlers[0] = one;
  handlers[1] = two;
  SpanHandler handler = NoopAwareSpanHandler.create(handlers, noop);
  when(one.begin(eq(context), eq(span), isNull())).thenReturn(true);
  when(one.end(eq(context), eq(span), eq(Cause.FINISHED))).thenReturn(true);

  handler.begin(context, span, null);
  handler.end(context, span, Cause.FINISHED);

  verify(one).begin(context, span, null);
  verify(two).begin(context, span, null);
  verify(two).end(context, span, Cause.FINISHED);
  verify(one).end(context, span, Cause.FINISHED);
}
 
Example 2
Source File: PendingSpansTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Before public void init() {
  MutableSpan defaultSpan = new MutableSpan();
  defaultSpan.localServiceName("favistar");
  defaultSpan.localIp("1.2.3.4");
  Clock clock = () -> this.clock.incrementAndGet() * 1000L;
  SpanHandler orphanTracker =
      OrphanTracker.newBuilder().defaultSpan(defaultSpan).clock(clock).build();
  pendingSpans = new PendingSpans(defaultSpan, clock, new SpanHandler() {
    @Override
    public boolean begin(TraceContext ctx, MutableSpan span, @Nullable TraceContext parent) {
      contexts.add(ctx);
      return orphanTracker.begin(ctx, span, parent);
    }

    @Override public boolean end(TraceContext ctx, MutableSpan span, Cause cause) {
      orphanTracker.end(ctx, span, cause);
      spans.end(ctx, span, cause);
      return true;
    }
  }, new AtomicBoolean());
}
 
Example 3
Source File: NoopAwareSpanHandler.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public boolean begin(TraceContext context, MutableSpan span, TraceContext parent) {
  for (SpanHandler handler : handlers) {
    if (!handler.begin(context, span, parent)) return false;
  }
  return true;
}