Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose cloudflare specific functionality (event.waitUntil) in hooks #2807

Closed
tomyan opened this issue Nov 15, 2021 · 1 comment · Fixed by #3868
Closed

Expose cloudflare specific functionality (event.waitUntil) in hooks #2807

tomyan opened this issue Nov 15, 2021 · 1 comment · Fixed by #3868
Labels
adapters - general Support for functionality general to all adapters pkg:adapter-cloudflare-workers

Comments

@tomyan
Copy link

tomyan commented Nov 15, 2021

Describe the problem

I'm trying to integrate with Sentry from my SvelteKit app that runs on cloudflare workers. Ideally I'd find a library that works when running in dev (i.e. npm run dev running in node) so I can try it out but also works when deployed in cloudflare workers. I don't think this is possible with any of the libraries, so I'm going to try to just get it to work when deployed in workers. I was planning on using toucan-js (https://github.com/punkeel/toucan-js). However this requires that I pass in the "workers fetch event" - the docs say that Toucan has to call the waitUntil method (https://developers.cloudflare.com/workers/runtime-apis/fetch-event#waituntil) - I assume so that it can reliably send the telemetry after the response has gone to the user.

I was wondering if there could be a way to expose features that are specific to the platform being run on like this - in my case I'm definitely targeting cloudflare so I'm okay being somewhat coupled to that platform? I wonder if it would make sense to make it possible for an adaptor to allow access to platform specific functionality and let the developer decide whether to couple to a specific platform or not, rather than force the lowest common denominator on everyone.

Describe the proposed solution

I would like to see an adaptor be able to make available provider specific options to the handle hook. I would then also like to see the cloudflare adapter provide this, although I'm using my own out of tree adapter (https://github.com/budgetdraw/sveltekit-cloudflare-adapter) so this is less relevant to me.

Alternatives considered

There is another sentry library targeting cloudflare workers:

https://github.com/cfworker/cfworker/blob/main/packages/sentry/README.md

This also suggests using FetchEvent.waitUntil.

I also noticed that the SvelteKit docs include a Sentry example:

https://kit.svelte.dev/docs#hooks-handleerror

However, I assume this is using the @sentry/node package (https://www.npmjs.com/package/@sentry/node), which wouldn't work (I don't think) when deployed to a worker.

Importance

would make my life easier

Additional Information

No response

@tomyan
Copy link
Author

tomyan commented Nov 16, 2021

I guess this might already be possible by adding extra key(s) to the request object outside the interface described in the documentation. If so perhaps what I'm asking for is an official way to do this

tomyan pushed a commit to budgetdraw/sveltekit-cloudflare-adapter that referenced this issue Nov 17, 2021
This allows for use of the waitFor method on the fetch event, which
at present isn't possible (as far as I know) in the standard SvelteKit
API. See sveltejs/kit#2807.
@benmccann benmccann added pkg:adapter-cloudflare-workers adapters - general Support for functionality general to all adapters labels Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters - general Support for functionality general to all adapters pkg:adapter-cloudflare-workers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants