use of brave.propagation.TraceContext in project brave by openzipkin.
the class TracingCallFactory method newCall.
@Override
public Call newCall(Request request) {
TraceContext currentSpan = currentTraceContext.get();
OkHttpClient.Builder b = ok.newBuilder();
if (currentSpan != null)
b.interceptors().add(0, new SetParentSpanInScope(currentSpan));
// TODO: This can hide errors at the beginning of call.execute, such as invalid host!
return b.build().newCall(request);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class CurrentTraceContextTest method restoresSpanAfterRunnable.
@Test
public void restoresSpanAfterRunnable() throws Exception {
TraceContext context0 = TraceContext.newBuilder().traceId(3L).spanId(3L).build();
try (CurrentTraceContext.Scope scope0 = currentTraceContext.newScope(context0)) {
attachesSpanInRunnable();
assertThat(currentTraceContext.get()).isEqualTo(context0);
verifyImplicitContext(context0);
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class Tracer method toString.
@Override
public String toString() {
TraceContext currentSpan = currentTraceContext.get();
List<zipkin2.Span> inFlight = recorder.snapshot();
return "Tracer{" + (currentSpan != null ? ("currentSpan=" + currentSpan + ", ") : "") + (inFlight.size() > 0 ? ("inFlight=" + inFlight + ", ") : "") + (noop.get() ? "noop=true, " : "") + "reporter=" + reporter + "}";
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class MutableSpanMap method reportOrphanedSpans.
/**
* Reports spans orphaned by garbage collection.
*/
void reportOrphanedSpans() {
Reference<? extends TraceContext> reference;
while ((reference = poll()) != null) {
TraceContext context = reference.get();
MutableSpan value = delegate.remove(reference);
if (value == null || noop.get())
continue;
try {
value.annotate(value.clock.currentTimeMicroseconds(), "brave.flush");
reporter.report(value.toSpan());
} catch (RuntimeException e) {
// don't crash the caller if there was a problem reporting an unrelated span.
if (context != null && logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "error flushing " + context, e);
}
}
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class CurrentTraceContextExecutorTest method execute.
@Test
public void execute() throws Exception {
final TraceContext[] threadValues = new TraceContext[2];
CountDownLatch latch = new CountDownLatch(1);
// execution time.
try (CurrentTraceContext.Scope ws = currentTraceContext.newScope(context)) {
executor.execute(() -> {
threadValues[0] = currentTraceContext.get();
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
});
// this won't run immediately because the other is blocked
executor.execute(() -> threadValues[1] = currentTraceContext.get());
}
// invoked with
try (CurrentTraceContext.Scope ws = currentTraceContext.newScope(context2)) {
latch.countDown();
shutdownExecutor();
assertThat(threadValues).containsExactly(context, context);
}
}
Aggregations