private void serializeSpan(final Span span) { jw.writeByte(OBJECT_START); writeField("name", span.getName()); writeTimestamp(span.getTimestamp()); serializeTraceContext(span.getTraceContext(), true); writeField("duration", span.getDuration()); if (span.getStacktrace() != null) { serializeStacktrace(span.getStacktrace().getStackTrace()); } if (span.getContext().hasContent()) { serializeSpanContext(span.getContext()); } serializeSpanType(span); jw.writeByte(OBJECT_END); }
@Test void testEnableStacktraces() throws InterruptedException { when(tracerImpl.getConfig(StacktraceConfiguration.class).getSpanFramesMinDurationMs()).thenReturn(-1L); Transaction transaction = tracerImpl.startTransaction(); try (Scope scope = transaction.activateInScope()) { Span span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { Thread.sleep(10); span.end(); } transaction.end(); } assertThat(reporter.getFirstSpan().getStacktrace()).isNotNull(); }
@Test void testEnableStacktracesForSlowSpans() throws InterruptedException { when(tracerImpl.getConfig(StacktraceConfiguration.class).getSpanFramesMinDurationMs()).thenReturn(1L); Transaction transaction = tracerImpl.startTransaction(); try (Scope scope = transaction.activateInScope()) { Span span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { Thread.sleep(10); span.end(); } transaction.end(); } assertThat(reporter.getFirstSpan().getStacktrace()).isNotNull(); }
@Test void testDisableStacktraces() { when(tracerImpl.getConfig(StacktraceConfiguration.class).getSpanFramesMinDurationMs()).thenReturn(0L); Transaction transaction = tracerImpl.startTransaction(); try (Scope scope = transaction.activateInScope()) { Span span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } transaction.end(); } assertThat(reporter.getFirstSpan().getStacktrace()).isNull(); }
@Test void testDisableStacktracesForFastSpans() { when(tracerImpl.getConfig(StacktraceConfiguration.class).getSpanFramesMinDurationMs()).thenReturn(100L); Transaction transaction = tracerImpl.startTransaction(); try (Scope scope = transaction.activateInScope()) { Span span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } transaction.end(); } assertThat(reporter.getFirstSpan().getStacktrace()).isNull(); }