feat(nextjs): Add body data to transaction request context
#3672
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds data from the request body to the
requestcontext data on server-side transactions.This data is already being collected for errors (because in that case we use the
parseRequestfunction from@sentry/node, which collects body data), but for transactions we haven't been (there we useaddRequestDataToEvent, which collects similar data, but has had body data as aTODO).My first version of this PR simply swapped
addRequestDataToEventout in favor ofparseRequest, which both fixes the missing body data and gets rid of some redundancy in the code. Unfortunately, the new end-to-end tests revealed that that would in fact be a breaking change, since in theurlfieldparseRequestsends a full URL whereasaddRequestDataToEventsends only the path. Becauserequest.urlgets copied over as a tag during ingest, and various features in Sentry's web app (alert rules, auto assignment, saved searches, etc) can rely on matching a certain tag value, the format change probably needs to wait for at least a minor bump, if not a major one.Therefore, the final version of this change simply adds body data collection to
addRequestDataToEvent, and leaves aTODOabout switching toparseRequestin the future. Also, as part of my first attempt, I modifiedparseRequestslightly to adapt it fornextjsuse, and since none of those changes affect any other platform, I left them in, so that the eventual swap is as easy as possible.