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
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):
@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.tstrpcContext.ts- just a function that creates the trpcContext (
Sentry.init()is called here)
- just a function that creates the trpcContext (
worker.ts- hono server running on CF workers
- pass in the
SENTRY_DSNkey as a Cloudflare binding - (file:workers.ts) - create a
trpcServerserver middleware as per the @hono/trpc-server documentation - (file:worker.ts)
SENTRY_DSN - (file:
trpcContext.ts)
SENTRY_DSN key in the context, I pass this key to Sentry.init() - which comes from
sentry/browser. - (file:trpcContext.ts)
Sentry.init() which I now have access to in every single procedure - (file: trpcContext.ts - line 61)
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)