-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add server-side request transactions #3533
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(nextjs): Add server-side request transactions #3533
Conversation
size-limit report
|
8cffa76
to
b16c34a
Compare
// Each value in that object is either a string representing a single entry point, an array of such strings, or an | ||
// object containing either of those, along with other configuration options. In that third case, the entry point(s) are | ||
// listed under the key `import`. | ||
type EntryPropertyObject = PlainObject<string | Array<string> | EntryPointObject>; | ||
type EntryPropertyObject = PlainObject<string> | PlainObject<Array<string>> | PlainObject<EntryPointObject>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type EntryPropertyObject = PlainObject<string> | PlainObject<Array<string>> | PlainObject<EntryPointObject>; | |
type EntryPropertyObject = Record<string, string> | Record<string, Array<string>> | Record<string, EntryPointObject>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work as well, but you'd have to confirm whether it allows for the same property-based for in/of
as [key: string]
does. If so, then PlainObject
can be removed entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I'd learned that Record
is really meant to be used on a known, finite set of keys. (I get that it would work - I'm talking about should.) Is that not true?
I made PlainObject
just because I was tired of typing {[key: string] : whatever}
a million times, and figured since there's Array
their might as well be an equivalent for objects. ¯_(ツ)_/¯ I'm not committed to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that not true?
Nope, it's basically what you wrote up there with key/value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no, I know it works. I just meant idiomatically. Here are a few things I dug out of my bookmarks:
https://stackoverflow.com/a/54100359/3874926
https://fnune.com/typescript/2019/01/30/typescript-series-1-record-is-usually-not-the-best-choice
https://rickcarlino.com/2017/02/27/real-world-use-case-for-typescript-record-types.html
Happy to go back to using { [key: string]: string }
if you think it's better than PlainObject
.
UPDATE: The playground hates it, but check out what compiles just fine if you actually use it in your code:
interface Object<T> extends ReturnType<ObjectConstructor> {
[key: string]: T;
}
const numObject: Object<number> = {
someNum: 4,
someNonNum: 'whoops', // Error: Type 'string' is not assignable to type 'number'.
};
I get that it's a little unorthodox, but what do you think of using that?? 😁
b16c34a
to
c9f78ce
Compare
|
||
// The parent directory for the new temporary directory | ||
|
||
describe('deepReadDirSync', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it 🥰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed comments!
This PR adds tracing to requests for both page routes and API routes, by wrapping the server's main request handler. In order for the SDK to be initialized early enough for this to work, the logic for including the user's
sentry.server.config.js
file has changed in the following ways:_document
nor into individual API routes.entry
entry, which causes it to get output as a separate file, which we can then require earlier in the process._injectFile
can be simplified, since it's now only handling client-side injection.Why is having webpack output a separate file any better than the separate file it already is? The answer is that doing it this way runs it through the same webpack processors as the rest of the code written by the user, which is a good idea in general (and is what was happening when we were injecting it into existing
entry
entries), and which is specifically necessary in this case because (warning: a trip down into the weeds ahead):sentry.server.config.js
for its side effect of starting up the SDK.module
in ourtsconfig
- and not only do we have a different one for our ESM builds, we've all seen how well it goes when we try to force our users into a particular TS configuration (see:localForage
and its numerous associated issues and PRs), so that feels like a non-starter.require
, but you can't require something which is itself using ESM imports, which our users easily might do in theirsentry.server.config.js
.Note: If you pull this to test it, you have to watch out for the relative path vs yarn linking problem, otherwise your test app won't build.
TODO in this PR:
Add testsUPDATE: There's too much to mock here, so we'll make an example app against which to test in a separate PRTODO in future PRs:
sentry-trace
andtracestate
)