Commit ff7a07d
authored
With
[waitUntil](https://vercel.com/docs/functions/functions-api-reference#waituntil)
the lambda execution continues until all async tasks (like sending data
to Sentry) are done.
Timing-wise it should work like this: `span.end()` -> `waitUntil()` ->
Nitro/Node `response.end()`
The problem in [this
PR](#13895) was that
the Nitro hook `afterResponse` is called to late (after
`response.end()`), so `waitUntil()` could not be added to this hook.
---
Just for reference how this is done in Nitro (and h3, the underlying
http framework):
1. The Nitro `afterResponse` hook is called in `onAfterResponse`
https://github.com/unjs/nitro/blob/359af68d2b3d51d740cf869d0f13aec0c5e9f565/src/runtime/internal/app.ts#L71-L77
2. h3 `onAfterResponse` is called after the Node response was sent (and
`onBeforeResponse` is called too early for calling `waitUntil`, as the
span just starts at this point):
https://github.com/unjs/h3/blob/7324eeec854eecc37422074ef9f2aec8a5e4a816/src/adapters/node/index.ts#L38-L47
- `endNodeResponse` calls `response.end()`:
https://github.com/unjs/h3/blob/7324eeec854eecc37422074ef9f2aec8a5e4a816/src/adapters/node/internal/utils.ts#L58
1 parent 6bc37f0 commit ff7a07d
1 file changed
+38
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| |||
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
| |||
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
49 | 70 | | |
50 | 71 | | |
51 | 72 | | |
| |||
64 | 85 | | |
65 | 86 | | |
66 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
0 commit comments