-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(cloudflare): instrument scheduled handler #13114
Conversation
20adfb9
to
1482a37
Compare
Drafting this PR for the time being because #13123 refactors a lot of this code, so this PR needs to be updated. Hence let's wait for that to get merged in first, and then look at this one in more detail. |
16ddfe8
to
6aa304f
Compare
This is now ready to review - I refactored this PR to pull in the refactors from #13123 |
attributes: { | ||
'faas.cron': event.cron, | ||
'faas.time': new Date(event.scheduledTime).toISOString(), | ||
'faas.trigger': 'timer', |
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.
These are from https://opentelemetry.io/docs/specs/semconv/faas/faas-spans
|
||
addCloudResourceContext(isolationScope); | ||
|
||
return startSpan( |
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 duplication with the request handler is not ideal, but I'd rather refactor this later once I'm more confident in the API design of the withIsolationScope
callback.
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.
looks good from my pov
handler.scheduled = new Proxy(handler.scheduled, { | ||
apply(target, thisArg, args: Parameters<ExportedHandlerScheduledHandler<ExtractEnv<E>>>) { | ||
const [event, env, context] = args; | ||
return withIsolationScope(isolationScope => { |
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.
just for my understanding, what do we need this isolation scope for here?
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.
To make sure scope bleed doesn't happen. If you define both a scheduled
handler and a fetch
handler, there's a chance that both happen at the same time, so we need to isolate accordingly.
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } }); | ||
throw e; | ||
} finally { | ||
context.waitUntil(flush(2000)); |
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.
why do we need to wait here?
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.
waitUntil
will execute keep the serverless function alive until we flush out all sentry requests, but it will ensure that this happens after a response is sent. Therefore flushing to sentry does not block sending a response back to whatever sent the request to the cloudflare worker.
a0a3666
to
459be04
Compare
resolves #13112
This PR adds instrumentation for the
scheduled
handler in cloudflare workers. This is used for cron triggers.I elected to not do automatic cron instrumentation for now, this is tracked by #13113. Instead I added manual instrumentation docs to the README, this will get copied to the sentry docs eventually.
ref #12620