-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture smartsheet exception more granularly && Add sentry service to…
… capture exception or message (#1078) * Capture smartsheet exception more granularly && Add sentry service to capture exception or message * Update src/main/java/org/mskcc/cbio/oncokb/service/SentryService.java Co-authored-by: Calvin Lu <[email protected]> --------- Co-authored-by: Calvin Lu <[email protected]>
- Loading branch information
Showing
2 changed files
with
96 additions
and
47 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/org/mskcc/cbio/oncokb/service/SentryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.mskcc.cbio.oncokb.service; | ||
|
||
import io.sentry.Sentry; | ||
import io.sentry.SentryEvent; | ||
import io.sentry.SentryLevel; | ||
import io.sentry.protocol.Message; | ||
import io.sentry.protocol.User; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class SentryService { | ||
|
||
/** | ||
* Send a message to Sentry | ||
* | ||
* @param sentryLevel Sentry event level. Warning, Error and more | ||
* @param message The custom message which will be displayed in the Sentry issue | ||
* @param user The optional user object if you want to group the issue based on the user | ||
*/ | ||
public void throwMessage(SentryLevel sentryLevel, String message, User user) { | ||
Sentry.setLevel(sentryLevel); | ||
if (user != null) { | ||
Sentry.setUser(user); | ||
} | ||
Sentry.captureMessage(message); | ||
} | ||
|
||
/** | ||
* Send the exception to Sentry | ||
* | ||
* @param sentryLevel Sentry event level. Warning, Error and more | ||
* @param exception Any throwable exception which will be displayed in the Sentry issue | ||
* @param message The custom message which will be displayed in the Sentry issue | ||
*/ | ||
public void throwEvent(SentryLevel sentryLevel, Throwable exception, String message) { | ||
SentryEvent event = new SentryEvent(); | ||
Message sentryMessage = new Message(); | ||
sentryMessage.setMessage(message); | ||
event.setMessage(sentryMessage); | ||
event.setLevel(sentryLevel); | ||
event.setThrowable(exception); | ||
|
||
Sentry.captureEvent(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters