io.sentry.context.Context Java Examples

The following examples show how to use io.sentry.context.Context. 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 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 #2
Source File: SentryHelper.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void captureMessageContext(String message, 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.INFO)
            .withLogger(clazz.getName());

    Sentry.capture(eventBuilder);
    Sentry.clearContext();
}
 
Example #3
Source File: SentryHelper.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void captureMessageErrorContext(String message, 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());

    Sentry.capture(eventBuilder);
    Sentry.clearContext();
}
 
Example #4
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 #5
Source File: MailSendService.java    From staffjoy with MIT License 4 votes vote down vote up
@Async(AppConfig.ASYNC_EXECUTOR_NAME)
public void sendMailAsync(EmailRequest req) {
    IToLog logContext = () -> {
        return new Object[] {
                "subject", req.getSubject(),
                "to", req.getTo(),
                "html_body", req.getHtmlBody()
        };
    };

    // In dev and uat - only send emails to @jskillcloud.com
    if (!EnvConstant.ENV_PROD.equals(envConfig.getName())) {
        // prepend env for sanity
        String subject = String.format("[%s] %s", envConfig.getName(), req.getSubject());
        req.setSubject(subject);

        if (!req.getTo().endsWith(MailConstant.STAFFJOY_EMAIL_SUFFIX)) {
            logger.warn("Intercepted sending due to non-production environment.");
            return;
        }
    }

    SingleSendMailRequest mailRequest = new SingleSendMailRequest();
    mailRequest.setAccountName(MailConstant.FROM);
    mailRequest.setFromAlias(MailConstant.FROM_NAME);
    mailRequest.setAddressType(1);
    mailRequest.setToAddress(req.getTo());
    mailRequest.setReplyToAddress(false);
    mailRequest.setSubject(req.getSubject());
    mailRequest.setHtmlBody(req.getHtmlBody());

    try {
        SingleSendMailResponse mailResponse = acsClient.getAcsResponse(mailRequest);
        logger.info("Successfully sent email - request id : " + mailResponse.getRequestId(), logContext);
    } catch (ClientException ex) {
        Context sentryContext = sentryClient.getContext();
        sentryContext.addTag("subject", req.getSubject());
        sentryContext.addTag("to", req.getTo());
        sentryClient.sendException(ex);
        logger.error("Unable to send email ", ex, logContext);
    }
}