sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Sentry install steps for JBoss

Open marandaneto opened this issue 4 years ago • 15 comments

https://www.jboss.org/

Relates to https://github.com/getsentry/sentry-java/issues/1471

marandaneto avatar May 31 '21 07:05 marandaneto

JBoss support is done through sentry-jul package. The challenge is only to configure it properly. I wrote down how to do it: https://gist.github.com/maciejwalkowiak/02fa1eb0089ebc6e0a4687458a204779 which either may go to official docs, or we can add it to https://github.com/getsentry/examples/tree/master/java. What do you think @marandaneto @bruno-garcia?

The big difference between our regular integrations and this guide, is that configuring Sentry in JBoss does not let to use Sentry SDK in the deployed application. JBoss configuration solves only passing logs to Sentry and limit configuration options to what can be configured externally - calling Sentry.init from the deployed application won't have an effect on the whole application server.

maciejwalkowiak avatar May 31 '21 11:05 maciejwalkowiak

if we already have support and it's just a matter of docs + sample, I'd say that both would make sense, but the official docs could link to the sample instead of duplicating the content.

maybe it'd also make sense to add to https://github.com/getsentry/sentry-java/tree/main/sentry-samples so we guarantee that the compilation with this setup isn't broken when doing changes, does that make sense or not really? not sure if it'd be possible to "build" it using Gradle

marandaneto avatar May 31 '21 11:05 marandaneto

There's not much duplicating as the configuration is very different. Also, there are many ways JBoss can be set up, so the configuration is not completely obvious. We cannot verify compilation as checking if it works requires downloading JBoss and configuring it - but thats not a concern as the compilation is verified in the sentry-jul module.

Adding it to official docs, probably will require us to provide similar level of support as to other modules (not sure if we want to). Adding this to example repo would give us a place we can refer people to who are struggling with setting up JBoss.

maciejwalkowiak avatar May 31 '21 11:05 maciejwalkowiak

what I meant is, do the basic setup that captureMessage and captureException work via Sentry static or JUL under https://github.com/getsentry/sentry-java/tree/main/sentry-samples and the official docs link to it, it's probably a good start already.

marandaneto avatar Jun 01 '21 05:06 marandaneto

Hi,

I'm testing/using on JBOSS 7.2.9, domain mode.

I'l test this ASAP. If any other help is needed, let me know.

But for now :

1.) From the documentation : '...See the configuration page for more details on external configuration....' --> This gist ( https://gist.github.com/platforms/java/configuration/ ) is 404

2.) Is it possible to set-up DNS through MDC? You (can) have many apps on JBOSS, each needs it's own DSN. The idea (my) is, that 'the first' dsn is written in '/modules/io/sentry/main/sentry.properties' but the, with each error, it's overriden though MDC?

klemenag avatar Jun 01 '21 06:06 klemenag

@klemenag

1). the correct link is https://docs.sentry.io/platforms/java/configuration/ (this gist was written as it would be integrated with official docs).

2). Currently there is no way to set up DSN per app in such setup. I am thinking how this could be done - as far as I can see there is no way to initialize Sentry on the application side and at the same time use Sentry configured in JBoss logging subsystem. We could workaround it through adding an option to set the DSN on the handler itself, and then configure handler per application in JBoss logging configuration.

maciejwalkowiak avatar Jun 01 '21 09:06 maciejwalkowiak

@maciejwalkowiak - Thank you for your time/effort/reply.

1.) I see, thanks.

2a.) That (configuring dns per handler) could/should work all-though this requires some development effort at Sentry's end.

2b.) I'm not an expert in Java but, what about MDC? Couldn't we initialize sentry with DSN then override it, per-app, with MDC?

klemenag avatar Jun 01 '21 09:06 klemenag

Sentry DSN is set once when Sentry is initialized, with MDC this means that for each log event the handler would have to lookup the client corresponding to this key. I think this is not a right way to go.

maciejwalkowiak avatar Jun 01 '21 09:06 maciejwalkowiak

Yes, agreed.

Sadly, we are in need of Sentry+JBOSS solution and would accept any solution as long it is working, even if it's temporary and/or a workaround.

Having one sentry dsn for the whole JBOSS server (all of the apps) is...less helpful.

I'll try the gist ASAP.

klemenag avatar Jun 01 '21 09:06 klemenag

You can use Sentry static API when you include Sentry in your application and initialize it there. The puzzle is only how to configure it with JBoss logging susbsystem.

maciejwalkowiak avatar Jun 01 '21 09:06 maciejwalkowiak

Yes, sound ok except for one thing - uncaught exceptions.

Uncaught exceptions are only logged to root logger, therefore Sentry must be implemented as a JBOSS logging subsystem (root logger). Or am I misunderstanding something?

klemenag avatar Jun 01 '21 10:06 klemenag

I've done several tests and unfortunately I did not find an elegant solution. At this stage my conclusion is:

  • there can be only single SentryHandler registered in in JBoss logging configuration - meaning single DSN applies to all applications
  • to use per-application Sentry configuration, Sentry must be configured on the application level - and Sentry.captureException must be called for sending exceptions to Sentry. In case of unhandled exceptions and JAX-RS, an ExceptionMapper<Throwable> can be registered that depending on the exception type, sends it to Sentry.

I think we can keep this issue open for a while as I am open for the voices from community - in case someone has a better idea on this topic.

maciejwalkowiak avatar Jun 02 '21 12:06 maciejwalkowiak

Hi,

I have tested the integration on JBOSS level and it's working as expected.

Let me clarify ; I have previous experience with php, ruby, .... where implementing sentry is really simple and it works (perfectly). But yes, concepts there are not the same as with EAP Java.

What I would like or/and I'm trying to achieve is a functionality of some sort where programmer wouldn't need to predict every try/catch block (or something of the sort).

ExceptionMapper<Throwable> is useful, but looking at the example here ( ' https://howtodoinjava.com/resteasy/resteasy-exceptionmapper-example/ ' ) every exception still needs to be caught separately. I know that the code written in the link is a case of good programming....but we can't expect that every line of code is handled properly.

For test 'purposes' I presume a line of ( ' int a = 1 / 0 ' ). That's it. No try catch, nothing.

But for now I still hadn't find a way how to 'get' this to Sentry.

TL;DR : I would like to send error reports to Sentry without (major) programmer involvment.

klemenag avatar Jun 15 '21 13:06 klemenag

@klemenag

ExceptionMapper is useful, but looking at the example here ( ' https://howtodoinjava.com/resteasy/resteasy-exceptionmapper-example/ ' ) every exception still needs to be caught separately.

How about registering ExceptionMapper<Throwable> or ExceptionMapper<Exception>? Wouldn't it catch all the unhandled cases including 1/0 without a need to declare mapper for each exception type?

maciejwalkowiak avatar Jun 16 '21 06:06 maciejwalkowiak

This is working, amazing! Thanks!

Maybe add this to documentation at least as a hint?

klemenag avatar Aug 18 '21 07:08 klemenag

@adinauer since we have a separate docs ticket https://github.com/getsentry/sentry-docs/issues/4600, should we just close this one?

romtsn avatar Jan 16 '24 22:01 romtsn

Yeah, let's use the one in docs. Closing this one.

adinauer avatar Jan 17 '24 10:01 adinauer