Skip to content

feat(node): Add NestJS error handler #11375

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 5 commits into from
Apr 4, 2024
Merged

Conversation

onurtemizkan
Copy link
Collaborator

  • Adds setupNestErrorHandler to capture globally caught exceptions in NestJS applications.
  • Adds NestJS end to end tests.

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),
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).
Copy link

codecov bot commented Apr 2, 2024

Bundle Report

Changes will increase total bundle size by 889 bytes ⬆️

Bundle name Size Change
@sentry/types-cjs 35 bytes 0 bytes
@sentry/types-esm 35 bytes 0 bytes
@sentry/utils-cjs 176.79kB 0 bytes
@sentry/utils-esm 172.24kB 0 bytes
@sentry-internal/replay-cjs 306.35kB 0 bytes
@sentry/core-cjs 238.78kB 0 bytes
@sentry/node-cjs 335.44kB 297 bytes ⬆️
@sentry/node-esm 331.99kB 260 bytes ⬆️
@sentry-internal/replay-esm 306.46kB 0 bytes
@sentry/core-esm 235.2kB 0 bytes
@sentry/aws-serverless-cjs 14.62kB 0 bytes
@sentry-internal/integration-shims-cjs 3.65kB 0 bytes
@sentry/vercel-edge-cjs 18.23kB 0 bytes
@sentry-internal/integration-shims-esm 2.99kB 0 bytes
@sentry-internal/feedback-cjs 65.81kB 0 bytes
@sentry/vercel-edge-esm 16.13kB 0 bytes
@sentry-internal/replay-canvas-cjs 29.51kB 0 bytes
@sentry-internal/tracing-cjs 65.73kB 0 bytes
@sentry/bun-esm 10.08kB 23 bytes ⬆️
@sentry-internal/replay-canvas-esm 29.43kB 0 bytes
@sentry/browser-cjs 106.89kB 0 bytes
@sentry/opentelemetry-cjs 70.22kB 0 bytes
@sentry/google-cloud-serverless-cjs 23.07kB 60 bytes ⬆️
@sentry-internal/node-integration-tests-cjs 1.04kB 0 bytes
@sentry/react-esm 41.18kB 0 bytes
@sentry/svelte-cjs 13.84kB 0 bytes
@sentry-internal/node-integration-tests-esm 888 bytes 0 bytes
@sentry/google-cloud-serverless-esm 19.18kB 23 bytes ⬆️
@sentry-internal/feedback-esm 65.5kB 0 bytes
@sentry/wasm-cjs 5.2kB 0 bytes
@sentry-internal/tracing-esm 65.5kB 0 bytes
@sentry/astro-cjs 27.19kB 60 bytes ⬆️
@sentry/react-cjs 45.04kB 0 bytes
@sentry/opentelemetry-esm 69.19kB 0 bytes
@sentry/vue-cjs 20.19kB 0 bytes
@sentry/wasm-esm 4.85kB 0 bytes
@sentry/gatsby-cjs 905 bytes 0 bytes
@sentry/svelte-esm 12.72kB 0 bytes
@sentry/astro-esm 23.41kB 23 bytes ⬆️
@sentry/sveltekit-esm 61.08kB 0 bytes
@sentry/remix-cjs 53.68kB 60 bytes ⬆️
@sentry/gatsby-esm 385 bytes 0 bytes
@sentry/vue-esm 18.85kB 0 bytes
@sentry/remix-esm 48.25kB 23 bytes ⬆️
@sentry/sveltekit-cjs 69.31kB 0 bytes
@sentry/nextjs-cjs 20.52kB 0 bytes
@sentry/nextjs-esm 20.02kB 0 bytes
@sentry/profiling-node-cjs 25.5kB 0 bytes
@sentry/profiling-node-esm 25.52kB 0 bytes
@sentry/browser-esm 104.06kB 0 bytes
@sentry/bun-cjs 13.56kB 60 bytes ⬆️

@@ -0,0 +1,4 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the prettier config here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, just deleted now 👍

Copy link
Contributor

github-actions bot commented Apr 2, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) 76.07 KB (0%)
@sentry/browser (incl. Tracing, Replay) 67.33 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 71.16 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 60.9 KB (0%)
@sentry/browser (incl. Tracing) 32 KB (0%)
@sentry/browser (incl. browserTracingIntegration) 32 KB (0%)
@sentry/browser (incl. feedbackIntegration) 31.28 KB (0%)
@sentry/browser (incl. feedbackModalIntegration) 31.39 KB (0%)
@sentry/browser (incl. feedbackScreenshotIntegration) 31.39 KB (0%)
@sentry/browser (incl. sendFeedback) 27.35 KB (0%)
@sentry/browser 22.52 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 71.09 KB (0%)
CDN Bundle (incl. Tracing, Replay) 65.8 KB (0%)
CDN Bundle (incl. Tracing) 32.14 KB (0%)
CDN Bundle 23.74 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 205.04 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 95.75 KB (0%)
CDN Bundle - uncompressed 70.05 KB (0%)
@sentry/react (incl. Tracing, Replay) 67.31 KB (0%)
@sentry/react 22.55 KB (0%)

@onurtemizkan onurtemizkan force-pushed the onur/add-nest-error-handler branch 3 times, most recently from 452a568 to 616561e Compare April 3, 2024 10:06
@onurtemizkan onurtemizkan marked this pull request as ready for review April 3, 2024 10:30
@mydea mydea changed the title feat(node): Add NestJS error handler. feat(node): Add NestJS error handler Apr 3, 2024
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

very nice!

@mydea mydea force-pushed the onur/add-nest-error-handler branch from 616561e to c315d8e Compare April 4, 2024 06:56
@AbhiPrasad AbhiPrasad merged commit 3790f1b into develop Apr 4, 2024
@AbhiPrasad AbhiPrasad deleted the onur/add-nest-error-handler branch April 4, 2024 13:11
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
- Adds `setupNestErrorHandler` to capture globally caught exceptions in
NestJS applications.
- Adds NestJS end to end tests.
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.

3 participants