io.sentry.event.interfaces.ExceptionInterface Java Examples

The following examples show how to use io.sentry.event.interfaces.ExceptionInterface. 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: ServerLogger.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void logToSentry(Level level, String tag, String message, Exception ex){
    if (!isSentryInitialized) return;

    Long previousTime = lastSentryExecution;
    long currentTimestamp = System.currentTimeMillis();

    lastSentryExecution = currentTimestamp;

    if (previousTime == null || (currentTimestamp - previousTime > MINIMUM_INTERVAL)){
        EventBuilder eventBuilder = new EventBuilder();

        if (level != null){
            eventBuilder.withLevel(level.sentryLevel());
        }

        if (!StringUtils.isEmpty(tag)){
            eventBuilder.withLogger(tag);
        }

        if (!StringUtils.isEmpty(message)){
            eventBuilder.withMessage(message);
        }

        if (ex != null) {
            eventBuilder.withSentryInterface(new ExceptionInterface(ex));
        }

        Sentry.capture(eventBuilder);
    }
}
 
Example #2
Source File: SentryBugReporter.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private EventBuilder createEvent(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo) {
    IdeaLoggingEvent ideaEvent = events[0];
    EventBuilder eventBuilder = new EventBuilder();
    eventBuilder.withMessage(ideaEvent.getMessage());
    eventBuilder.withRelease(getPluginVersion());
    eventBuilder.withTag(TAG_PLATFORM_VERSION, getPlatformVersion());
    eventBuilder.withTag(TAG_OS, SystemInfo.OS_NAME);
    eventBuilder.withTag(TAG_OS_VERSION, SystemInfo.OS_VERSION);
    eventBuilder.withTag(TAG_OS_ARCH, SystemInfo.OS_ARCH);
    eventBuilder.withTag(TAG_JAVA_VERSION, SystemInfo.JAVA_VERSION);
    eventBuilder.withTag(TAG_JAVA_RUNTIME_VERSION, SystemInfo.JAVA_RUNTIME_VERSION);
    Object data = ideaEvent.getData();
    if (data instanceof LogMessage) {
        LogMessage logMessage = (LogMessage) data;
        Throwable throwable = logMessage.getThrowable();
        eventBuilder.withSentryInterface(new ExceptionInterface(throwable));
    } else if (ideaEvent.getThrowable() != null) {
        eventBuilder.withSentryInterface(new ExceptionInterface(ideaEvent.getThrowable()));
    }
    if (additionalInfo != null) {
        eventBuilder.withExtra(EXTRA_ADDITIONAL_INFO, additionalInfo);
    }
    if (events.length > 1) {
        eventBuilder.withExtra(EXTRA_MORE_EVENTS, getMoreEvents(events));
    }
    eventBuilder.withExtra(EXTRA_OTHER_PLUGINS, getOtherPluginsInfo());
    return eventBuilder;
}
 
Example #3
Source File: SentryHelper.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void captureException(String message, Throwable t, Class<?> clazz) {
    EventBuilder eventBuilder = new EventBuilder()
            .withMessage(message)
            .withLevel(Event.Level.ERROR)
            .withLogger(clazz.getName())
            .withSentryInterface(new ExceptionInterface(t));
    Sentry.capture(eventBuilder);
}
 
Example #4
Source File: SentryHelper.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void captureExceptionContext(String message, Throwable t, Class<?> clazz, String user) {
    final Context context = Sentry.getContext();
    context.setUser(new UserBuilder().setUsername(user).build());
    EventBuilder eventBuilder = new EventBuilder()
            .withMessage(message)
            .withLevel(Event.Level.ERROR)
            .withLogger(clazz.getName())
            .withSentryInterface(new ExceptionInterface(t));
    Sentry.capture(eventBuilder);
    Sentry.clearContext();
}
 
Example #5
Source File: SentryConfiguration.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty("SENTRY_DSN") // only if environment variable exists
public HandlerExceptionResolver sentryExceptionResolver() {
    // Recipe FROM: https://github.com/getsentry/sentry-java/issues/575
    Sentry.getStoredClient().addShouldSendEventCallback(event ->
            event.getSentryInterfaces().values().stream()
                    .filter(ExceptionInterface.class::isInstance)
                    .map(ExceptionInterface.class::cast)
                    .map(ExceptionInterface::getExceptions)
                    .flatMap(Collection::stream)
                    .noneMatch(sentryException ->
                            Arrays.stream(ignoredExceptions).anyMatch(ignoredException -> sentryException.getExceptionClassName().equals(ignoredException))
                    ));
    Sentry.getStoredClient().addBuilderHelper(eventBuilder -> {
        HttpServletRequest request = SentryServletRequestListener.getServletRequest();
        if (request == null) {
            return;
        }
        eventBuilder.withTag("method", request.getMethod());
        eventBuilder.withTag("application", extractApplication(request.getRequestURI()));
        eventBuilder.withTag("uri", defaultString(getMatchingPattern(request)));
        eventBuilder.withTag("query", defaultString(request.getQueryString()));
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        eventBuilder.withSentryInterface(new UserInterface(null, authentication.getName(),
                remoteAddressResolver.getRemoteAddress(request), null), true);
    });
    log.info("Creating a SentryExceptionResolver as HandlerExceptionResolver - Ignored exceptions: {}", ignoredExceptions);
    return new SentryExceptionResolver();
}