Internal Server Error 500 when triggering worker sometimes

We are using Cloudflare Workers to capture some audit information, our backend triggers the worker via a POST request and includes some audit log information.

This largely seems to work, however, over the past 7 days (which is when we started to use this) we have consistently seen some requests return 500 HTTP codes.

We use Sentry to capture errors, and it clearly shows the POST request to our worker domain returning 500. Using wrangler tail does not provide any information everything is just “ok”. When I use the error and/or cancelled status the tail receives no information.

wrangler tail cloudshelf-audit-handler --format pretty --method POST --status error canceled"

Over the last 7 days Sentry has caught 63000+ responses with a 500 code, 8.6k of them being in the last 24 hours, the last one being 2 minutes ago (again with nothing showing in the tail).

I opened a ticket about this, and the support bot told me that “Since Cloudflare does not generate 500s, you would need to work with your hosting provider”, but given the worker is hosted on the cloudflare edge… I’m now stuck.

Any ideas?

The fact that wrangler tail says the request went ok, suggests that it is the worker code itself that is returning the 500 code. I would suggest looking in your worker for anywhere that a 500 error code might be returned. Getting the response body could also be helpful in determining the source.