Skip to content

Conversation

@lforst
Copy link
Contributor

@lforst lforst commented Dec 7, 2023

Resolves #9570

This PR will auto instrument Next.js app router "generation functions":

We are capturing errors, the duration in the form of transactions, and recording parameters if sendDefaultPii is set.

Because these generation functions are a Next.js 14 feature, I had to add a new E2E test application.

Event: https://sentry-sdks.sentry.io/issues/4722077733/events/967aa2215944414984e37b75ed20148

Screenshot 2023-12-13 at 12 13 24

Screenshot 2023-12-13 at 12 13 46

Comment on lines +68 to +99
const sentryRequest = https.request(
sentryIngestUrl,
{ headers: proxyRequest.headers, method: proxyRequest.method },
sentryResponse => {
sentryResponse.addListener('data', (chunk: Buffer) => {
proxyResponse.write(chunk, 'binary');
sentryResponseChunks.push(chunk);
});

sentryResponse.addListener('end', () => {
eventCallbackListeners.forEach(listener => {
const rawSentryResponseBody = Buffer.concat(sentryResponseChunks).toString();

const data: SentryRequestCallbackData = {
envelope: parseEnvelope(proxyRequestBody, new TextEncoder(), new TextDecoder()),
rawProxyRequestBody: proxyRequestBody,
rawSentryResponseBody,
sentryResponseStatusCode: sentryResponse.statusCode,
};

listener(Buffer.from(JSON.stringify(data)).toString('base64'));
});
proxyResponse.end();
});

sentryResponse.addListener('error', err => {
throw err;
});

proxyResponse.writeHead(sentryResponse.statusCode || 500, sentryResponse.headers);
},
);

Check failure

Code scanning / CodeQL

Server-side request forgery

The [URL](1) of this request depends on a [user-provided value](2).
@lforst lforst marked this pull request as ready for review December 12, 2023 14:23
@AbhiPrasad
Copy link
Member

Could we get some more details in PR description? Ideally also a screenshot/link to error/transaction that this generates.

@lforst
Copy link
Contributor Author

lforst commented Dec 13, 2023

@AbhiPrasad for sure! Updated.

@lforst lforst merged commit da8c9c3 into develop Dec 15, 2023
@lforst lforst deleted the lforst-generation-functions branch December 15, 2023 10:49
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.

Instrument Next.js App Router generation functions

3 participants