diff --git a/src/axiom_py/client.py b/src/axiom_py/client.py index f34bb1c..dcf6824 100644 --- a/src/axiom_py/client.py +++ b/src/axiom_py/client.py @@ -235,12 +235,25 @@ def ingest( # prepare query params params = self._prepare_ingest_options(opts) - # override the default header and set the value from the passed parameter - res = self.session.post( - path, data=payload, headers=headers, params=params - ) - status_snake = decamelize(res.json()) - return from_dict(IngestStatus, status_snake) + try: + # override the default header and set the value from the passed parameter + res = self.session.post( + path, data=payload, headers=headers, params=params + ) + status_snake = decamelize(res.json()) + return from_dict(IngestStatus, status_snake) + except AxiomError as err: + # Do not crash the app if we cannot save to the logs to Axiom's servers + # Log the error to stdout, since we cannot send it to Axiom + print(err) + return IngestStatus( + ingested=0, + failed=1, + failures=[], + processed_bytes=0, + blocks_created=0, + wal_length=0, + ) def ingest_events( self, diff --git a/tests/test_client.py b/tests/test_client.py index fe00be8..5e4c3c3 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -105,6 +105,22 @@ def test_retries(self): self.client.datasets.get("test") assert len(responses.calls) == 3 + @responses.activate + def test_backend_failures(self): + axiomUrl = os.getenv("AXIOM_URL") or "" + url = f"{axiomUrl}/v1/datasets/{self.dataset_name}/ingest" + responses.add(responses.POST, url, status=503) + responses.add(responses.POST, url, status=503) + responses.add(responses.POST, url, status=503) + responses.add(responses.POST, url, status=503) + + try: + self.client.ingest_events(self.dataset_name, self.events) + except: # noqa: E722 + # fail the test if we crash during ingestion + assert False + assert True + def test_step001_ingest(self): """Tests the ingest endpoint""" data: bytes = ujson.dumps(self.events).encode()