logtail-python 0.5.1__tar.gz → 0.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {logtail_python-0.5.1 → logtail_python-0.5.2}/PKG-INFO +2 -2
  2. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/__init__.py +1 -1
  3. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/flusher.py +7 -7
  4. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail_python.egg-info/PKG-INFO +2 -2
  5. {logtail_python-0.5.1 → logtail_python-0.5.2}/setup.py +1 -1
  6. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_flusher.py +37 -2
  7. {logtail_python-0.5.1 → logtail_python-0.5.2}/LICENSE.md +0 -0
  8. {logtail_python-0.5.1 → logtail_python-0.5.2}/MANIFEST.in +0 -0
  9. {logtail_python-0.5.1 → logtail_python-0.5.2}/README.md +0 -0
  10. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/compat.py +0 -0
  11. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/formatter.py +0 -0
  12. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/frame.py +0 -0
  13. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/handler.py +0 -0
  14. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/helpers.py +0 -0
  15. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/py.typed +0 -0
  16. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/rq.py +0 -0
  17. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail/uploader.py +0 -0
  18. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail_python.egg-info/SOURCES.txt +0 -0
  19. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail_python.egg-info/dependency_links.txt +0 -0
  20. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail_python.egg-info/requires.txt +0 -0
  21. {logtail_python-0.5.1 → logtail_python-0.5.2}/logtail_python.egg-info/top_level.txt +0 -0
  22. {logtail_python-0.5.1 → logtail_python-0.5.2}/requirements.txt +0 -0
  23. {logtail_python-0.5.1 → logtail_python-0.5.2}/setup.cfg +0 -0
  24. {logtail_python-0.5.1 → logtail_python-0.5.2}/test-requirements.txt +0 -0
  25. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/__init__.py +0 -0
  26. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_formatter.py +0 -0
  27. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_frame.py +0 -0
  28. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_handler.py +0 -0
  29. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_helpers.py +0 -0
  30. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_rq.py +0 -0
  31. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/test_uploader.py +0 -0
  32. {logtail_python-0.5.1 → logtail_python-0.5.2}/tests/typecheck/public_api.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: logtail-python
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Better Stack client library
5
5
  Home-page: https://github.com/logtail/logtail-python
6
- Download-URL: https://github.com/logtail/logtail-python/tarball/0.5.1
6
+ Download-URL: https://github.com/logtail/logtail-python/tarball/0.5.2
7
7
  Author: Logtail
8
8
  Author-email: hello@logtail.com
9
9
  License: ISC
@@ -5,7 +5,7 @@ from .handler import LogtailHandler
5
5
  from .helpers import LogtailContext, DEFAULT_CONTEXT
6
6
  from .formatter import LogtailFormatter
7
7
 
8
- __version__ = '0.5.1'
8
+ __version__ = '0.5.2'
9
9
 
10
10
  context = DEFAULT_CONTEXT
11
11
 
@@ -89,13 +89,13 @@ class FlushWorker(threading.Thread):
89
89
  if delay is not None:
90
90
  time.sleep(delay)
91
91
 
92
- # A network error surfaces as a Fake500 that carries an `exception`
93
- # attribute; a genuine server HTTP 500 is a real `requests.Response`
94
- # that has no such attribute. Use a default so the latter doesn't
95
- # raise AttributeError here and kill the flush thread (dropping all
96
- # subsequent logs for the life of the process).
97
- if response.status_code == 500 and getattr(response, "exception", None) is not None:
98
- print('Failed to send logs to Better Stack after {} retries: {}'.format(len(RETRY_SCHEDULE), response.exception))
92
+ # The batch is dropped once the retries run out. A network error
93
+ # surfaces as a Fake500 that carries the `exception`; a 5xx answer
94
+ # from the server is a real `requests.Response` without one, so it
95
+ # is reported by its status code instead.
96
+ if _should_retry(response.status_code):
97
+ reason = getattr(response, 'exception', 'HTTP {}'.format(response.status_code))
98
+ print('Failed to send logs to Better Stack after {} retries: {}'.format(len(RETRY_SCHEDULE), reason))
99
99
 
100
100
  self._clean = True
101
101
  if shutdown and self.pipe.empty():
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: logtail-python
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Better Stack client library
5
5
  Home-page: https://github.com/logtail/logtail-python
6
- Download-URL: https://github.com/logtail/logtail-python/tarball/0.5.1
6
+ Download-URL: https://github.com/logtail/logtail-python/tarball/0.5.2
7
7
  Author: Logtail
8
8
  Author-email: hello@logtail.com
9
9
  License: ISC
@@ -3,7 +3,7 @@ import os
3
3
  from setuptools import setup
4
4
 
5
5
 
6
- VERSION = '0.5.1'
6
+ VERSION = '0.5.2'
7
7
  ROOT_DIR = os.path.dirname(__file__)
8
8
 
9
9
  REQUIREMENTS = [
@@ -143,9 +143,44 @@ class TestFlushWorker(unittest.TestCase):
143
143
  for log in first_frame:
144
144
  pipe.put(log, block=False)
145
145
 
146
- fw.step() # must not raise AttributeError
146
+ with patch('builtins.print') as mock_print:
147
+ fw.step() # must not raise AttributeError
147
148
 
148
149
  self.assertTrue(fw._clean)
150
+ # The batch is dropped here, so say why, as the network-error path does.
151
+ mock_print.assert_called_once_with('Failed to send logs to Better Stack after 3 retries: HTTP 500')
152
+
153
+ @patch('logtail.flusher.time.sleep')
154
+ def test_step_logs_any_server_5xx_after_retries(self, _mock_sleep):
155
+ def uploader(frame):
156
+ resp = requests.models.Response()
157
+ resp.status_code = 503
158
+ return resp
159
+
160
+ pipe, _, fw = self._setup_worker(uploader)
161
+ pipe.put('log', block=False)
162
+
163
+ with patch('builtins.print') as mock_print:
164
+ fw.step()
165
+
166
+ mock_print.assert_called_once_with('Failed to send logs to Better Stack after 3 retries: HTTP 503')
167
+
168
+ @patch('logtail.flusher.time.sleep')
169
+ def test_step_does_not_log_when_a_retry_succeeds(self, _mock_sleep):
170
+ status_codes = iter([500, 503, 202])
171
+
172
+ def uploader(frame):
173
+ resp = requests.models.Response()
174
+ resp.status_code = next(status_codes)
175
+ return resp
176
+
177
+ pipe, _, fw = self._setup_worker(uploader)
178
+ pipe.put('log', block=False)
179
+
180
+ with patch('builtins.print') as mock_print:
181
+ fw.step()
182
+
183
+ mock_print.assert_not_called()
149
184
 
150
185
  @patch('logtail.flusher.time.sleep')
151
186
  def test_step_still_logs_network_error_fake500(self, _mock_sleep):
@@ -164,7 +199,7 @@ class TestFlushWorker(unittest.TestCase):
164
199
  with patch('builtins.print') as mock_print:
165
200
  fw.step()
166
201
 
167
- mock_print.assert_called_once()
202
+ mock_print.assert_called_once_with('Failed to send logs to Better Stack after 3 retries: network is down')
168
203
 
169
204
  def test_shutdown_condition_empties_queue_and_shuts_down(self):
170
205
  self.buffer_capacity = 10
File without changes
File without changes