middleware icon indicating copy to clipboard operation
middleware copied to clipboard

sentry-middleware: Switch from `toucan-js` to `@sentry/cloudflare`

Open jbergstroem opened this issue 1 year ago • 14 comments

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 avatar Jan 22 '25 13:01 jbergstroem

@jbergstroem Thank you for the issue.

Hi @sam-lippert, Can you handle this?

yusukebe avatar Jan 23 '25 01:01 yusukebe

@yusukebe I'll start taking a look this weekend.

sam-lippert avatar Jan 24 '25 04:01 sam-lippert

@sam-lippert Thanks!

yusukebe avatar Jan 24 '25 09:01 yusukebe

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 avatar Feb 19 '25 18:02 schettn

@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.

sam-lippert avatar Feb 19 '25 19:02 sam-lippert

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

schettn avatar Feb 19 '25 20:02 schettn

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

Lms24 avatar Feb 20 '25 12:02 Lms24

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 avatar Feb 20 '25 17:02 sam-lippert

@sam-lippert a middleware shouldn't be too much effort. I'll put it onto my backlog.

lforst avatar Feb 25 '25 15:02 lforst

@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

riderx avatar Apr 10 '25 10:04 riderx

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 avatar Jul 01 '25 13:07 markwitt1

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.

yusukebe avatar Jul 01 '25 21:07 yusukebe

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 avatar Jul 14 '25 06:07 BradNut

@BradNut Check the Sentry docs for your JS runtime, for example https://docs.sentry.io/platforms/javascript/guides/bun/

markwitt1 avatar Jul 14 '25 07:07 markwitt1