Skip to content

Commit 64904f5

Browse files
authored
fix(cloudflare): calculate retries not attempts (#16834)
The `message.attempts` property starts at 1 so we were calculating the number of attempts not the number of retries. Attempt 2 is the first retry not attempt 1. Currently the retry count is the same as the number of messages in the batch this way: ![Screenshot 2025-07-07 at 23 40 48](https://github.com/user-attachments/assets/69ee5947-4677-4bd4-b0e1-33c1b62c0a10) Additionally this causes the error rate to be quite nice and I have been assured my code is not THAT bad: ![Screenshot 2025-07-07 at 23 41 43](https://github.com/user-attachments/assets/738cbd9b-f4fe-4213-a40c-820fe402befc) See: https://developers.cloudflare.com/queues/configuration/javascript-apis/
1 parent 95c4fe3 commit 64904f5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/cloudflare/src/handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
175175
'messaging.destination.name': batch.queue,
176176
'messaging.system': 'cloudflare',
177177
'messaging.batch.message_count': batch.messages.length,
178-
'messaging.message.retry.count': batch.messages.reduce((acc, message) => acc + message.attempts, 0),
178+
'messaging.message.retry.count': batch.messages.reduce(
179+
(acc, message) => acc + message.attempts - 1,
180+
0,
181+
),
179182
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'queue.process',
180183
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.queue',
181184
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',

packages/cloudflare/test/handler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ describe('withSentry', () => {
843843
'messaging.destination.name': batch.queue,
844844
'messaging.system': 'cloudflare',
845845
'messaging.batch.message_count': batch.messages.length,
846-
'messaging.message.retry.count': batch.messages.reduce((acc, message) => acc + message.attempts, 0),
846+
'messaging.message.retry.count': batch.messages.reduce((acc, message) => acc + message.attempts - 1, 0),
847847
'sentry.sample_rate': 1,
848848
'sentry.source': 'task',
849849
},

0 commit comments

Comments
 (0)