def test_non_sampled_span_thrift(recorder): mock_connection = MockConnection() mock_connection.open() non_sampled_span = BasicSpan( lightstep.tracer._LightstepTracer(False, recorder, None), operation_name="non_sampled", context=SpanContext(trace_id=1, span_id=1, sampled=False), start_time=time.time(), ) non_sampled_span.finish() sampled_span = BasicSpan( lightstep.tracer._LightstepTracer(False, recorder, None), operation_name="sampled", context=SpanContext(trace_id=1, span_id=2, sampled=True), start_time=time.time(), ) sampled_span.finish() recorder.record_span(non_sampled_span) recorder.record_span(sampled_span) recorder.flush(mock_connection) if recorder.use_thrift: for span_record in mock_connection.reports[0].span_records: assert span_record.span_name == "sampled" else: for span in mock_connection.reports[0].spans: assert span.operation_name == "sampled"
def test_stress_logs(self): recorder = self.create_test_recorder() for i in range(1000): recorder.record_span(self.dummy_basic_span(recorder, i)) self.assertTrue(recorder.flush(self.mock_connection)) self.assertEqual(len(self.mock_connection.reports[0].span_records), 1000) self.check_spans(self.mock_connection.reports[0].span_records)
def test_buffer_limits(self): self.runtime_args.update({ 'max_span_records': 88, }) recorder = self.create_test_recorder() self.assertEqual(len(recorder._span_records), 0) for i in range(0, 10000): recorder.record_span(self.dummy_basic_span(recorder, i)) self.assertEqual(len(recorder._span_records), 88) self.assertTrue(recorder.flush(self.mock_connection))
def test_send_spans_after_shutdown(self): recorder = self.create_test_recorder() # Send 10 spans for i in range(10): recorder.record_span(self.dummy_basic_span(recorder, i)) self.assertTrue(recorder.flush(self.mock_connection)) # Check 10 spans self.check_spans(self.mock_connection.reports[0].span_records) # Delete current logs and shutdown runtime self.mock_connection.clear() recorder.shutdown() # Send 10 spans, though none should get through for i in range(10): recorder.record_span(self.dummy_basic_span(recorder, i)) self.assertFalse(recorder.flush(self.mock_connection)) self.assertEqual(len(self.mock_connection.reports), 0)
def test_send_spans_after_shutdown(recorder): mock_connection = MockConnection() mock_connection.open() # Send 10 spans for i in range(10): dummy_basic_span(recorder, i) assert recorder.flush(mock_connection) # Check 10 spans check_spans(recorder.converter, mock_connection.reports[0]) # Delete current logs and shutdown runtime mock_connection.clear() recorder.shutdown() # Send 10 spans, though none should get through for i in range(10): recorder.record_span(dummy_basic_span(recorder, i)) assert not recorder.flush(mock_connection) assert len(mock_connection.reports) == 0