Skip to content

Conversation

@lobsterkatie
Copy link
Member

This PR adds data from the request body to the request context data on server-side transactions.

This data is already being collected for errors (because in that case we use the parseRequest function from @sentry/node, which collects body data), but for transactions we haven't been (there we use addRequestDataToEvent, which collects similar data, but has had body data as a TODO).

My first version of this PR simply swapped addRequestDataToEvent out in favor of parseRequest, 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 the url field parseRequest sends a full URL whereas addRequestDataToEvent sends only the path. Because request.url gets 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 a TODO about switching to parseRequest in the future. Also, as part of my first attempt, I modified parseRequest slightly to adapt it for nextjs use, and since none of those changes affect any other platform, I left them in, so that the eventual swap is as easy as possible.

@github-actions
Copy link
Contributor

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.97 KB (0%)
@sentry/browser - Webpack 21.84 KB (0%)
@sentry/react - Webpack 21.88 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.36 KB (0%)

}

if (options.transaction && !event.transaction) {
// TODO do we even need this anymore?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afair it will be dropped in the next major.

// query string:
// node: req.url (raw)
// express, koa: req.query
// express, koa, nextjs: req.query
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad it worked despite incorrect comment 😶

@lobsterkatie lobsterkatie merged commit 1054d3d into master Jun 14, 2021
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-add-body-data-to-request-context branch June 14, 2021 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants