def test_emit(self): client = mock.Mock() client.Export.return_value = iter([1]) exporter = TraceExporter(service_name=SERVICE_NAME, client=client, transport=MockTransport) exporter.emit({}) self.assertTrue(client.Export.called)
def test_emit_throw(self): client = mock.Mock() client.Export.side_effect = grpc.RpcError() exporter = TraceExporter(service_name=SERVICE_NAME, client=client, transport=MockTransport) # does not throw exporter.emit({}) self.assertTrue(client.Export.called)
def test_span_emit_exception(self): client = mock.Mock() span_data = span_data_module.SpanData( name="name0", context=span_context_module.SpanContext( trace_id='0e0c63257de34c92bf9efcd03927272e'), span_id='0e0c63257de34c92', parent_span_id=None, start_time=None, end_time=None, attributes=None, child_span_count=None, stack_trace=None, time_events=None, links=None, status=None, same_process_as_parent_span=None, span_kind=0) exporter = TraceExporter( service_name=SERVICE_NAME, client=client, transport=MockTransport) client.Export.side_effect = grpc.RpcError() # does not throw: exporter.emit([span_data]) client.Export.return_value = iter([1]) exporter.emit([span_data]) self.assertEqual(len(client.Export.mock_calls), 2) actual_request = list(client.Export.call_args[0][0])[0] self.assertEqual(actual_request.node, exporter.node)
def test_basic_spans_emit(self): hex_encoder = codecs.getencoder('hex') client = mock.Mock() client.Export.return_value = iter([1]) span_data0 = span_data_module.SpanData( name="name0", context=span_context_module.SpanContext( trace_id='0e0c63257de34c92bf9efcd03927272e'), span_id='0e0c63257de34c92', parent_span_id=None, start_time=None, end_time=None, attributes=None, child_span_count=None, stack_trace=None, time_events=None, links=None, status=None, same_process_as_parent_span=None, span_kind=0) span_data1 = span_data_module.SpanData( name="name1", context=span_context_module.SpanContext( trace_id='1e0c63257de34c92bf9efcd03927272e'), span_id='1e0c63257de34c92', parent_span_id=None, start_time=None, end_time=None, attributes=None, child_span_count=None, stack_trace=None, time_events=None, links=None, status=None, same_process_as_parent_span=None, span_kind=0) exporter = TraceExporter( service_name=SERVICE_NAME, client=client, transport=MockTransport) exporter.emit([span_data0]) actual_request0 = list(client.Export.call_args[0][0])[0] self.assertEqual(actual_request0.node, exporter.node) pb_span0 = actual_request0.spans[0] self.assertEqual(pb_span0.name.value, "name0") self.assertEqual(hex_encoder(pb_span0.trace_id)[ 0], b'0e0c63257de34c92bf9efcd03927272e') self.assertEqual(hex_encoder(pb_span0.span_id)[0], b'0e0c63257de34c92') exporter.emit([span_data1]) self.assertEqual(len(client.Export.mock_calls), 2) actual_request1 = list(client.Export.call_args[0][0])[0] self.assertEqual(actual_request1.node, exporter.node) pb_span1 = actual_request1.spans[0] self.assertEqual(pb_span1.name.value, "name1") self.assertEqual(hex_encoder(pb_span1.trace_id)[ 0], b'1e0c63257de34c92bf9efcd03927272e') self.assertEqual(hex_encoder(pb_span1.span_id)[0], b'1e0c63257de34c92')