Replies: 1 comment 2 replies
-
Hi, this is a good question. I have not used It wasn't clear to me from their docs how What I would do is make a light weight builder function to wrap server actions in a export const createSentryInstrumentedAction = <
TServerAction extends (...args: any) => Promise<any>,
>(params: {
name: string
action: TServerAction
}) => {
return async (
...args: Parameters<TServerAction>
): Promise<ReturnType<TServerAction>> => {
return await Sentry.startSpan(
{
name: params.name,
},
async () => {
const [data, err] = await params.action(...args)
if (err) {
Sentry.captureException(err)
}
return [data, err]
}
)
}
} Then when you make actions, you would do something like this: "use server"
export const myMonitoredAction = createSentryInstrumentedAction({
name: "myMonitoredAction",
action: adminActionProc
.createServerAction()
.input(createCategorySchema)
.handler(async ({ input }) => {
// normal logic
return `hello world` as const
}),
}) Hopefully that puts you in the right direction. Let me know if it helps -- I can add this to our main docs! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm at the point where I'm using zsa daily in my projects, but now I need to bring in Sentry.io for catching errors.
I know that zsa catches errors too, so I'm really confused on how to make both libraries work together.
I found this article where Sentry team explains on how to use it with server actions: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#instrument-nextjs-server-actions
But couldn't understand if I should wrap zsa procedure with sentry or is it vice versa?
Do I even need to capture errors in server actions?
For example I have a server action:
Should I do it like this?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions