def test_client_shutdown_async(self, mock_traces_collect, mock_send): client = Client( servers=['http://example.com'], app_name='app_name', secret_token='secret', async_mode=True, ) client.send(auth_header='foo', **{ 'foo': 'bar', }) client.close() self.assertEqual(mock_traces_collect.call_count, 1) self.assertEqual(mock_send.call_count, 1)
def test_send_not_enabled(self, time, send_remote): time.return_value = 1328055286.51 with mock.patch.dict('os.environ', {'ELASTIC_APM_DISABLE_SEND': 'true'}): client = Client( servers=['http://example.com'], app_name='app_name', secret_token='secret', ) client.send(**{ 'foo': 'bar', }) assert not send_remote.called
def test_send_with_auth_header(self, time, send_remote): time.return_value = 1328055286.51 client = Client( servers=['http://example.com'], app_name='app_name', secret_token='secret', ) client.send(auth_header='foo', **{ 'foo': 'bar', }) send_remote.assert_called_once_with( url='http://example.com', data=six.b('x\x9c\xabVJ\xcb\xcfW\xb2RPJJ,R\xaa\x05\x00 \x98\x04T'), headers={ 'Content-Type': 'application/json', 'Content-Encoding': 'deflate', 'Authorization': 'foo', 'User-Agent': 'elasticapm-python/%s' % elasticapm.VERSION, }, )
def test_send_remote_failover_sync_stdlib(should_try, http_send): should_try.return_value = True client = Client( server_url='http://example.com', service_name='app_name', secret_token='secret', transport_class='elasticapm.transport.http.Transport', ) logger = mock.Mock() client.error_logger.error = logger # test error http_send.side_effect = ValueError('oopsie') client.send('http://example.com/api/store', **{'message': 'oh no'}) assert client.state.status == client.state.ERROR assert len(logger.call_args_list) == 1 assert 'oopsie' in logger.call_args_list[0][0][1] # test recovery http_send.side_effect = None client.send('http://example.com/api/store', **{'message': 'oh no'}) assert client.state.status == client.state.ONLINE client.close()
def test_send_remote_failover_sync_stdlib(should_try, http_send): should_try.return_value = True client = Client( server_url="http://example.com", service_name="app_name", secret_token="secret", transport_class="elasticapm.transport.http.Transport", ) logger = mock.Mock() client.error_logger.error = logger # test error http_send.side_effect = ValueError("oopsie") client.send("http://example.com/api/store", **{"message": "oh no"}) assert client.state.status == client.state.ERROR assert len(logger.call_args_list) == 1 assert "oopsie" in logger.call_args_list[0][0][1] # test recovery http_send.side_effect = None client.send("http://example.com/api/store", **{"message": "oh no"}) assert client.state.status == client.state.ONLINE client.close()