@Autowired public WingtipsSpringBootConfiguration(WingtipsSpringBootProperties wingtipsProperties) { this.wingtipsProperties = wingtipsProperties; // Set the span logging representation if specified in the wingtips properties. if (wingtipsProperties.getSpanLoggingFormat() != null) { Tracer.getInstance().setSpanLoggingRepresentation(wingtipsProperties.getSpanLoggingFormat()); } }
private Span findCompletedSpanByCriteria(Predicate<Span> criteria) { Tracer.getInstance().setSpanLoggingRepresentation(Tracer.SpanLoggingRepresentation.KEY_VALUE); List<Span> matchingSpans = spanRecorder.completedSpans.stream().filter(criteria).collect(Collectors.toList()); assertThat(matchingSpans) .withFailMessage( "Expected to find exactly 1 span matching the specified criteria - instead found: " + matchingSpans.size() ) .hasSize(1); return matchingSpans.get(0); }
@Test(expected = IllegalArgumentException.class) public void setSpanLoggingRepresentation_blows_up_if_spanLoggingRepresentation_is_null() { // expect Tracer.getInstance().setSpanLoggingRepresentation(null); }
@DataProvider(value = { "JSON", "KEY_VALUE" }, splitBy = "\\|") @Test public void verify_span_serialization_methods(Tracer.SpanLoggingRepresentation serializationOption) { // given Span span = Span.generateRootSpanForNewTrace(UUID.randomUUID().toString(), SpanPurpose.LOCAL_ONLY).build(); String expectedOutput; switch(serializationOption) { case JSON: expectedOutput = span.toJSON(); break; case KEY_VALUE: expectedOutput = span.toKeyValueString(); break; default: throw new IllegalArgumentException("Unhandled option: " + serializationOption); } Tracer.getInstance().setSpanLoggingRepresentation(serializationOption); // then assertThat(Tracer.getInstance().getSpanLoggingRepresentation()).isEqualTo(serializationOption); // and when String serializedString = Tracer.getInstance().serializeSpanToDesiredStringRepresentation(span); // then assertThat(serializedString).isEqualTo(expectedOutput); }
private void resetTracer() { Tracer.getInstance().completeRequestSpan(); Tracer.getInstance().setRootSpanSamplingStrategy(new SampleAllTheThingsStrategy()); for (SpanLifecycleListener listener : new ArrayList<>(Tracer.getInstance().getSpanLifecycleListeners())) { Tracer.getInstance().removeSpanLifecycleListener(listener); } Tracer.getInstance().setSpanLoggingRepresentation(Tracer.SpanLoggingRepresentation.JSON); }