use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITMongoDBTracing method makesChildOfCurrentSpan.
@Test
public void makesChildOfCurrentSpan() {
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
executeFind(COLLECTION_NAME);
}
MutableSpan clientSpan = testSpanHandler.takeRemoteSpan(CLIENT);
assertChildOf(clientSpan, parent);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ExtraFactoryTest method idempotent.
@Test
public void idempotent() {
TraceContext decorated = propagationFactory.decorate(context);
List<Object> originalExtra = decorated.extra();
assertThat(propagationFactory.decorate(decorated).extra()).isSameAs(originalExtra);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ExtraFactoryTest method decorate_extractedExtra_plus_parent_merge.
/**
* This scenario is possible, albeit rare. {@code tracer.nextSpan(extracted} } is called when
* there is an implicit parent. For example, you have a trace in progress when extracting extra
* from an incoming message. Another example is where there is a span in scope due to a leak such
* as from using {@link CurrentTraceContext.Default#inheritable()}.
*
* <p>Extracted extra should merge into the current extra state instead creating multiple
* entries in {@link TraceContext#extra()}.
*/
@Test
public void decorate_extractedExtra_plus_parent_merge() {
TraceContext decorated = propagationFactory.decorate(context);
BasicMapExtra extra1 = decorated.findExtra(BasicMapExtra.class);
BasicMapExtra extracted = factory.create();
extra1.put("1", "one");
extracted.put("1", "two");
extracted.put("2", "three");
context2 = propagationFactory.decorate(context2.toBuilder().addExtra(extra1).addExtra(extracted).build());
BasicMapExtra extra2 = context2.findExtra(BasicMapExtra.class);
// merged
assertThat(context2.extra()).containsExactly(extra2);
// extracted should win!
assertThat(extra2.get("1")).isEqualTo("two");
assertThat(extra2.get("2")).isEqualTo("three");
assertExtraClaimed(context2);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ExtraFactoryTest method decorate_redundant.
@Test
public void decorate_redundant() {
List<TraceContext> contexts = asList(context.toBuilder().addExtra(factory.create()).build(), context.toBuilder().addExtra(1L).addExtra(factory.create()).build(), context.toBuilder().addExtra(factory.create()).addExtra(1L).build(), context.toBuilder().addExtra(1L).addExtra(factory.create()).addExtra(2L).build());
for (TraceContext context : contexts) {
context = factory.decorate(context);
assertThat(factory.decorate(context)).isSameAs(context);
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ExtraFactoryTest method decorate_forksWhenFieldsAlreadyClaimed.
@Test
public void decorate_forksWhenFieldsAlreadyClaimed() {
TraceContext other = TraceContext.newBuilder().traceId(98L).spanId(99L).build();
BasicMapExtra claimed = factory.decorate(other).findExtra(BasicMapExtra.class);
List<TraceContext> contexts = asList(context.toBuilder().addExtra(claimed).build(), context.toBuilder().addExtra(1L).addExtra(claimed).build(), context.toBuilder().addExtra(claimed).addExtra(1L).build(), context.toBuilder().addExtra(1L).addExtra(claimed).addExtra(2L).build());
for (TraceContext context : contexts) {
TraceContext ensured = factory.decorate(context);
assertThat(ensured).isNotSameAs(context);
assertThat(ensured.extra()).isNotSameAs(context.extra()).hasSize(context.extra().size());
assertExtraClaimed(ensured);
}
}
Aggregations