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);
}
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;
}
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"));
}
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);
}
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);
}
Aggregations