use of brave.handler.MutableSpan in project brave by openzipkin.
the class TracingProducerTest method should_add_parent_trace_when_context_injected_on_headers.
@Test
public void should_add_parent_trace_when_context_injected_on_headers() {
ProducerRecord<Object, String> record = new ProducerRecord<>(TEST_TOPIC, TEST_KEY, TEST_VALUE);
tracingProducer.injector.inject(parent, new KafkaProducerRequest(record));
tracingProducer.send(record);
mockProducer.completeNext();
MutableSpan producerSpan = spans.get(0);
assertThat(producerSpan.kind()).isEqualTo(PRODUCER);
assertChildOf(producerSpan, parent);
assertThat(lastHeaders(mockProducer)).containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method doesntCrashOnNonFatalThrowable.
@Test
public void doesntCrashOnNonFatalThrowable() {
Throwable[] toThrow = new Throwable[1];
SpanHandler handler = NoopAwareSpanHandler.create(new SpanHandler[] { new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
doThrowUnsafely(toThrow[0]);
return true;
}
} }, noop);
toThrow[0] = new RuntimeException();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
toThrow[0] = new Exception();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
toThrow[0] = new Error();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
// fatal
toThrow[0] = new StackOverflowError();
try {
// assertThatThrownBy doesn't work with StackOverflowError
handler.end(context, span, Cause.FINISHED);
failBecauseExceptionWasNotThrown(StackOverflowError.class);
} catch (StackOverflowError e) {
}
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class ZipkinJsonV2JsonWriterTest method missingFields_testCases.
@Test
public void missingFields_testCases() {
jsonWriter.write(MutableSpanTest.PERMUTATIONS.get(0).get(), buffer);
assertThat(buffer.toString()).isEqualTo("{}");
// check for simple bugs
for (int i = 1, length = MutableSpanTest.PERMUTATIONS.size(); i < length; i++) {
buffer.pos = 0;
MutableSpan span = MutableSpanTest.PERMUTATIONS.get(i).get();
jsonWriter.write(span, buffer);
assertThat(buffer.toString()).doesNotContain("null").doesNotContain(":0");
}
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class ZipkinJsonV2JsonWriterTest method specialCharacters.
@Test
public void specialCharacters() {
MutableSpan span = new MutableSpan();
span.name("\u2028 and \u2029");
span.localServiceName("\"foo");
span.tag("hello \n", "\t\b");
span.annotate(1L, "\uD83D\uDCA9");
jsonWriter.write(span, buffer);
String string = buffer.toString();
assertThat(string).isEqualTo("{\"name\":\"\\u2028 and \\u2029\",\"localEndpoint\":{\"serviceName\":\"\\\"foo\"},\"annotations\":[{\"timestamp\":1,\"value\":\"\uD83D\uDCA9\"}],\"tags\":{\"hello \\n\":\"\\t\\b\"}}");
assertThat(jsonWriter.sizeInBytes(span)).isEqualTo(string.getBytes(UTF_8).length);
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class OrphanTrackerTest method setup.
@Before
public void setup() {
defaultSpan = new MutableSpan();
defaultSpan.localServiceName(TracerTest.class.getSimpleName());
defaultSpan.localIp("127.0.0.1");
// same as how PendingSpans initializes
span = new MutableSpan(context, defaultSpan);
tracker = orphanTrackerWithFakeLogger();
}
Aggregations