Skip to content

Conversation

@MichaelGHSeg
Copy link
Contributor

Summary

Implements improved HTTP response handling and retry logic to align with changes in analytics-java and analytics-next:

  • ✅ Add Authorization header (Basic auth with write key, OAuth Bearer token)
  • ✅ Add X-Retry-Count header on all requests (starts at 0)
  • ✅ Implement Retry-After header support (capped at 300s, doesn't count against retry budget)
  • ✅ Granular status code classification for retryable vs non-retryable errors
  • ✅ Replace backoff decorator with custom retry loop for better control
  • ✅ Exponential backoff with jitter (0.5s base, 60s cap)
  • ✅ Increase max retries from 10 to 1000 (to accommodate faster retry cadence)
  • ✅ Clear OAuth token on 511 Network Authentication Required
  • ✅ 413 Payload Too Large is non-retryable

Status Code Handling

Retryable 4xx: 408, 410, 429, 460
Non-retryable 4xx: 400, 401, 403, 404, 413, 422, and all other 4xx
Retryable 5xx: All except 501, 505
Non-retryable 5xx: 501, 505

Retry-After Behavior

  • Respected for status codes: 408, 429, 503
  • Retry-After attempts do NOT count against backoff retry budget
  • Capped at 300 seconds maximum delay

Test Coverage

  • Added 30 new comprehensive tests
  • Total test suite: 106 tests passing
  • Tests cover: Authorization headers, X-Retry-Count, Retry-After parsing, status code classification, backoff logic, network errors, retry budget separation

Changes

Modified Files

  • segment/analytics/consumer.py: Custom retry loop, status code classification, Retry-After support
  • segment/analytics/request.py: Authorization header, X-Retry-Count header, parse_retry_after()
  • segment/analytics/client.py: Increased default max_retries to 1000
  • segment/analytics/test/test_consumer.py: 13 new test cases
  • segment/analytics/test/test_request.py: 17 new test cases

Alignment

This implementation aligns with:

  • analytics-java commit c3f60c5 and 80cc33d
  • analytics-next commit 31e275d2

🤖 Generated with Claude Code

MichaelGHSeg and others added 2 commits February 11, 2026 19:20
- Add Authorization header with Basic auth (base64 encoded write key)
- Add X-Retry-Count header on all requests (starts at 0)
- Implement Retry-After header support (capped at 300s)
- Retry-After attempts don't count against backoff retry budget
- Add granular status code classification:
  - Retryable 4xx: 408, 410, 429, 460
  - Non-retryable 4xx: 400, 401, 403, 404, 413, 422
  - Retryable 5xx: all except 501, 505
  - Non-retryable 5xx: 501, 505
- Replace backoff decorator with custom retry loop
- Exponential backoff with jitter (0.5s base, 60s cap)
- Clear OAuth token on 511 Network Authentication Required
- 413 Payload Too Large is non-retryable
- Add 30 new comprehensive tests (106 total tests)

Aligns with analytics-java and analytics-next retry behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Aligns with analytics-java change to accommodate shorter backoff
periods (0.5s base, 60s cap). With faster retries, a higher retry
limit allows for better resilience during extended outages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant