Cloudflare SDK Initial Roadmap #13007
AbhiPrasad
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
ref: #12620
Over the past 2 weeks I've been looking at building out a Cloudflare SDK. Initially I was focusing on just cloudflare workers, but I soon realized that cloudflare pages support is extremely important, because a vast majority of the users who wanted Sentry supported were using cloudflare pages (in conjuction with remix, next.js, sveltekit, nuxt, etc.).
This is a writeup that goes through where we started from, and outlines the public API design of
@sentry/cloudflare
, the SDK we are set to release soon.Prior art
Our recommended solution for cloudflare workers has been Toucan.js, which has worked pretty well for many users.
Here is the expected usage of Toucan:
Cloudflare themselves point their users to use Toucan, and even created a Cloudlfare Pages plugin that leverages Toucan under the hood:
Aside from Toucan, Cloudflare has also has a Sentry integration that leverages Tail Workers, out-of-band processes that receive information from the main process worker that can then asynchronously flush data to different sources.
Drawbacks of prior art
For it's purpose, Toucan works very well. There are few drawbacks in just using Toucan directly for your applications. The primary hurdles with Toucan are with it's developer experience.
@sentry/remix
,@sentry/sveltekit
).The tail worker has more drawbacks.
@sentry/cloudflare
We are building
@sentry/cloudflare
as an attempt to unify the Sentry experience with Cloudflare, and support workers and pages accordingly. We would also like to add specialized instrumentation for Cloudflare's different products that connect to workers via bindings (D1, R2, queues, etc.) and support all the handlers that workers have (alarm, queue, scheduled, etc.).Because we require tracing support as top-of-mind priority,
AsyncLocalStorage
support is a requirement of the SDK. This means that (for now)compatibility_flags = ["nodejs_compat"]
orcompatibility_flags = ["nodejs_als"]
is required to be set to use the SDK.Using
@sentry/cloudflare
with standalone workerWhen just using
@sentry/cloudflare
with a standalone worker, you do something like so:withSentry
is a helper function that wraps your worker. It takes two arguments. The first is identical toSentry.init
, and represents the sentry instance created for each handler instantiation. This needs to be done because workers can change their bindings (env
) without re-deploying the entire worker, so a top-levelSentry.init
call would become stale.Under the hood this would use
ctx.waitUntil
to flush events, which means it has the same drawback as Toucan to keep the worker alive the entire execution time.Using
@sentry/cloudflare
with cloudflare pagesGiven there is a recommended way to publish pages plugins, we would format this the same way
@cloudflare/pages-plugin-sentry
works.Under the hood this would use
@sentry/cloudflare
.Using
@sentry/cloudflare
with meta-framework SDKsGiven we re-export everything from
@sentry/cloudflare/pages
, we can easily use this in the metaframeworks and re-export as necessary. To start though, we'll probably recommend installing a separate package.@sentry/cloudflare
integrationsOnce we have the worker and pages setup ready, we can start building out integrations for all of the different cloudflare products. We can create spans for R2/D1/Analytics Engine, automatically instrument cloudflare crons, and more!
Next Steps
After this has been initially released, there are a variety of improvements we can look to make.
@sentry/cloudflare
to completely leverage tail workers and make sure it never flushes on the main process.a. automatically create/manage Sentry projects
b. setup sourcemaps uploading
c. Bi-directionally link cloudflare w/ Sentry and let folks go back and forth from the different dashboards.
Beta Was this translation helpful? Give feedback.
All reactions