io.sentry.event.BreadcrumbBuilder Java Examples

The following examples show how to use io.sentry.event.BreadcrumbBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SentryHelper.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void breadcrumbContext(String breadcrumb, String user) {
    final Context context = Sentry.getContext();
    context.setUser(new UserBuilder().setUsername(user).build());
    context.recordBreadcrumb(
            new BreadcrumbBuilder().setMessage(breadcrumb).build()
    );
    Sentry.clearContext();
}
 
Example #2
Source File: SentryErrorReporter.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Send a error to Sentry
 *
 * @param throwable Throws
 * @param context   BreadCrumb
 * @return Event Uniqud ID
 */
public @Nullable UUID sendError(@NotNull Throwable throwable, @NotNull String... context) {
    try {
        if (plugin.getBootError() != null) {
            return null; // Don't report any errors if boot failed.
        }
        if (tempDisable) {
            this.tempDisable = false;
            return null;
        }
        if (disable) {
            return null;
        }
        if (!enabled) {
            return null;
        }

        if (!checkWasCauseByQS(throwable)) {
            return null;
        }

        if (!canReport(throwable)) {
            return null;
        }
        if (ignoredException.contains(throwable.getClass())) {
            return null;
        }
        for (String record : context) {
            this.context.recordBreadcrumb(new BreadcrumbBuilder().setMessage(record).build());
        }
        String pasteURL = "Failed to paste.";
        try {
            Paste paste = new Paste(plugin);
            pasteURL = paste.paste(paste.genNewPaste());
            if (pasteURL != null && !pasteURL.isEmpty()) {
                lastPaste = pasteURL;
            }
        } catch (Throwable ex) {
            // Ignore
            pasteURL = this.lastPaste;
        }
        this.context.addTag("paste", pasteURL);
        this.sentryClient.sendException(throwable);
        this.context.clearBreadcrumbs();
        plugin
                .getLogger()
                .warning(
                        "A exception was thrown, QuickShop already caught this exception and reported it, switch to debug mode to see the full errors.");
        plugin.getLogger().warning("====QuickShop Error Report BEGIN===");
        plugin.getLogger().warning("Description: " + throwable.getMessage());
        plugin.getLogger().warning("Event    ID: " + this.context.getLastEventId());
        plugin.getLogger().warning("Server   ID: " + plugin.getServerUniqueID());
        plugin.getLogger().warning("====QuickShop Error Report E N D===");
        Util.debugLog(throwable.getMessage());
        Arrays.stream(throwable.getStackTrace()).forEach(a -> Util.debugLog(a.getClassName() + "." + a.getMethodName() + ":" + a.getLineNumber()));
        if (Util.isDevMode()) {
            throwable.printStackTrace();
        }
        return this.context.getLastEventId();
    } catch (Throwable th) {
        th.printStackTrace();
        return null;
    }
}
 
Example #3
Source File: SentryService.java    From Transport-Pipes with MIT License 4 votes vote down vote up
public void breadcrumb(Breadcrumb.Level level, String category, String message) {
    if (!isInitialized()) {
        return;
    }
    client.getContext().recordBreadcrumb(new BreadcrumbBuilder().setLevel(level).setCategory(category).setMessage(message).build());
}