EventBuilder missing method for logging a Throwable

The current Java API for EventBuilder allows me to send an event where I can set the message and log level, but it is missing a method for adding a Throwable for the event.

In Android I log non fatal exception using a Logcat wrapper. In this wrapper I also send events to Sentry, but I currently can’t send the message and log level along with the exception.

Any chance we can have this added?

Thanks!

// Erik

1 Like

any update on this? I’m in the process of integrating Sentry into my app and I have just run into this shortfall… is it being worked on? is there another way?

Currently I am using this:
Sentry.capture(“my log message”)
Sentry.capture(Throwable)

but that just doesn’t feel right…

So… I have found the solution/workaround

One first needs to create an EventBuilder, and on this EventBuilder one needs to call the following methods(all of them are optional):

  • withLogger(…) : as far as I can tell this is the thing that is reporting the error
  • withMessage(…): this is to add your message
  • withLevel(Event.Level.?): to set the level of the error ie: Error, Debug etc…
  • withSentryInterface(new ExceptionInterface(throwable))): This is to add your Exception Throwable

and then one would call Sentry.capture(yourEventBuilder) // Note we do not call .build() on the EventBuilder, this is to allow Sentry to add any further details that one may have configured to be added.

I hope this helps someone in the future, I really don’t know why, in over a year, a Sentry official has not posted this solution here…

This seems like the correct approach to me.
Except that logger shouldn’t be mandatory.
If it currently is, we should likely update the SDK.

Usually a capture with a throwable would use the values of it to set the message and also by default set e error level. Reason why it’s sort of uncommon to set message/level with a throwable.