Search in sources :

Example 21 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TracerTest method localServiceName_ignoredWhenGivenLocalEndpoint.

@Test
public void localServiceName_ignoredWhenGivenLocalEndpoint() {
    Endpoint endpoint = Endpoint.newBuilder().ip("1.2.3.4").serviceName("my-bar").build();
    tracer = Tracing.newBuilder().localServiceName("my-foo").endpoint(endpoint).build().tracer();
    MutableSpan defaultSpan = new MutableSpan();
    defaultSpan.localServiceName("my-bar");
    defaultSpan.localIp("1.2.3.4");
    assertThat(tracer).extracting("pendingSpans.defaultSpan").isEqualTo(defaultSpan);
}
Also used : MutableSpan(brave.handler.MutableSpan) Endpoint(zipkin2.Endpoint) Test(org.junit.Test)

Example 22 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TracerTest method tracerThatPartitionsNamesOnlocalRootId.

Map<Long, List<String>> tracerThatPartitionsNamesOnlocalRootId() {
    Map<Long, List<String>> reportedNames = new LinkedHashMap<>();
    tracer = Tracing.newBuilder().addSpanHandler(new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            assertThat(context.localRootId()).isNotZero();
            reportedNames.computeIfAbsent(context.localRootId(), k -> new ArrayList<>()).add(span.name());
            // retain
            return true;
        }
    }).alwaysSampleLocal().build().tracer();
    return reportedNames;
}
Also used : MutableSpan(brave.handler.MutableSpan) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) TestSpanHandler(brave.test.TestSpanHandler) SpanHandler(brave.handler.SpanHandler) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class RedactingSpanHandlerTest method showRedaction.

@Test
public void showRedaction() throws Exception {
    ScopedSpan span = tracing.tracer().startScopedSpan("auditor");
    try {
        span.tag("a", "1");
        span.tag("b", "4121-2319-1483-3421");
        span.annotate("cc=4121-2319-1483-3421");
        span.tag("c", "3");
    } finally {
        span.finish();
    }
    MutableSpan reported = spans.take();
    assertThat(reported.tags()).containsExactly(entry("a", "1"), // credit card tag was nuked
    entry("c", "3"));
    assertThat(reported.annotations()).extracting(Entry::getValue).containsExactly("cc=xxxx-xxxx-xxxx-xxxx");
    // Leak some data by adding a tag using the same context after the span was .
    tracing.tracer().toSpan(span.context()).tag("d", "cc=4121-2319-1483-3421");
    // Orphans are via GC, to test this, we have to drop any reference to the context
    span = null;
    GarbageCollectors.blockOnGC();
    // GC only clears the reference to the leaked data. Normal tracer use implicitly handles orphans
    tracing.tracer().nextSpan().abandon();
    MutableSpan leaked = spans.take();
    assertThat(leaked.tags()).containsExactly(// credit card tag was nuked
    entry("d", "cc=xxxx-xxxx-xxxx-xxxx"));
}
Also used : MutableSpan(brave.handler.MutableSpan) ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Example 24 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TagTest method tag_mutableSpan.

@Test
public void tag_mutableSpan() {
    when(parseValue.apply(input, context)).thenReturn("value");
    tag.tag(input, context, mutableSpan);
    verify(parseValue).apply(input, context);
    // doesn't parse twice
    verifyNoMoreInteractions(parseValue);
    MutableSpan expected = new MutableSpan();
    expected.tag("key", "value");
    assertThat(mutableSpan).isEqualTo(expected);
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 25 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class RealSpanTest method finish.

private void finish(String start, String end, Kind span2Kind) {
    Span span = tracing.tracer().newTrace().name("foo").start();
    span.annotate(1L, start);
    span.annotate(2L, end);
    MutableSpan span2 = spans.get(0);
    assertThat(span2.annotations()).isEmpty();
    assertThat(span2.startTimestamp()).isEqualTo(1L);
    assertThat(span2.finishTimestamp()).isEqualTo(2L);
    assertThat(span2.kind()).isEqualTo(span2Kind);
}
Also used : MutableSpan(brave.handler.MutableSpan) MutableSpan(brave.handler.MutableSpan)

Aggregations

MutableSpan (brave.handler.MutableSpan)141 Test (org.junit.Test)107 TraceContext (brave.propagation.TraceContext)36 KafkaStreams (org.apache.kafka.streams.KafkaStreams)28 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)28 Topology (org.apache.kafka.streams.Topology)28 Scope (brave.propagation.CurrentTraceContext.Scope)14 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 KeyValue (org.apache.kafka.streams.KeyValue)9 ArrayList (java.util.ArrayList)8 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)8 MessagingTracing (brave.messaging.MessagingTracing)7 FileNotFoundException (java.io.FileNotFoundException)7 Arrays (java.util.Arrays)7 List (java.util.List)7 CONSUMER (brave.Span.Kind.CONSUMER)6 PRODUCER (brave.Span.Kind.PRODUCER)6 SpanHandler (brave.handler.SpanHandler)6 KafkaTracing (brave.kafka.clients.KafkaTracing)6 KAFKA_STREAMS_FILTERED_TAG (brave.kafka.streams.KafkaStreamsTags.KAFKA_STREAMS_FILTERED_TAG)6