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

feat(nuxt): Add server error hook #12796

Merged
merged 9 commits into from
Jul 9, 2024
Merged

feat(nuxt): Add server error hook #12796

merged 9 commits into from
Jul 9, 2024

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Jul 8, 2024

Reports errors thrown in nitro. Tests will be added when adding the E2E test application.

closes #12795

@s1gr1d s1gr1d requested review from lforst, Lms24 and andreiborza July 8, 2024 12:55
@s1gr1d s1gr1d force-pushed the sig/nuxt-server branch from 48c34df to 85359f8 Compare July 8, 2024 12:57
@s1gr1d s1gr1d requested a review from AbhiPrasad July 8, 2024 14:28
s1gr1d added 2 commits July 8, 2024 16:36

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

if (context) {
captureException(error, {
captureContext: { contexts: { nuxt: context } },
Copy link
Member

Choose a reason for hiding this comment

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

m: I would be more selective in what we record here instead of dumping the entire context object in here. It could become a problem if context suddenly starts containing PII, becomes very large, or circular in a future nitro update.

Copy link
Member

Choose a reason for hiding this comment

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

yes ideally we:

  1. We parse the incoming nuxt context and extract the fields we care about
  2. We put that in a nuxt context attached to the sentry event
  3. Document the nuxt context in the develop docs

@s1gr1d s1gr1d requested a review from lforst July 9, 2024 08:35

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@s1gr1d s1gr1d added the Package: nuxt Issues related to the Sentry Nuxt SDK label Jul 9, 2024
Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

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

:shipit:

Comment on lines 8 to 13
// Do not handle 404 and 422
if (error instanceof H3Error) {
if (error.statusCode === 404 || error.statusCode === 422) {
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

l/m: We could arguably skip all 4xxs (also 3xxs if that can ever happen).

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Two optional suggestion to streamline the code but otherwise LGTM! (feel free to merge and streamline in a follow-up PR or not at all)

Comment on lines 15 to 24
if (errorContext) {
const structuredContext = extractErrorContext(errorContext);

captureException(error, {
captureContext: { contexts: { nuxt: structuredContext } },
mechanism: { handled: false },
});
} else {
captureException(error, { mechanism: { handled: false } });
}
Copy link
Member

Choose a reason for hiding this comment

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

l (feel free to disregard): WDYT about calling captureException only once and setting captureContext depending on errorContext

tags: undefined,
};

if (errorContext) {
Copy link
Member

Choose a reason for hiding this comment

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

l: do we need this guard? i.e. can CapturedErrorContext be undefined?

s1gr1d and others added 2 commits July 9, 2024 15:25

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@s1gr1d s1gr1d merged commit 47e1b7e into develop Jul 9, 2024
88 of 89 checks passed
@s1gr1d s1gr1d deleted the sig/nuxt-server branch July 9, 2024 13:43
s1gr1d added a commit that referenced this pull request Jul 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Preparing `@sentry/nuxt` for a release (experimental)

Merge after this PR:
#12796
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add server (nitro) instrumentation
4 participants