use of brave.propagation.TraceContext in project brave by openzipkin.
the class BraveTracer method inject.
@Override
public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
if (format != Format.Builtin.HTTP_HEADERS) {
throw new UnsupportedOperationException(format + " != Format.Builtin.HTTP_HEADERS");
}
TraceContext traceContext = ((BraveSpanContext) spanContext).context;
injector.inject(traceContext, (TextMap) carrier);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class OpenTracingAdapterTest method injectTraceContext.
@Test
public void injectTraceContext() throws Exception {
TraceContext context = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build();
Map<String, String> map = new LinkedHashMap<>();
TextMapInjectAdapter carrier = new TextMapInjectAdapter(map);
opentracing.inject(BraveSpanContext.wrap(context), Format.Builtin.HTTP_HEADERS, carrier);
assertThat(map).containsExactly(entry("X-B3-TraceId", "0000000000000001"), entry("X-B3-SpanId", "0000000000000002"), entry("X-B3-Sampled", "1"));
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class NonStringPropagationKeysTest method injectExtractTraceContext.
@Test
public void injectExtractTraceContext() throws Exception {
TraceContext context = tracing.tracer().newTrace().context();
Metadata metadata = new Metadata();
injector.inject(context, metadata);
assertThat(metadata.keys()).containsExactly("x-b3-traceid", "x-b3-spanid", "x-b3-sampled");
assertThat(extractor.extract(metadata).context()).isEqualTo(context);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class MutableSpanMapTest method reportOrphanedSpans_afterGC.
/**
* This is the key feature. Spans orphaned via GC are reported to zipkin on the next action.
*
* <p>This is a customized version of https://github.com/raphw/weak-lock-free/blob/master/src/test/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMapTest.java
*/
@Test
public void reportOrphanedSpans_afterGC() {
TraceContext context1 = context.toBuilder().spanId(1).build();
map.getOrCreate(context1);
TraceContext context2 = context.toBuilder().spanId(2).build();
map.getOrCreate(context2);
TraceContext context3 = context.toBuilder().spanId(3).build();
map.getOrCreate(context3);
TraceContext context4 = context.toBuilder().spanId(4).build();
map.getOrCreate(context4);
// By clearing strong references in this test, we are left with the weak ones in the map
context1 = context2 = null;
blockOnGC();
// After GC, we expect that the weak references of context1 and context2 to be cleared
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(null, null, context3, context4);
map.reportOrphanedSpans();
// After reporting, we expect no the weak references of null
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(context3, context4);
// We also expect the spans to have been reported
assertThat(spans).flatExtracting(Span::annotations).extracting(Annotation::value).containsExactly("brave.flush", "brave.flush");
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class MutableSpanMapTest method noop_afterGC.
@Test
public void noop_afterGC() {
TraceContext context1 = context.toBuilder().spanId(1).build();
map.getOrCreate(context1);
TraceContext context2 = context.toBuilder().spanId(2).build();
map.getOrCreate(context2);
TraceContext context3 = context.toBuilder().spanId(3).build();
map.getOrCreate(context3);
TraceContext context4 = context.toBuilder().spanId(4).build();
map.getOrCreate(context4);
map.noop.set(true);
// By clearing strong references in this test, we are left with the weak ones in the map
context1 = context2 = null;
blockOnGC();
// After GC, we expect that the weak references of context1 and context2 to be cleared
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(null, null, context3, context4);
map.reportOrphanedSpans();
// After reporting, we expect no the weak references of null
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(context3, context4);
// since this is noop, we don't expect any spans to be reported
assertThat(spans).isEmpty();
}
Aggregations