Description
Problem Statement
So while I've been reviewing all the nextjs PRs + working on remix, I figured we should probably take some time to consolidate all the utils we have around managing requests and setting domains, perhaps exporting them all from @sentry/node
so they can be consumed accordingly.
We now have a couple of steps we always need to do here, and there's probably a bunch I'm missing
- monkey-patch the request handler to consume some kind of req (either a fetch API req https://developer.mozilla.org/en-US/docs/Web/API/Request or a express-like req)
- Set up domain to prevent scope bleed
- extract sentry-trace and baggage from req
- Add request data through event processor
- extract method from req
- Get paramaterized name
- Start transaction with
op
:http.server
,name
:${METHOD} ${PARAMETERIZED_NAME}
- Automatically capture
5xx
as errors - Call original request handler OR call next() in the case of middleware
- try-catch the request handler to process errors
- patch response end to end transaction and do cleanup
Solution Brainstorm
Ideally the goal is as follows.
We have a common set of utilities that is all called under the hood, so framework instrumentation just calls wrapRequestHandler(frameworkRequestHandler))
and everything should be done.
This way we can also tell folks in docs to just use our utils if they are using a framework we don't support.
This is tech debt - but worthwhile for us to work on since it'll help unblock future Node SDK work (and reduce all the duplication and inconsistency between express handlers, nextjs withSentry
, nextjs data fetching instrumentation, and remix.