-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(cloudflare): Add instrumentWorkflowWithSentry
to instrument workflows
#16672
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
Conversation
return wrapRequestHandler({ options, request: context.request, context }, () => context.next()); | ||
return wrapRequestHandler({ options, request: context.request, context: { ...context, props: {} } }, () => | ||
context.next(), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was due to updating to the latest Cloudflare types.
ExecutionContext
now has a props
property which isn't on EventPluginContext
.
@@ -34,7 +34,7 @@ export function initCloudflareSentryHandle(options: CloudflareOptions): Handle { | |||
return wrapRequestHandler( | |||
{ | |||
options: opts, | |||
request: event.request, | |||
request: event.request as Request<unknown, IncomingRequestCfProperties<unknown>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type updates also broke this...
❌ Unsupported file format
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work - just some small comments.
…try/sentry-javascript into timfish/feat/cloudflare-workflows
It was tricky to instrument Cloudflare workflows! The code for a workflow might look simple but there is a lot of clever shenanigans going on under the hood in the runtime to allow suspension of workflows. Workflows can be hibernated at any time and all state/context inside the your workflow class and elsewhere is lost. Ideally we want all of our step runs to have the same
trace_id
so all steps in a workflow run are linked together and all steps should have the same sampling decision.To work around the state limitations, we use the workflow
instanceId
as both the Sentrytrace_id
and the last 4 characters are used to generate thesample_rand
used in the sampling decision. Cloudflare uses uuid's by default forinstanceId
but users do have the option of passing their own IDs. If users are supplying their owninstanceId
's, they need to be both random and a 32 character uuid (with or without hyphens) or the Sentry instrumentation will throw an error.Points worthy of note:
enableDedupe
config option (docs hidden) which removes thededupeIntegration
for workflows. We want to get duplicate errors for step retriesWorkflowStep
object in another class. The Cloudflare step object is native so it's properties can't be overridden or proxiedin_app: false
step.sleep
,step.sleepUntil
orstep.waitForEvent
because code doesn't run after the Cloudflare native function returnssetPropagationContext
directly on the isolation context didn't work. It needed anotherwithScope
inside forsetPropagationContext
to work. @mydea is that expected?Here is an example trace showing the final step failing (throwing) 6 times before completing successfully. The exponential retry backoff is clearly visible.