Skip to content

ref(nestjs): Add mechanism to captured errors #17312

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Aug 4, 2025

The NestJS SDK didn't add a mechanism to a bunch of caught errors. This resulted in the errors being incorrectly marked as handled: true and the mechansim.type defaulting to 'generic'.

This PR:

  • adds the mechanism to all captureException calls within the SDK, marking caught exceptions as handled: false
    • reviewers: Please let me know if any of these should in fact be handled: true!
  • adds a specific mechanism.type, following the naming scheme of trace origin
  • adjusts and adds test assertions so that we actually test on the expected mechanism

I noticed that we have some startSpan calls in the SDK that don't include a sentry.origin attribute. I'll open a follow-up PR to fix this separately.

ref #17212
closes #17259

@Lms24 Lms24 marked this pull request as draft August 4, 2025 15:24
@@ -19,12 +19,12 @@ export const SentryCron = (monitorSlug: string, monitorConfig?: MonitorConfig):
try {
result = originalMethod.apply(this, args);
} catch (e) {
captureException(e);
captureException(e, { mechanism: { handled: false, type: 'auto.cron.nestjs' } });
Copy link
Member Author

@Lms24 Lms24 Aug 5, 2025

Choose a reason for hiding this comment

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

(auto.)cron is not a listed category, which is a bit suboptimal. The two alternatives are:

  • function given we wrap some kind of cron-executed function
  • omitting the category, since it's not required: auto.nestjs.sentry_cron

@AbhiPrasad thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

worth noting: I didn't find a specific span that reliably applies here, so there's no direct span counterpart to this mechanism.type

Copy link
Member

Choose a reason for hiding this comment

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

let's do auto.function.X

@@ -77,7 +77,7 @@ export function SentryExceptionCaptured() {
return originalCatch.apply(this, [exception, host, ...args]);
}

captureException(exception);
captureException(exception, { mechanism: { handled: false, type: 'auto.function.nestjs.exception_captured' } });
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 think auto.function.* is correct here, given this decorator can be applied to any arbitrary function.

@Lms24 Lms24 self-assigned this Aug 5, 2025
@Lms24 Lms24 marked this pull request as ready for review August 5, 2025 08:36
@Lms24 Lms24 requested review from chargome and AbhiPrasad August 5, 2025 08:36
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

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.

Adjust mechanism in nestjs SDK
3 participants