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

fix: Update ExtractedNodeRequestData to include valid query_params for tracesSampler #3715

Merged
merged 3 commits into from
Jul 6, 2021

Conversation

kamilogorek
Copy link
Contributor

@kamilogorek kamilogorek commented Jun 21, 2021

Fixes #3714

Fwiw we should somehow unify ExtractedNodeRequestData and Request types, as they are almost identical.

It should™ be a non-breaking change, as the broader type includes string and it's never used directly by the user.

@kamilogorek kamilogorek requested review from a team, lobsterkatie and vladanpaunovic and removed request for a team June 21, 2021 09:30
@rhcarvalho
Copy link
Contributor

I think the safer change would be to fix the implementation in @sentry/nextjs:

It should not pass req.query (map-like) directly.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 21, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 21.39 KB (-0.01% 🔽)
@sentry/browser - Webpack 22.4 KB (0%)
@sentry/react - Webpack 22.44 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.89 KB (-0.01% 🔽)

@kamilogorek
Copy link
Contributor Author

Not sure how feasible it is, so cc @lobsterkatie @AbhiPrasad @iker-barriocanal

@rhcarvalho
Copy link
Contributor

The QueryParams type was introduced rather recently in https://github.com/getsentry/sentry-javascript/pull/3580/files#diff-64477348658a923e34c3ce4e902c93d1de079bafab9322ee194f2de5809d7eb9R22

And it has the downside of forcing users to check the type in runtime before using it, because you can get 1 of 3 types... harder to use than our original state.

@lobsterkatie
Copy link
Member

lobsterkatie commented Jun 29, 2021

The QueryParams type was introduced rather recently in #3580 (files)

@rhcarvalho - The type change was made to match the unified SDK spec.

If we can only pass it as a string, we'll have to artificially construct a string of the form key1=value1&key2=value2, since in next.js the req.query object includes not only anything from the original URL's actual query string but also any parameters included as part of the URL itself. (So, in other words, if the URL is /dogs/maisey/tricks?trickName=kangaroo and the route is dogs/[dogName]/tricks, then req.query is { dogName: 'maisey', trickName: 'kangaroo' }. Obviously this is doable, but given that the spec allows an object, it feels like work we shouldn't have to do.

Thoughts?

And it has the downside of forcing users to check the type in runtime before using it, because you can get 1 of 3 types... harder to use than our original state.

For any given framework, it should always be the same type, so no type-checking ought to be necessary. Can you think of an instance where that wouldn't be true?

@iker-barriocanal
Copy link
Member

An object is easier to deal with than a query string, and if the spec allows it...

@rhcarvalho
Copy link
Contributor

An object is easier to deal with than a query string, and if the spec allows it...

Yes, an object might be easy to work with, but a union type not as much. Because it is not always an object, user code needs to handle all possible types.

@rhcarvalho
Copy link
Contributor

The type change was made to match the unified SDK spec.

The spec is what Relay accepts, doesn't necessarily mean that SDKs should send data in all possible types.

For any given framework, it should always be the same type, so no type-checking ought to be necessary. Can you think of an instance where that wouldn't be true?

Hmm, I don't think that's the case in TS. See https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMAFAQwE4HMBciDOUGMYWiAPgUSVgNoC6DFiA3orQNYCmAnnocVL1+1UgG5EAXwCUrAFCJFiCAnxwANlwB06uFnTYtJACZcAHgHlUAcjTXp0sXMly5oSLASJ9mXFUFYsiwKSipgapo6egZYRmCmljZ2Dk4ubijWAFZoYFwwGHD2Tvq2AF55UFxFrkA

function f(arg: string | string[][] | { [key: string]: string; }) {
    console.log(arg.indexOf('a'));
}

function g(arg: string) {
    console.log(arg.indexOf('a'));
}

f('janeiro');
g('azeite');
This expression is not callable.
  Not all constituents of type 'string | ((searchString: string, position?: number | undefined) => number) | ((searchElement: string[], fromIndex?: number | undefined) => number)' are callable.

So even though you expect that under certain circumstances (e.g. in @sentry/nextjs) the type is always a certain type that is part of the union, you'd still need to write something to convince the compiler, and then cross-fingers that your expectation/assumption was right and you won't introduce a runtime error.

@rhcarvalho
Copy link
Contributor

My comments just reflect my views on usability and compatibility, but I don't have a strong stance on this, please feel free to disagree and move on with any decision.

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

I say we go with it and revisit only if someone complains.

@kamilogorek kamilogorek enabled auto-merge (squash) July 6, 2021 07:01
@kamilogorek kamilogorek merged commit f624f44 into master Jul 6, 2021
@kamilogorek kamilogorek deleted the tracer-query-params branch July 6, 2021 07:12
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.

SamplingContext.request.query_string became object, but still has type 'string'
4 participants