Skip to content

Conversation

@lobsterkatie
Copy link
Member

This PR does two things:

  1. It wraps two more methods on next's Server class, one of which is called on every API request, and the other of which is called on every page request. Both methods are passed a parameterized version of the path, which our wrappers grab and use to modify the name of the currently active transaction.

  2. It adds an event processor which pulls data off of the request and adds it to the event. This runs whether or not tracing is enabled, in order to add data to both error and transaction events.

The only other thing of minor interest is that the type for Event.request.query_string is expanded to include objects, which is okay according to the dev docs.

@lobsterkatie lobsterkatie requested a review from kamilogorek as a code owner May 20, 2021 23:02
@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.76 KB (+0.01% 🔺)
@sentry/browser - Webpack 21.98 KB (0%)
@sentry/react - Webpack 22.01 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.16 KB (0%)


// requests for pages will only ever be GET requests, so don't bother to include the method in the transaction
// name; requests to API routes could be GET, POST, PUT, etc, so do include it there
const namePrefix = req.url.startsWith('/api') ? `${(req.method || 'GET').toUpperCase()} ` : '';
Copy link
Member

Choose a reason for hiding this comment

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

@HazAT pinging Daniel to give his thoughts on the name prefix for transaction

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what we agreed to in our meeting, no? API requests might have different methods, but page requests are always GET, so include the method for API calls, and not for the page ones. I believe I even confirmed it with him afterwards.

const transaction = Sentry.startTransaction({
name: `${namePrefix}${reqPath}`,
op: 'http.server',
metadata: { request: req },
Copy link
Member

Choose a reason for hiding this comment

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

Can we store the req.method as a tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we can. I'm curious why, though, given that it's in the transaction name if it's anything other than GET.

if (transaction && transaction.metadata.request) {
// strip query string, if any
const origPath = transaction.metadata.request.url.split('?')[0];
transaction.name = transaction.name.replace(origPath, parameterizedPath);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we do a .replace here instead of just overwriting the URL?

Copy link
Member

Choose a reason for hiding this comment

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

Also will this affect users manual transactions as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I used replace because some of the transaction names have the method, and I only want to overwrite the URL part. As for manual transactions, it would only affect them if they a) store the correct metadata on the transaction, and b) have a request URL as part or all of their transaction name. Though not technically impossible... it still feels unlikely.

@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-parameterize-transaction-name branch from 40bab14 to f960139 Compare May 22, 2021 03:28
@lobsterkatie lobsterkatie merged commit a0bab2f into kmclb-next-js-performance May 25, 2021
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-parameterize-transaction-name branch May 25, 2021 13:34
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.

4 participants