Skip to content

Commit 144bd24

Browse files
authored
Merge branch 'master' into neelkanth-kaushik/LIBRARIES-2434
2 parents 5321347 + bc40fba commit 144bd24

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 2.3.5 / 2025-11-18
2+
- Fix for Github Issue #516
3+
- Fix for Github Issue #515
4+
- Fix for Github Issue #493
5+
- Updated the version to 2.3.5
6+
- 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.
7+
- Moved the return success out of the finally block in segment/analytics/consumer.py at Line 84.
8+
- Removed redundant error logging in segment/analytics/request.py to avoid duplicate logs when exceptions are raised.
9+
110
# 2.3.4 / 2025-2-24
211
- Fix for proxy values not being used
312

segment/analytics/consumer.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
# lower to leave space for extra data that will be added later, eg. "sentAt".
1515
BATCH_SIZE_LIMIT = 475000
1616

17+
1718
class FatalError(Exception):
1819
def __init__(self, message):
1920
self.message = message
21+
2022
def __str__(self):
2123
msg = "[Segment] {0})"
2224
return msg.format(self.message)
@@ -81,7 +83,7 @@ def upload(self):
8183
# mark items as acknowledged from queue
8284
for _ in batch:
8385
self.queue.task_done()
84-
return success
86+
return success
8587

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

137+
attempt_count = 0
138+
135139
@backoff.on_exception(
136140
backoff.expo,
137141
Exception,
138142
max_tries=self.retries + 1,
139-
giveup=fatal_exception)
143+
giveup=fatal_exception,
144+
on_backoff=lambda details: self.log.debug(
145+
f"Retry attempt {details['tries']}/{self.retries + 1} after {details['elapsed']:.2f}s"
146+
))
140147
def send_request():
141-
post(self.write_key, self.host, gzip=self.gzip,
142-
timeout=self.timeout, batch=batch, proxies=self.proxies,
143-
oauth_manager=self.oauth_manager)
148+
nonlocal attempt_count
149+
attempt_count += 1
150+
try:
151+
return post(self.write_key, self.host, gzip=self.gzip,
152+
timeout=self.timeout, batch=batch, proxies=self.proxies,
153+
oauth_manager=self.oauth_manager)
154+
except Exception as e:
155+
if attempt_count >= self.retries + 1:
156+
self.log.error(f"All {self.retries} retries exhausted. Final error: {e}")
157+
raise
144158

145159
send_request()

segment/analytics/request.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ def post(write_key, host=None, gzip=False, timeout=15, proxies=None, oauth_manag
5454
try:
5555
res = _session.post(url, **kwargs)
5656
except Exception as e:
57-
log.error(e)
5857
raise e
59-
58+
6059
if res.status_code == 200:
6160
log.debug('data uploaded successfully')
6261
return res

segment/analytics/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.3.4'
1+
VERSION = '2.3.5'

0 commit comments

Comments
 (0)