Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge runtime server actions don't log handled errors #11884

Open
3 tasks done
Xexr opened this issue May 3, 2024 · 3 comments
Open
3 tasks done

Edge runtime server actions don't log handled errors #11884

Xexr opened this issue May 3, 2024 · 3 comments

Comments

@Xexr
Copy link

Xexr commented May 3, 2024

Is there an existing issue for this?

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.

@lforst
Copy link
Member

lforst commented May 6, 2024

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.

@Xexr
Copy link
Author

Xexr commented May 7, 2024

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)?

@lforst
Copy link
Member

lforst commented May 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Status: Waiting for: Community
Development

No branches or pull requests

3 participants