Skip to content

feat(remix): Continue transaction from request headers #5600

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

Merged
merged 9 commits into from
Sep 1, 2022

Conversation

AbhiPrasad
Copy link
Member

Enables propogation of traces through sentry-trace and dynamic sampling propogation through baggage

@onurtemizkan
Copy link
Collaborator

Looks like baggage is not populated anymore, but sentry-trace is.

Copy link
Contributor

@vladanpaunovic vladanpaunovic left a comment

Choose a reason for hiding this comment

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

Can we make sure there is some test that validates this?

@AbhiPrasad
Copy link
Member Author

Yup - first have to figure out why existing tests are failing, then we add a new test.

@AbhiPrasad AbhiPrasad marked this pull request as draft August 18, 2022 13:59
@AbhiPrasad AbhiPrasad self-assigned this Aug 18, 2022
@AbhiPrasad AbhiPrasad force-pushed the abhi-extract-trace-headers branch from 5b25a5e to 299e93b Compare August 30, 2022 15:58
@github-actions
Copy link
Contributor

github-actions bot commented Aug 30, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.42 KB (+0.01% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 60.08 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.99 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 52.94 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 19.79 KB (0%)
@sentry/browser - Webpack (minified) 64.33 KB (0%)
@sentry/react - Webpack (gzipped + minified) 19.81 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.66 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.91 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.28 KB (+0.01% 🔺)

@AbhiPrasad
Copy link
Member Author

AbhiPrasad commented Aug 30, 2022

image
image

Comment on lines +105 to +114
async function makeRequest(
method: 'get' | 'post' = 'get',
url: string,
axiosConfig?: AxiosRequestConfig,
): Promise<void> {
try {
if (method === 'get') {
await axios.get(url);
await axios.get(url, axiosConfig);
} else {
await axios.post(url);
await axios.post(url, axiosConfig);
Copy link
Member Author

Choose a reason for hiding this comment

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

thoughts on this approach for adding axois config @onurtemizkan? Should we do it some other way? Maybe by putting base axios config in the TestEnv constructor?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this approach (passing to the data method) with a default header set in TestEnv would make it easier if we want to test consecutive requests with different configurations?

I have just tested setting the default inside class, and it's not breaking any of the current Node / Remix tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

I extract this to be a setter on the class, lmk what you think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good to me!

@AbhiPrasad AbhiPrasad marked this pull request as ready for review August 30, 2022 20:26
@AbhiPrasad
Copy link
Member Author

This is now ready to review!

Comment on lines 318 to 321
const matches = matchServerRoutes(routes, url.pathname, pkg);
const match = matches && getRequestMatch(url, matches);
const name = match === null ? url.pathname : match.route.id;
const source = match === null ? 'url' : 'route';
const [name, source]: [string, TransactionSource] =
match === null ? [url.pathname, 'url'] : [match.route.id, 'route'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion, don't feel obligated to act: I believe we could do the matching of the routes to the request url outside of this function. That way we don't have to pass in url, routes and pkg but could instead just pass a transactionName argument.

That would probably mean though that we duplicate the route matching logic in instrumentServer.ts and the express.ts adapter. Maybe we could extract this whole route matching + source determining into a separate function? Anyways, just a suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion, done with fc4f653

Comment on lines 54 to 60
const transaction = startRequestHandlerTransaction(hub, url, routes, pkg, {
headers: {
'sentry-trace': (req.headers && isString(req.headers['sentry-trace']) && req.headers['sentry-trace']) || '',
baggage: (req.headers && isString(req.headers.baggage) && req.headers.baggage) || '',
},
method: request.method,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Just fyi @Lms24 opened an issue to track the parsing of baggage headers if there are multiple ones on one request: #5672

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) September 1, 2022 18:05
@AbhiPrasad AbhiPrasad merged commit 74672a0 into master Sep 1, 2022
@AbhiPrasad AbhiPrasad deleted the abhi-extract-trace-headers branch September 1, 2022 18:17
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.

4 participants