Java EE (JBoss) integration (advice)

we are already using sentry self-hosted, just not yet for java (EE)

I’m looking at this example in regards to triggering events.

    try {
       int example = 1 / 0;
    } catch (Exception e) {
      logger.error("Caught exception!", e);
   }

I’m sure this is more of a java question rather than a sentry(sdk) version but ; what if an error happens and is not sent to logger.error()?

Is it sent to sentry?

The problem is that all code blocks are not ‘equipped’ with try/catch blocks and subsequently with logger.error()…how do these errors arrive to sentry?

hi @bruno-garcia, can you offer any advice or at least point me to any direction?

Sentry’s Java SDK also capture unhandled exceptions. So if the process is going to crash, Sentry will send an event for that

1 Like

@bruno-garcia, thanks for the reply.

What I did

  • log4j2.xml file
  • sentry.properties and dns=myprojectdsn entry
  • sentry-log4j2 dependency through maven

Shoud, in this case/configuration, uncaught exceptions also be caught? I can verify that, if ‘pushed’ trough logger.error(), the error is shown in Sentry. But uncaught (the same mistake) isn’t.

Should I explicitly install ‘sentry’ through maven?

It’s been a while since I worked with JBoss but as far as I can tell: either you need to catch the exception (in case you use JAX-RS take a look here how this can be done) or you need to configure JBoss to use log4j2 and configure SentryAppender there. You may find this guide useful.

Yes, but this is exactly what is done with sentra-log4j2 package :slight_smile: (?)

Keep in mind that sentry-java master is a base for 3.0 version which is very different from the 1.7.x that you are likely using (?).

In both cases, SDK comes with a Sentry appender that must be configured - either in application or in the application server. Is this unhandled exception logged using log4j2 configured in your application, or is it logged with loggers managed by JBoss?

hi, @maciejwalkowiak

yes, using 1.7

<dependency>
   <groupId>io.sentry</groupId>
   <artifactId>sentry-log4j2</artifactId>
   <version>1.7.30</version>

Uncaught exception is logged by (and is not in Sentry) :
“loggerClassName”:“org.jboss.as.ejb3.logging.EjbLogger_$logger”

‘Caught’ exception (logger.error()) is logged in Sentry :
“loggerClassName”:“org.jboss.logmanager.Logger”

It seems that, somehow, I need to override default ejb logging?

Some updated info of what I did :

I added an additional exception ( int a = 1 / 0; ) which is not logged in Sentry (in both examples).

What I’m i doing wrong / not understanding?

We need a lot more information to be able to answer this question. Are you using a self-hosted Sentry (I think you do based on your initial message)? Then have you checked its logs to see if the events are actually getting to your Sentry instances? If that’s the case do all workers and services run properly?

Hi,

I’m using self-hosted sentry, yes, latest version (20+).

For the errors that do come to Sentry, I see information in logs. For the uncaught errors, there is nothing - nothing in logs, no tcpdump traffic.

Sounds like a an SDK related thing then. Pinging @bruno-garcia

We’ve release Java 3.0 this week, could you please try it out?

Docs for log4j2 are here:

1 Like

Good information thanks for sharing
vmware

@bruno-garcia ; just replacing 1.7.30 with 3.0.0 in pom.xml causes this :

package org.apache.logging.log4j does not exist

Output of mvn dependency:tree

[INFO] — maven-dependency-plugin:2.8:tree (default-cli) @ sentry-java-log4j2-example —
[INFO] io.sentry:sentry-java-log4j2-example:jar:1.0-SNAPSHOT
[INFO] ± io.sentry:sentry-log4j2:jar:3.0.0:compile
[INFO] | ± io.sentry:sentry:jar:3.0.0:compile
[INFO] | | - com.google.code.gson:gson:jar:2.8.5:runtime
[INFO] | ± org.apache.logging.log4j:log4j-api:jar:2.13.3:runtime
[INFO] | - org.apache.logging.log4j:log4j-core:jar:2.13.3:runtime
[INFO] - org.slf4j:slf4j-simple:jar:1.7.22:compile
[INFO] - org.slf4j:slf4j-api:jar:1.7.22:compile

org.apache.logging.log4j:log4j-api:jar is set as a runtime dependency - meaning we don’t bring this dependency and you need to include it yourself.

Please just add the dependency to log4j2 in your Maven or Gradle configuration file and this issue will be resolved.

Thanks for the info.

Created a simple .war (for our JBOSS EAP 7.2) - no luck

Error is sent to Sentry :

private static final Logger logger = LogManager.getLogger(TestProjectRest.class.getName());
try {
int example = 1/0;
} catch (Exception e) {
logger.error(“Uncaught exception in TestProjectRest!”, e);
return Response.serverError().entity(“{"Error":"” + “"}”).build();
}

First line of server.log (JBOSS):

“loggerClassName”:“org.jboss.logmanager.Logger”,“loggerName”:“stdout”

Error is not sent to Sentry :

private static final Logger logger = LogManager.getLogger(TestProjectRest.class.getName());
int example = 1/0;

First line of server.log (JBOSS):

“loggerClassName”:“org.jboss.as.ejb3.logging.EjbLogger_$logger”,“loggerName”

Lets first take a small(er) step ;

There is an example for java basic : https://github.com/getsentry/examples/tree/master/java/basic

It uses ‘sentry 1.7.5’. Last version of 1.7 branch is 1.7.30 and the latest is 3.0.0. Would it be possible to update this example with version 3.0.0?
It would be nice if the example would also have an example of uncaught exception.

Please take a look at this PR that updates an example to Sentry 3.0: https://github.com/getsentry/examples/pull/59

If it won’t solve your issue - provide please more information about your application. Do you configure Sentry appender in the application or on the application server level? Is it a Java EE application or Spring or something else? If you could provide a minimal example that I could just take and deploy to JBoss it would help me finding an issue.

1 Like

The thread continues here: https://forum.sentry.io/t/re-java-ee-jboss-integration-advice/11438