-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(cloudflare): Flush after waitUntil
#16681
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
feat(cloudflare): Flush after waitUntil
#16681
Conversation
…try's `flush` handling across Cloudflare handlers.
e91f0d9
to
16578ab
Compare
Rather than add an internal |
That would be nice, we just need to make flush get access to the I'm a bit scared patching |
I think we can do it easily with AsyncLocalStorage. I will redo it this way and will see. But, I am not very familiar with the code-base. Do we use flush anywhere else? Except @sentry/cloudflare? |
sentry-javascript/packages/core/src/client.ts Line 318 in d8f12c2
We can just change |
Why only sentry methods? Exception might happen after the flush() promise was resolved and the buffer will not be flushed. Or I am wrong in my assumption? |
There are other usages of Let's make the change to the client then. I'll test this out with https://github.com/getsentry/sentry-mcp, @timfish would appreciate if you can also use your test apps to test this. |
…FlushLock`, ensuring proper synchronization with `waitUntil`. Update tests to validate new `flush` behavior.
I also fixed out-of-scope linter issue (the same module was imported twice: 86f5251) |
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.
Really nice change @0xbad0c0d3 - just one quick thing about the init
API
packages/cloudflare/src/sdk.ts
Outdated
@@ -36,16 +38,19 @@ export function getDefaultIntegrations(options: CloudflareOptions): Integration[ | |||
/** | |||
* Initializes the cloudflare SDK. | |||
*/ | |||
export function init(options: CloudflareOptions): CloudflareClient | undefined { | |||
export function init(options: CloudflareOptions, ctx: ExecutionContext | void): CloudflareClient | undefined { |
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.
Let's make ctx: ExecutionContext | void
part of CloudflareOptions
instead of a separate arg.
void
probably be replaced with ctx?: ExecutionContext
as well.
…with `waitUntil`.
Also found that was missed to modify durable object wrapper |
This commit introduces unit tests to validate the functionality of `instrumentDurableObjectWithSentry`. The tests ensure proper instrumentation of all methods, correct handling of `waitUntil` promises, and interaction with Sentry's `flush` logic.
Basic tests for durableobject has been added |
waitUntil
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.
Mind running yarn fix
to format? Then we are good to merge!
This commit ensures consistency by adding a missing semicolon in the `ctx` property of the `CloudflareOptions` interface. No functional changes were made, but it improves code style and adheres to linting rules.
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #16681 Co-authored-by: AbhiPrasad <18689448+AbhiPrasad@users.noreply.github.com>
This PR aim is to send events if all (if any was scheduled) waitUntil promises were finished. Otherwise you may loose events.
This fixes: #16559