Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 2.3.5 / 2025-11-18
- Fix for Github Issue #516
- Fix for Github Issue #515
- Fix for Github Issue #493
- Updated the version to 2.3.5
- Enhanced retry logic in segment/analytics/consumer.py by adding detailed debug logs for each retry attempt and logging an error when all retries are exhausted.
- Moved the return success out of the finally block in segment/analytics/consumer.py at Line 84.
- Removed redundant error logging in segment/analytics/request.py to avoid duplicate logs when exceptions are raised.

# 2.3.4 / 2025-2-24
- Fix for proxy values not being used

Expand Down
24 changes: 19 additions & 5 deletions segment/analytics/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# lower to leave space for extra data that will be added later, eg. "sentAt".
BATCH_SIZE_LIMIT = 475000


class FatalError(Exception):
def __init__(self, message):
self.message = message

def __str__(self):
msg = "[Segment] {0})"
return msg.format(self.message)
Expand Down Expand Up @@ -81,7 +83,7 @@ def upload(self):
# mark items as acknowledged from queue
for _ in batch:
self.queue.task_done()
return success
return success

def next(self):
"""Return the next batch of items to upload."""
Expand Down Expand Up @@ -132,14 +134,26 @@ def fatal_exception(exc):
# retry on all other errors (eg. network)
return False

attempt_count = 0

@backoff.on_exception(
backoff.expo,
Exception,
max_tries=self.retries + 1,
giveup=fatal_exception)
giveup=fatal_exception,
on_backoff=lambda details: self.log.debug(
f"Retry attempt {details['tries']}/{self.retries + 1} after {details['elapsed']:.2f}s"
))
def send_request():
post(self.write_key, self.host, gzip=self.gzip,
timeout=self.timeout, batch=batch, proxies=self.proxies,
oauth_manager=self.oauth_manager)
nonlocal attempt_count
attempt_count += 1
try:
return post(self.write_key, self.host, gzip=self.gzip,
timeout=self.timeout, batch=batch, proxies=self.proxies,
oauth_manager=self.oauth_manager)
except Exception as e:
if attempt_count >= self.retries + 1:
self.log.error(f"All {self.retries} retries exhausted. Final error: {e}")
raise

send_request()
3 changes: 1 addition & 2 deletions segment/analytics/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ def post(write_key, host=None, gzip=False, timeout=15, proxies=None, oauth_manag
try:
res = _session.post(url, **kwargs)
except Exception as e:
log.error(e)
raise e

if res.status_code == 200:
log.debug('data uploaded successfully')
return res
Expand Down
2 changes: 1 addition & 1 deletion segment/analytics/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.3.4'
VERSION = '2.3.5'