✨ support asynchronous beforeSend callbacks - #4964
Conversation
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 24b825a | Docs | View more details | Give us feedback! |
de2cd10 to
650935c
Compare
Bundles Sizes Evolution
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 650935c9a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
650935c to
7243a4b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7243a4b61a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
7243a4b to
eb3d440
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb3d440f0b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
eb3d440 to
24b825a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24b825af7c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Async beforeSend may deliver view events out of order — discard stale updates | ||
| // before any branch logic so they can't corrupt per-view state. | ||
| const lastVersion = viewVersions.get(viewId) | ||
| if (lastVersion !== undefined && serverRumEvent._dd.document_version < lastVersion) { |
There was a problem hiding this comment.
trackEventCounts also subscribes to RUM_EVENT_COLLECTED and its counters end up in view.action.count, view.error.count, etc. through processViewUpdate. With an async callback the child event is counted when the promise resolves instead of when it's collected, so the final update triggered in view.end() can ship with lower counts. startRumEventBridge has the same gap since it never goes through createBatchDispatcher. Should this live in the assembly so every RUM_EVENT_COLLECTED consumer gets it?
| } | ||
|
|
||
| function handleBeforeSendResult(beforeSendResult: unknown) { | ||
| if (!shouldSend(serverRumEvent, beforeSendResult, eventRateLimiters)) { |
There was a problem hiding this comment.
The rate limit check now runs after the promise resolves, and I think that breaks allowNextEvent in createEventRateLimiter. It sets the flag, calls onLimitReached, then resets it in a finally, so it only works if the agent error reaches isLimitReached() in the same tick. With an async callback the promise is still pending at that point, so the "Reached max number of errors by minute" event gets dropped too. Logs isn't affected thanks to the log.origin !== ErrorSource.AGENT guard, should we add the same one here?
Motivation
Allow RUM and Logs
beforeSendcallbacks to perform asynchronous enrichment or filtering before an event is sent—for example, reading a fetch response from the resource event domain context.Changes
Promise<boolean>results from RUM and LogsbeforeSendcallbacks while preserving synchronous callback behavior.Test instructions
beforeSendcallback.context.response.text()and add the result to the event context.Checklist