H
Hono5mo ago
kgni

Sentry - hono/trpc/cloudflare workers

Hi guys, I'm trying to implement sentry into my hono/trpc/cloudflare application. If I'm just using the @hono/sentry middleware, what errors are exactly being caught? Will this middleware automatically catch all expcetions thrown from my middleware trpc server? I guess if I want to have a bit more fine grained control (as to when I'm capturing exceptions) inside of each of my trpc procedures, I need a bit of a different implementation, right? I'm not quite sure if I understood how everything works, I would very much appreciate any feedback! Here is what I'm currently doing to get the sentry instance into my trpc server: (gist for reference): - trpc.ts - trpcContext.ts - just a function that creates the trpcContext (Sentry.init() is called here) - worker.ts - hono server running on CF workers Since Cloudflare workers run on the v8 engine, I' assuming I can just use the sentry/browser package in my workers. 1. pass in the SENTRY_DSN key as a Cloudflare binding - (file: workers.ts) 2. create a trpcServer server middleware as per the @hono/trpc-server documentation - (file: worker.ts) 3a. when creating my tRPC server I pass in my Cloudflare bindings to the trpc context, including the SENTRY_DSN - (file: trpcContext.ts) 3b. now that I have access to the SENTRY_DSN key in the context, I pass this key to Sentry.init() - which comes from sentry/browser. - (file: trpcContext.ts) 3c. I return the instance of Sentry.init() which I now have access to in every single procedure - (file: trpcContext.ts - line 61) 4. as a "catch all", when initializing the trpc server, I can in the errorFormatter check if the error.code === 'INTERNAL_SERVER_ERROR and then capture all these exceptions to sentry, before I return the error to the client. - (file: trpc.ts - line 8) Am I overcomplicating it? I'm afraid I am.
1 Reply
kgni
kgniOP5mo ago
"Since Cloudflare workers run on the v8 engine, I'm assuming I can just use the sentry/browser package in my workers."
Well just found out that toucan-js is the sentry client for CF workers. First issue solved :1012tick:
Want results from more Discord servers?
Add your server