Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(nextjs): UseRequestData integration for errors #5729

Merged

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Sep 13, 2022

In #5703, a new integration, RequestData, was added to take the place of the request-specific event processors we've been using to add request data to transaction events in the nextjs SDK. This builds on that work by making the same switch for error events.

Notes:

  • Because of Clean up code relating to scope/event transaction value  #5718, it's hard to reason about the potential side effects of making major changes to the logic in @sentry/utils/requestData. Therefore, the majority of the new logic in this PR has been added to the integration, and just overwrites the transaction value added by the functions in requestData. Once we've cleaned up the request data code, we can consolidate the logic.

@lobsterkatie lobsterkatie marked this pull request as draft September 13, 2022 04:23
@lobsterkatie lobsterkatie changed the base branch from master to kmclb-nextjs-add-requestdata-integration September 13, 2022 04:37
@lobsterkatie lobsterkatie mentioned this pull request Sep 13, 2022
43 tasks
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-add-requestdata-integration branch from e0c4edc to 96d9a6c Compare September 13, 2022 16:54
lobsterkatie added a commit that referenced this pull request Sep 17, 2022
As part of the work adding a `RequestData` integration, this moves the `requestdata` functions back into the node SDK. (The dependency injection makes things hard to follow, and soon the original reason for the move (so that they could be used in the `_error` helper in the nextjs SDK, which runs in both browser and node) will no longer apply (once #5729 is merged).)

Once these functions are no longer needed, they can be deleted from `@sentry/utils`.

More details and a work plan are in #5756.
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-add-requestdata-integration branch from 96d9a6c to e4a9dd6 Compare September 19, 2022 06:24
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-use-requestdata-integration-for-errors branch 2 times, most recently from 3c05857 to adea16a Compare September 19, 2022 07:35
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-add-requestdata-integration branch 2 times, most recently from f84a690 to 124fd6d Compare September 19, 2022 13:57
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-use-requestdata-integration-for-errors branch from adea16a to 18c2eda Compare September 19, 2022 13:58
Base automatically changed from kmclb-nextjs-add-requestdata-integration to master September 19, 2022 14:58
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-use-requestdata-integration-for-errors branch from 18c2eda to e8685e3 Compare September 19, 2022 17:27
@lobsterkatie lobsterkatie marked this pull request as ready for review September 20, 2022 05:23
// When the `transaction` option is set to true, it tries to extract a transaction name from the request
// object. We don't want this since we already have a high-quality transaction name with a parameterized
// route. Setting `transaction` to `true` will clobber that transaction name.
transaction: false,
Copy link
Member

Choose a reason for hiding this comment

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

It just took me 20 minutes to figure out why it is safe to remove the transaction: false logic here. I believe what confused me since we don't have the include.transaction defaulted to false in the requestdata integration. I think we should add that default just so it's more explicit.

Also (for a lack of better place to comment) there are still some TODO comments in addRequestDataToEvent in requestdata.ts referencing Next.js. Can we remove those now?

Copy link
Member Author

Choose a reason for hiding this comment

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

It just took me 20 minutes to figure out why it is safe to remove the transaction: false logic here. I believe what confused me since we don't have the include.transaction defaulted to false in the requestdata integration. I think we should add that default just so it's more explicit.

include.transaction isn't a thing anymore, at least not for the integration. From the description of #5703:

  • The options API for the new integration is inspired by, but different from, the options API for our Express request handler.
    • In the handler options, transaction can either be a boolean or a TransactionNamingScheme. In the integration, it can no longer be a boolean - events are going to have transactions, one way or another, so we shouldn't let people set it to false. Further, since it's now not about whether transaction is or isn't included, it's been moved out of include into its own transactionNamingScheme option.

Regardless, we didn't actually need that setting in the first place, at least not for transaction events. Even if include.transaction is set to true, transaction events will never fall into the if because they always already have a transaction value:

if (include.transaction && !event.transaction) {

So that handles transaction events. As for error events, as of this PR it doesn't matter what transaction value addRequestDataToTransaction sets, because we're overwriting it in the integration.

(And sorry - I don't mean that to sound dismissive. It's a valid concern, just not one that happens to apply here.)

Also (for a lack of better place to comment) there are still some TODO comments in addRequestDataToEvent in requestdata.ts referencing Next.js. Can we remove those now?

Probably. I'll give them a look.

Copy link
Member

@lforst lforst Sep 20, 2022

Choose a reason for hiding this comment

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

Ah right. I now remember why I set transaction: false in the first place - it was because the errors originating from data fetchers had the unparameterized route in a tag - which now seems to be the case again and I'm not sure this is a good thing, since the transaction tag now mismatches the actual transaction (Do we even need to be exact here though? I guess it might be confusing to users):

Example - here the transaction tag is GET /parameterized-page-with-getServerSideProps/two while it should be /parameterized-page-with-getServerSideProps/[pageNum]

Screen Shot 2022-09-20 at 10 43 13

Screen Shot 2022-09-20 at 10 47 40

(event (after), event (before))

I guess both are sort of correct, I am just wondering which one is better. Do you have an opinion here?

Copy link
Member

Choose a reason for hiding this comment

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

There also seem to be events where the tag is the request url. Not sure if this is related to this change though:

event

Screen Shot 2022-09-20 at 10 56 24

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh. In my testing, the tag was always overwritten with the transaction value, even when I specifically set it to be something different in beforeSend. The "after" event is from this branch?

(Also, there's no reason we can't just fix the tag, too, just to be certain.)

UPDATE: In your event(after), event(before) links, one thing I notice is that the before event doesn't have a transaction value at all (only a tag). Lemme play around with this a little more.

UPDATE2: Damn. Rebase fail. 🤦🏻‍♀️ An old bug crept back in - wrong naming scheme for the link to the transaction on the request. Now I want to go back and make sure nothing else regressed...

On the transaction score, I think we should be good now, though:

image

Copy link
Member

Choose a reason for hiding this comment

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

Yeah before is some event before this PR and after is after checking out the PR.

Are we sure we want to have the GET in the transaction tag though? Since there will be a mismatch between actual transaction and transaction 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.

Yup, discovered that as well. I think I managed to drop a fixup commit somewhere in there, which both fixed how the transaction is retrieved and the check for whether or not to include the method for nextjs events.

For nextjs, to make it match current behavior, the answer is yes for API routes, no for page routes. I'm proposing that in v8 we should just standardize on always including the method. (We already include it in our express transaction names, for example.)

there will be a mismatch between actual transaction and transaction tag.

From my testing, I believe the only way this can happen (in the UI, at least) is for an event to come in with a transaction tag but no top-level transaction value (like your "before" event). If an outgoing event has both a top-level transaction value and a transaction tag, and they don't match, ingest seems to overwrite the tag value with the top-level value. For example, this beforeSend

beforeSend: (event) => {
  event.transaction = "aardvark";
  event.tags.transaction = "zebra";
  return event;
}

produced an event with this JSON:

image

Copy link
Member

Choose a reason for hiding this comment

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

Gut feeling wise I like the current behavior (yes for API routes, no for page routes), because that way the pageload/pagenavigation transaction names and data-fetcher transactions line up. But let's discuss this in-depth when we get to it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm not wedded to either outcome, I just think we should standardize it across SDKs if possible. The tricky part when it comes to something like Express is that it's not as clear-cut what's an API request and what's a page load request. But as you say, we can talk about it closer to the time.

@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-use-requestdata-integration-for-errors branch 2 times, most recently from a780472 to 19c4fb1 Compare September 21, 2022 00:20
@lobsterkatie lobsterkatie merged commit f9d3139 into master Sep 21, 2022
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-use-requestdata-integration-for-errors branch September 21, 2022 13:38
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.

None yet

2 participants