sentry-middleware: Switch from `toucan-js` to `@sentry/cloudflare`
Which middleware is the feature for?
@hono/sentry
What is the feature you are proposing?
Upstream is deprecating toucan-js in favor of @sentry/cloudflare.
New library: https://github.com/getsentry/sentry-javascript/tree/develop/packages/cloudflare
@jbergstroem Thank you for the issue.
Hi @sam-lippert, Can you handle this?
@yusukebe I'll start taking a look this weekend.
@sam-lippert Thanks!
Hi @sam-lippert. Is there any progress yet?
Sentry is currently working on a Hono guide that utilizes @sentry/cloudflare. The issue I have with it is that this only works with Cloudflare and it is no longer a hono middleware approach, instead the default export gets wrapped.
@yusukebe @sam-lippert do you see a way to add a cross platform middleware or at least support node, bun, Cloudflare Workers and maybe deno?
@schettn I had done a little digging and found that @sentry/cloudflare does not export its init method from the library itself, and so swapping out toucan-js is a slight challenge. toucan-js calls itself "a Sentry client for Cloudflare Workers," and so I'm hoping that once I can call init on a Cloudflare-supported library, the middleware should work cross-platform as it does now.
I'll look into other libraries too like @sentry/browser to see if something else would be a good fit. Otherwise, if I can't find a workaround, I might need to open a pull request with Sentry and see if they can export init so that it can be used in the middleware.
Maybe @Lms24 can help out here.
https://sentry-docs-git-lforst-hono.sentry.dev/platforms/javascript/guides/hono/#setup-on-other-runtimes https://github.com/getsentry/sentry-javascript/issues/15260#issuecomment-2662445832
Hi, thanks for the tag! I'm a bit booked with stuff so excuse my naive question: What is the concrete ask from Sentry? Do you need an exported init function?
I'm not deeply involved with cloudflare or hono, so I can forward the request to the respective experts once I know what you need :)
Hi @Lms24, the ask is to be able to init Sentry in a cross-platform Hono middleware rather than requiring the withSentry wrapper function only for Cloudflare environments. There is an implementation using toucan-js, and it works in node, deno, bun, and wrangler, but that package will be deprecated at the end of this year:
https://github.com/honojs/middleware/blob/57b9f5dbdca99a05070687a8dcac4b634d058d5b/packages/sentry/src/index.ts#L34-L43
I'm not sure yet if exporting init is specifically required. If there is another cross-platform way to achieve the same goal, then I can use that.
@sam-lippert a middleware shouldn't be too much effort. I'll put it onto my backlog.
@sam-lippert also note that current sentry middleware is not published in JSR, and it would be nice to have it there :) For old version and future one. I can't wait to use the new implementation as the current one is very limited
Just delete the package, its just 10 lines of code anyways. It's really confusing that there is the official sentry guide https://docs.sentry.io/platforms/javascript/guides/hono/ and this "official" package
Hi @sam-lippert, I think it's a good idea to add a description to README.md that tells users toucan-js will be achieved in the near future.
Just delete the package, its just 10 lines of code anyways. It's really confusing that there is the official sentry guide https://docs.sentry.io/platforms/javascript/guides/hono/ and this "official" package
@markwitt1, if you did this then how did you set up the DSN init? Their example doesn't really show that.
@BradNut Check the Sentry docs for your JS runtime, for example https://docs.sentry.io/platforms/javascript/guides/bun/