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

Export function that builds error chain from wrapped errors #291

Closed
avgeorge opened this issue Oct 30, 2020 · 8 comments
Closed

Export function that builds error chain from wrapped errors #291

avgeorge opened this issue Oct 30, 2020 · 8 comments

Comments

@avgeorge
Copy link

Summary

Please export a function that can build an error chain from a wrapped error.

Motivation

This package has logic that builds an error chain for an event from errors that are wrapped using several different error packages. However, this logic is in a function that builds an event and submits it immediately. I would like to be able to use this logic so that I can make further changes to the event before submitting it.

Additional Context

The simplest way to achieve this would be to export Client.eventFromException which builds an event from an error. The function doesn't depend on the client receiver so it's trivial to change it to a standalone function.
It might be better to create a function with a different signature though, e.g. func ExtractErrorChain(err error) []Exception

@rhcarvalho
Copy link
Contributor

I would like to be able to use this logic so that I can make further changes to the event before submitting it.

Have you tried BeforeSend (global) or using an EventProcessor (if you need per-scope customization)? Those are the standard ways to inspect and modify events before sending, including the possibility to drop the event altogether.

@avgeorge
Copy link
Author

Thanks, I think the Scope.AddEventProcessor should allow me to do what I need.

I want to build a sentry hook for logrus so that errors are sent to sentry automatically when they are logged from logrus. A logrus error log would include the error (or error chain), a message and any additional context as key value pairs. I can set the additional data on the scope, but Hub.CaptureException doesn't allow adding a message. I think I can use an EventProcessor to set the message, but it seems a bit overkill to use it just to set a field I already had when the event was created. So I would still prefer access to this function if possible.

@cottrellio
Copy link

^ +1 I want logging with the error chain, a custom message, and contextual data

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

This issue 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 🥀

@KevinSnyderCodes
Copy link

Can we reopen this issue? I am trying to accomplish the same as here: create a custom logger that automatically sends events to Sentry in addition to logging them.

The easiest way to do this is to create a NewEvent() and populate it with a message, exceptions, tags, and extras as the log event gets populated.

The easiest way to add exceptions to this event would be by using the Client.eventFromException() method. However, this method is private, so I must copy the implementation into my own code, which means it might drift from upstream.

Adding a new public method such as Event.AddException(exception error) with the same implementation as Client.eventFromException() would solve this problem and ensure that anyone's implementation of adding an exception to their event stays the same as upstream.

@cleptric
Copy link
Member

We did merge and released a Logrus integration (#471) a while ago.

@KevinSnyderCodes
Copy link

Logrus is now in maintenance mode, with newer libraries such as zerolog and zap offering better performance.

What would be nice is to be able to build a custom logger implementation that wraps any number of logging/event capturing solutions (Sentry, Logrus, zerolog, zap) instead of being tightly coupled to Sentry via hooks.

@cleptric
Copy link
Member

#607

I can't come up with an immediate answer to why we shouldn't export these two functions.
Maybe you can give this a try and report back in the PR if this is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants