sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Edge runtime server actions don't log handled errors

Open Xexr opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.113.0

Framework Version

Next 14.2.3

Link to Sentry event

No response

SDK Setup

Sentry.init({
  dsn: process.env['NEXT_PUBLIC_SENTRY_DSN'],
  tracesSampleRate: 1,
  debug: false,
});

Steps to Reproduce

I've noticed that Sentry does not log handled errors in nextjs server actions when using the edge runtime.

The same code when run on the node runtime works fine.

Minimal reproduction with instructions: https://github.com/Xexr/sentry-edge-error

Expected Result

Sentry should record the error event "test action error" when pressing the "Test action" button.

Actual Result

You will see that clicking the test button does not generate a Sentry entry.

If you comment out the edge runtime line, you'll see that it starts to work correctly.

Note: this seems to only be the case specifically for caught errors in a server action running on the edge runtime.

Xexr avatar May 03 '24 09:05 Xexr

Hi, thanks for writing in! I just tried out your reproduction example and indeed I had trouble receiving events. I received some, but very inconsistently.

The edge runtime needs a manual await Sentry.flush() call to flush out pending events. I recommend you use Sentry.withServerActionInstrumentation which will do this implicitly: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#instrument-nextjs-server-actions

I see that our docs do not document this at all, however, generally the SDKs auto instrumentation will call flush automatically. We just don't have any automatic instrumentation for server actions yet.

lforst avatar May 06 '24 09:05 lforst

Thanks @lforst

Yes, agreed its inconsistent, I have noticed that very occasionally some events get through, but its rare.

I originally started by using Sentry.withServerActionInstrumentation but was finding the same issue. That doesn't seem to be the case now, so I'll switch back to that.

For my reference though - are you saying that if I call await Sentry.flush() before calling captureException, it should then work too (outside of withServerActionInstrumentation)?

Xexr avatar May 07 '24 09:05 Xexr

flush() flushes all events that are pending to be sent, so you should call it at the end of your request.

lforst avatar May 07 '24 10:05 lforst

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

getsantry[bot] avatar Jun 06 '24 07:06 getsantry[bot]