Sentry log message through eclipse editor for check

Hi Team,

I am trying to check the Sentry error log through running java code through eclipse. even when an exception occurred, I do not see any exceptions in Sentry.

Following configuration, (as part of my POC)
Sentry.Properties File contains below attributes:
dsn=https://0bdf27a99d2344b99427aeb2495a64fd@sentry.io/1235757
stacktrace.app.packages=WT,
sample.rate=0.75
buffer.gracefulshutdown=true
buffer.shutdowntimeout=5000
release=1.0.0
dist=x86
environment=production
servername=http://localhost:8080/prweb/PRServlet

log4j properties file contains below attributes:

Enable the Console and Sentry appenders

log4j.rootLogger=INFO, Console, Sentry

Configure the Console appender

log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{HH🇲🇲ss.SSS} [%t] %-5p: %m%n

Configure the Sentry appender, overriding the logging threshold to the WARN level

log4j.appender.Sentry=io.sentry.log4j.SentryAppender
log4j.appender.Sentry.threshold=WARN

and the Java code:
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.SentryClientFactory;
import io.sentry.context.Context;
import io.sentry.event.BreadcrumbBuilder;
import io.sentry.event.UserBuilder;
public class WT {
private static SentryClient sentry;
public static void main(String… args) {
/
It is recommended that you use the DSN detection system, which
will check the environment variable “SENTRY_DSN”, the Java
System Property “sentry.dsn”, or the “sentry.properties” file
in your classpath. This makes it easier to provide and adjust
your DSN without needing to change your code. See the configuration
page for more information.
/
Sentry.init();
// You can also manually provide the DSN to the init method.
String dsn = “https://ba018e5387354012b08668fc75c618eb@sentry.io/1199682”; Sentry.init(dsn);

    /
    It is possible to go around the static ``Sentry`` API, which means
    you are responsible for making the SentryClient instance available
    to your code.
    /
   sentry = SentryClientFactory.sentryClient();
  WT myClass = new WT();
  myClass.logWithStaticAPI();
   myClass.logWithInstanceAPI();  
}
/*
  An example method that throws an exception.
 /
void unsafeMethod() {
    throw new UnsupportedOperationException("You shouldn't call this!");
}

/
  Examples using the (recommended) static API.
 /
void logWithStaticAPI() {
    // Note that all fields set on the context are optional. Context data is copied onto
    // all future events in the current context (until the context is cleared).
    // Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.
    Sentry.getContext().recordBreadcrumb(
        new BreadcrumbBuilder().setMessage("User made an action").build()
    );
    // Set the user in the current context.
    Sentry.getContext().setUser(
        new UserBuilder().setEmail("hello@sentry.io").build()
    );
    // Add extra data to future events in this context.
    Sentry.getContext().addExtra("extra", "thing");
    // Add an additional tag to future events in this context.
    Sentry.getContext().addTag("tagName", "tagValue");

    /
    This sends a simple event to Sentry using the statically stored instance
    that was created in the ``main`` method.
    /
    Sentry.capture("This is a test");

    try {
        unsafeMethod();
    } catch (Exception e) {
        // This sends an exception event to Sentry using the statically stored instance
        // that was created in the ``main`` method.
        Sentry.capture(e);
    }
}
/
  Examples that use the SentryClient instance directly.
 */
void logWithInstanceAPI() {
    // Retrieve the current context.
    Context context = sentry.getContext();
    // Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.
    context.recordBreadcrumb(new BreadcrumbBuilder().setMessage("User made an action").build());

    // Set the user in the current context.
    context.setUser(new UserBuilder().setEmail("hello@sentry.io").build());
    // This sends a simple event to Sentry.
    sentry.sendMessage("This is a test");
    try {
        unsafeMethod();
    } catch (Exception e) {
        // This sends an exception event to Sentry.
        sentry.sendException(e);
    }
}

}

When we run the Java cpde, there was an exception, that was not send to sentry

Hi Ramar,

I faced this similar issue in running basic example too which is shown on the manual usage documentation page. I have all Sentry dependencies downloaded properly, can run the java class properly, I can see the exceptions in my IDE (STS). But the events don’t show up on Sentry dashboard. Tried hardcoding the DSN in init method, passed it from properties file, added as environment variable, but nothing helped. Any guidance will be of great help.

I got the solution. I edited DSN by using “?async=false” in the end. We can add this in the property file as well. Various options can be added in the property file. I referred https://docs.sentry.io/platforms/java/configuration/options/