Search in sources :

Example 51 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class MutableSpanMapTest method remove_resolvesHashCodeCollisions.

@Test
public void remove_resolvesHashCodeCollisions() {
    // intentionally clash on hashCode, but not equals
    TraceContext context1 = context.toBuilder().spanId(1).build();
    TraceContext context2 = context.toBuilder().spanId(-2L).build();
    // sanity check
    assertThat(context1.hashCode()).isEqualTo(context2.hashCode());
    assertThat(context1).isNotEqualTo(context2);
    map.getOrCreate(context1);
    map.getOrCreate(context2);
    map.remove(context1);
    assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsOnly(context2);
}
Also used : Tracing(brave.Tracing) PowerMockito.mockStatic(org.powermock.api.mockito.PowerMockito.mockStatic) PowerMockito.when(org.powermock.api.mockito.PowerMockito.when) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Span(zipkin2.Span) Test(org.junit.Test) TraceContext(brave.propagation.TraceContext) ArrayList(java.util.ArrayList) Reference(java.lang.ref.Reference) List(java.util.List) Annotation(zipkin2.Annotation) Platform(brave.internal.Platform) Endpoint(zipkin2.Endpoint) After(org.junit.After) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Reference(java.lang.ref.Reference) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class AWSPropagation method currentTraceId.

/**
 * Returns the current {@link #traceId(TraceContext)} or null if not available
 */
@Nullable
public static String currentTraceId() {
    Tracing tracing = Tracing.current();
    if (tracing == null)
        return null;
    TraceContext context = tracing.currentTraceContext().get();
    if (context == null)
        return null;
    return traceId(context);
}
Also used : TraceContext(brave.propagation.TraceContext) Tracing(brave.Tracing) Nullable(brave.internal.Nullable)

Example 53 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class AWSPropagationTest method traceIdWhenPassThrough.

@Test
public void traceIdWhenPassThrough() {
    carrier.put("x-amzn-trace-id", "Robot=Hello;Self=1-582113d1-1e48b74b3603af8479078ed6;  " + "Root=1-58211399-36d228ad5d99923122bbe354;  " + "TotalTimeSoFar=112ms;CalledFrom=Foo");
    TraceContext context = contextWithPassThrough();
    assertThat(AWSPropagation.traceId(context)).isEqualTo("1-58211399-36d228ad5d99923122bbe354");
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 54 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class AWSPropagationTest method traceId_null_if_not_aws.

@Test
public void traceId_null_if_not_aws() {
    TraceContext notAWS = sampledContext.toBuilder().extra(Collections.emptyList()).build();
    assertThat(AWSPropagation.traceId(notAWS)).isNull();
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Aggregations

TraceContext (brave.propagation.TraceContext)54 Test (org.junit.Test)46 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)21 CurrentTraceContext (brave.propagation.CurrentTraceContext)10 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Span (brave.Span)4 Tracer (brave.Tracer)4 Tracing (brave.Tracing)4 ThreadContextCurrentTraceContext (brave.context.log4j2.ThreadContextCurrentTraceContext)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 After (org.junit.After)4 Endpoint (zipkin2.Endpoint)4 Span (zipkin2.Span)4 Platform (brave.internal.Platform)3 Propagation (brave.propagation.Propagation)3 Reference (java.lang.ref.Reference)3