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

ref(angular): Set Angular ErrorHandler specific Exception Mechanism #3844

Merged
merged 7 commits into from Jul 22, 2022

Conversation

onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Jul 27, 2021

Fixes: #3836

(Edited by @Lms24 because the PR changed quite a bit)

Previously, exceptions caught in the Sentry Angular ErrorHandler defaulted to the generic mechanism, meaning they were marked as handled: true and mechanism: generic. This PR adds a custom mechanism for these events: handled: false (because they were caught in our ErrorHandler) and mechanism: angular.
The mechanism is set by using a Scope Eventprocessor (similarly to how we do it in the Remix SDK)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 27, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 22.37 KB (+0.05% 🔺)
@sentry/browser - Webpack 23.25 KB (+0.06% 🔺)
@sentry/react - Webpack 23.28 KB (+0.06% 🔺)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 29.81 KB (+0.04% 🔺)

Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

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

The implementation is valid, so +1 on this. However, I think we should decide how to make a clear distinctions between handled/unhandled and mechanisms name. If we decide to go with this PR, then we should also update Vue, Ember, React and all remaining frameworks to with the correct mechanism name.

cc @getsentry/team-webplatform

@lobsterkatie
Copy link
Member

I think we should decide how to make a clear distinctions between handled/unhandled and mechanisms name.

I've been wanting to circle back around to mechanism for a while. I definitely think there are ways we could be clearer about what's what.

Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

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

@AbhiPrasad pointed me here when we were talking about hints.

Hints work, but are a form of two-way communication between the SDK and user code that we sometimes abuse to pass information around. In particular, I find this use of hint.data harder to understand and maintain than alternatives.

One alternative, what SDKs like angular, ember, etc can do is to use a Scope-based Event Processor to mutate the event in arbitrary ways, without requiring extra code in upstream packages like @sentry/browser (so probably a win in terms of bundle size).

@HazAT
Copy link
Member

HazAT commented Sep 6, 2021

These changes lgtm, can we merge it?

@github-actions
Copy link
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@bruno-garcia
Copy link
Member

@onurtemizkan could you please update this branch and lets merge?

This resolve an issue I opened (#3836) and seems to have all approvals it needs

@AbhiPrasad
Copy link
Member

I would like to see us switch to using a scope processor vs. adding the mechanism through a hint.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 12, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.43 KB (+0.06% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 60.06 KB (+0.05% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.01 KB (+0.05% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 52.97 KB (+0.06% 🔺)
@sentry/browser - Webpack (gzipped + minified) 19.77 KB (+0.05% 🔺)
@sentry/browser - Webpack (minified) 64.31 KB (+0.05% 🔺)
@sentry/react - Webpack (gzipped + minified) 19.79 KB (+0.05% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.08 KB (+0.03% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.88 KB (+0.04% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.13 KB (+0.05% 🔺)

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.

@onurtemizkan is there any chance we could add a test for this change? I recently started adding tests for the changes I made to the Angular SDK and I think it should be possible to add a simple test for this.
I know that our testing setup is far from optimal for Angular rn but it's on my todo list to change that.

If it turns out that it's not that easy then that's fine as well. We can come back to it once I improved our setup.

EDIT: fyi, in #5416 I'm adding a few more tests.

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.

One more remark @onurtemizkan, thanks!

Comment on lines 45 to 58
getCurrentHub().captureException(extractedError, { data: { mechanism: { type: 'angular', handled: false } } }),
);
Copy link
Member

@Lms24 Lms24 Jul 14, 2022

Choose a reason for hiding this comment

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

Can we change the way of passing on the mechanism to using an eventprocessor on the scope? Similarly to how we do it in remix here? If this is possible, we'd prefer that over adding it to the hint.

@onurtemizkan onurtemizkan force-pushed the onur/browser-provide-mechanism branch from 039919d to 5d94e2a Compare July 20, 2022 15:23
@onurtemizkan
Copy link
Collaborator Author

Thanks for the review @Lms24!

Updated the PR

@onurtemizkan onurtemizkan requested a review from Lms24 July 20, 2022 15:24
Comment on lines 161 to 169
const providedMechanism: Mechanism | undefined =
hint && hint.data && (hint.data as { mechanism: Mechanism }).mechanism;
const mechanism: Mechanism = providedMechanism || {
handled: true,
type: 'generic',
};

addExceptionMechanism(event, mechanism);

Copy link
Member

Choose a reason for hiding this comment

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

Now that we're using the scope eventprocessor - do we still need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default fallback mechanism seems unneeded at this point, removing it.

Not sure about the rest, though.
The original intent on this PR was to mimic how mechanisms are passed in Node SDK on browser SDK, but a lot changed since, so I don't know if that's still relevant.

Still, it looks like this can also be moved into scope.addEventProcessor to be consistent, if we are keeping it.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to change the Node approach to how we do it in Express (and Angular). (But let's do this in another PR). Which makes me think that we don't need to query the hint here. The original call to addExceptionMechanism shouldn't be a problem because it won't overwrite the already set mechanism with the default value (see here)

So overall, I don't think we need this change here (unless I'm missing something)

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.

Thanks for adding the tests and the scope event processor @onurtemizkan
The linter isn't happy yet but I think that's easily fixable.

Just one more question (above) and then I think this is ready to go.

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.

Thanks @onurtemizkan ❤️

@Lms24
Copy link
Member

Lms24 commented Jul 22, 2022

Tested on NG14 test project:
image

@Lms24 Lms24 merged commit 3665831 into master Jul 22, 2022
@Lms24 Lms24 deleted the onur/browser-provide-mechanism branch July 22, 2022 07:53
@Lms24 Lms24 changed the title feat(browser): Allow mechanism to be provided as a hint. Update angular exception mechanism. ref(angular): Set Angular ErrorHandler specific Exception Mechanism Jul 22, 2022
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.

Angular error handler should report handled: false
8 participants