Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cloudflare): Missing events inside waitUntil#18486

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
JPeer264 wants to merge3 commits intodevelop
base:develop
Choose a base branch
Loading
fromjp/wait-for-waituntil

Conversation

@JPeer264
Copy link
Member

follow up to#16681

Problem

The waitUntil could take longer than the actual request is taking, which is actually a good thing and wanted by Cloudflare. By definition of our implementation we are ending the root span at the end of the request, while the promise inside waitUntil could still generate events. These events are only send while the root span is still active ("Event 1" in the mermaid diagram), but are not send anymore when the root span ended ("Event 2") and are basically dropped.

sequenceDiagram    participant R as Request    participant W as waitUntil    participant S as Sentry Spans    Note over R: Request starts    activate R        R->>S: Root span starts    activate S        Note over R,W: User calls ctx.waitUntil(promise)    R->>W: Promise created    activate W        W->>S: Event 1 ✓    Note over S: Captured (span still active)        Note over R: Request handler returns    deactivate R        R->>S: Root span ends    deactivate S        Note over W: waitUntil continues running...        W->>S: Event 2 ✗    Note over S: LOST!<br/>Span already ended        W->>W: waitUntil completes    deactivate W
Loading

Solution

There is a way to end the root span after everything has been finished, which allows us to send everything in one transaction. In order to still have a correct span for the request itself, I had to create a dedicated span just for the request (that can be seen in the "after" picture beneath).

Right now we only send one transaction after everything is finished, which could take up to "request time" + 30 seconds (that is the maximum wait time for awaitUntil). Which means Sentry gets that data after that time. Very soon there will be the concept ofspan streaming which would make these events available earlier.

sequenceDiagram    participant R as Request    participant W as waitUntil    participant S as Root Span    Note over R: Request starts    activate R        R->>S: Root span starts    activate S        Note over R,W: User calls ctx.waitUntil(promise)    R->>W: Promise created    activate W        W->>S: Event 1 ✓        Note over R: Request handler returns    deactivate R        Note over S: Root span stays open!<br/>Waiting for waitUntil...        Note over W: waitUntil continues running...        W->>S: Event 2 ✓    Note over S: Captured!<br/>Same transaction        W->>W: waitUntil completes    deactivate W        R->>S: Root span ends (after all waitUntil done)    deactivate S
Loading

Special eyes

There is now an extra span for thefetch, which is basically the request itself. So this can be looked at with a critical eye

Comparison

before:

Screenshot 2025-12-12 at 15 02 10

after:

Screenshot 2025-12-12 at 15 00 19

@github-actions
Copy link
Contributor

github-actionsbot commentedDec 12, 2025
edited
Loading

size-limit report 📦

PathSize% ChangeChange
@sentry/browser24.81 kB--
@sentry/browser - with treeshaking flags23.3 kB--
@sentry/browser (incl. Tracing)41.56 kB--
@sentry/browser (incl. Tracing, Profiling)46.15 kB--
@sentry/browser (incl. Tracing, Replay)79.98 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags69.7 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)84.65 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)96.9 kB--
@sentry/browser (incl. Feedback)41.52 kB--
@sentry/browser (incl. sendFeedback)29.49 kB--
@sentry/browser (incl. FeedbackAsync)34.48 kB--
@sentry/react26.52 kB--
@sentry/react (incl. Tracing)43.76 kB--
@sentry/vue29.27 kB--
@sentry/vue (incl. Tracing)43.37 kB--
@sentry/svelte24.82 kB--
CDN Bundle27.24 kB--
CDN Bundle (incl. Tracing)42.23 kB--
CDN Bundle (incl. Tracing, Replay)78.75 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)84.21 kB--
CDN Bundle - uncompressed80.04 kB--
CDN Bundle (incl. Tracing) - uncompressed125.39 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed241.42 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed254.18 kB--
@sentry/nextjs (client)45.98 kB--
@sentry/sveltekit (client)41.93 kB--
@sentry/node-core51.5 kB--
@sentry/node160.31 kB--
@sentry/node - without tracing92.91 kB--
@sentry/aws-serverless108.44 kB+0.01%+1 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

github-actionsbot commentedDec 15, 2025
edited
Loading

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

ScenarioRequests/s% of BaselinePrev. Requests/sChange %
GET Baseline8,932-9,114-2%
GET With Sentry1,77020%1,778-0%
GET With Sentry (error only)6,24870%6,189+1%
POST Baseline1,212-1,233-2%
POST With Sentry60250%616-2%
POST With Sentry (error only)1,07889%1,086-1%
MYSQL Baseline3,350-3,399-1%
MYSQL With Sentry50615%531-5%
MYSQL With Sentry (error only)2,75582%2,769-1%

View base workflow run

@JPeer264
Copy link
MemberAuthor

This PR is on hold for now, because we add another span in here and this might not be optimal in all situations. We'll try to use the span streaming implementation and see if we can use the same behavior as before, but send thewait_until spans after the request span has ended.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@JPeer264

[8]ページ先頭

©2009-2025 Movatter.jp