Search in sources :

Example 71 with TraceContext

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);
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 72 with TraceContext

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);
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 73 with TraceContext

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);
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 74 with TraceContext

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);
    }
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 75 with TraceContext

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);
    }
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Aggregations

TraceContext (brave.propagation.TraceContext)200 Test (org.junit.Test)163 CurrentTraceContext (brave.propagation.CurrentTraceContext)77 Scope (brave.propagation.CurrentTraceContext.Scope)52 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)52 MutableSpan (brave.handler.MutableSpan)38 Span (brave.Span)17 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 MockResponse (okhttp3.mockwebserver.MockResponse)12 SpanHandler (brave.handler.SpanHandler)9 Clock (brave.Clock)7 SamplingFlags (brave.propagation.SamplingFlags)7 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 TestSpanHandler (brave.test.TestSpanHandler)6 AssertableCallback (brave.test.util.AssertableCallback)6 Message (javax.jms.Message)6 After (org.junit.After)6