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

feat: perf event handlers #553

Merged
merged 10 commits into from
Mar 14, 2023
Merged

feat: perf event handlers #553

merged 10 commits into from
Mar 14, 2023

Conversation

zzmp
Copy link
Contributor

@zzmp zzmp commented Mar 12, 2023

Adds new perf event handlers so that relevant events can be instrumented by integrators (eg to track performance metrics):

  • onSwapQuote
  • onTokenAllowance
  • onPermit2Allowance
  • onSwapSend
  • onWrapSend

Deprecates existing handlers whose functionality is shared by the new handlers: onSwapApprove, onSubmitSwapClick.

Perf event handlers should record the entire event, so they all follow a similar pattern and use a new helper hook: usePerfEventHandler. All perf event hooks take two parameters: args and an event. The event is a promise that resolves (or rejects) when the instrumented event has completed. usePerfEventHandler wraps event in a resolved Promise, so that it is not executed until after the perf event handler has executed. This allows integrators to instrument the full event (eg even if it triggers a fetch).


INFRA-144

@vercel
Copy link

vercel bot commented Mar 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
widgets ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 13, 2023 at 8:24PM (UTC)

@zzmp zzmp marked this pull request as ready for review March 12, 2023 06:52
@zzmp zzmp requested review from just-toby, a team and vm and removed request for just-toby and a team March 12, 2023 06:52
src/state/routing/slice.ts Outdated Show resolved Hide resolved
src/state/routing/slice.ts Show resolved Hide resolved
throw parsedError.status
}
}
throw queryError
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a way to indicate in perf.ts that these can throw certain types of errors? should the integrator be aware so they can handle them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we could extend Promise to have a typed catch method: https://github.com/reduxjs/redux-toolkit/blob/ad508a18d3a475fafecfaa77cf2c50da755c7e3e/packages/toolkit/src/query/core/buildMiddleware/types.ts#L99

However, this would not maintain the typing with async-await usage, so I don't think it's worth the added effort (and I don't know that we'd get typechecking without avoiding async-await).

Copy link
Contributor Author

@zzmp zzmp Mar 13, 2023

Choose a reason for hiding this comment

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

I think a good follow up would be for us to export an enum (or extend Error) and only throw these errors from integration hooks, but I don't think that that should be a part of this PR. It could be a future improvement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds good - i was imagining some generic "throws" descriptor on the function , not even typing it. maybe something worth calling out in the docs if we update them for the PerfEventHandlers

src/hooks/usePerfEventHandler.ts Outdated Show resolved Hide resolved
}
}, [parsedAmountIn, wrappedNativeCurrencyContract, wrapType])
const callback = usePerfEventHandler('onWrapSend', wrapCallback, parsedAmountIn && { amount: parsedAmountIn })
Copy link
Collaborator

Choose a reason for hiding this comment

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

{ amount: parsedAmountIn } is inputs to wrapCallback right? kinda hard to tell without comments in usePerfEventHandler and without labelling these inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored to (hopefully) make this more clear. usePerfEventHandler is meant to mirror the arguments of the perf event handler, so I want it to be ordinal inputs (ie not an options object).

Copy link
Collaborator

Choose a reason for hiding this comment

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

this makes sense now thanks

@vercel vercel bot temporarily deployed to Preview March 13, 2023 19:59 Inactive
@vercel vercel bot temporarily deployed to Preview March 13, 2023 20:01 Inactive
@vercel vercel bot temporarily deployed to Preview March 13, 2023 20:14 Inactive
@vercel vercel bot temporarily deployed to Preview March 13, 2023 20:16 Inactive
@vercel vercel bot temporarily deployed to Preview March 13, 2023 20:24 Inactive
@zzmp zzmp requested a review from just-toby March 13, 2023 20:27
throw parsedError.status
}
}
throw queryError
Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds good - i was imagining some generic "throws" descriptor on the function , not even typing it. maybe something worth calling out in the docs if we update them for the PerfEventHandlers

@zzmp zzmp merged commit 771e41f into main Mar 14, 2023
@zzmp zzmp deleted the perf-event-handlers branch March 14, 2023 18:38
@github-actions
Copy link

🎉 This PR is included in version 2.48.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants