Skip to content

Commit f99ac40

Browse files
committed
fix: handle non-retryable errors
1 parent f11664e commit f99ac40

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • drift/core/tracing/adapters

‎drift/core/tracing/adapters/api.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
)
2727
from .base import ExportResult, SpanExportAdapter
2828

29+
30+
class NonRetryableError(Exception):
31+
"""Error that should not be retried (e.g., 4xx client errors)."""
32+
33+
pass
34+
35+
2936
if TYPE_CHECKING:
3037
from betterproto.lib.google.protobuf import Struct
3138

@@ -162,11 +169,12 @@ async def export_spans(self, spans: list[CleanSpanData]) -> ExportResult:
162169
async def do_export() -> ExportResult:
163170
return await self._do_export(spans)
164171

165-
# Execute with retry
172+
# Execute with retry (NonRetryableError bypasses retry)
166173
result = await retry_async(
167174
do_export,
168175
config=self._retry_config,
169-
retryable_exceptions=(Exception,), # Retry all exceptions
176+
retryable_exceptions=(Exception,),
177+
non_retryable_exceptions=(NonRetryableError,),
170178
operation_name="span_export",
171179
)
172180

@@ -231,9 +239,9 @@ async def _do_export(self, spans: list[CleanSpanData]) -> ExportResult:
231239
error_text = await http_response.text()
232240
raise Exception(f"Server error (status {http_response.status}): {error_text}")
233241
elif http_response.status != 200:
234-
# Client errors (4xx) are not retryable
242+
# Client errors (4xx) are not retryable - fail immediately
235243
error_text = await http_response.text()
236-
raise Exception(f"API request failed (status {http_response.status}): {error_text}")
244+
raise NonRetryableError(f"Client error (status {http_response.status}): {error_text}")
237245

238246
response_bytes = await http_response.read()
239247
response = ExportSpansResponse().parse(response_bytes)

0 commit comments

Comments
 (0)