Skip to content

Instantly share code, notes, and snippets.

@maciejwalkowiak
Last active September 18, 2023 06:59
Show Gist options
  • Save maciejwalkowiak/02fa1eb0089ebc6e0a4687458a204779 to your computer and use it in GitHub Desktop.
Save maciejwalkowiak/02fa1eb0089ebc6e0a4687458a204779 to your computer and use it in GitHub Desktop.

Installation

Create a Sentry module in <jboss-path>/modules/io/sentry/main/module.xml:

<?xml version='1.0' encoding='UTF-8'?>
<module xmlns="urn:jboss:module:1.1" name="io.sentry">
  <resources>
    <resource-root path="sentry-4.3.0.jar"/>
    <resource-root path="sentry-jul-4.3.0.jar"/>
    <resource-root path="gson-2.8.6.jar"/>
    <resource-root path="slf4j-api-1.7.30.jar"/>
    <resource-root path="."/>
  </resources>
</module>

Download listed above resources jar files to <jboss-path>/modules/io/sentry/main/:

Configure a SentryHandler in <jboss-path>/standalone/configuration/standalone.xml or <jboss-path>/domain/configuration/domain.xml file:

<subsystem xmlns="urn:jboss:domain:logging:8.0">
  // Configure `SentryHandler`
  <custom-handler name="SENTRY" class="io.sentry.jul.SentryHandler" module="io.sentry">
    <level name="INFO"/>
  </custom-handler>
  <root-logger>
    // ...
    <handlers>
      // include SENTRY handler in <root-logger>
      <handler name="SENTRY"/>
      <handler name="CONSOLE"/>
    </handlers>
  </root-logger>
    ...
</subsystem>

Configuration

DSN Configuration

Sentry reads the DSN from the system property sentry.dsn, environment variable SENTRY_DSN or the dsn property in <jboss-path>/modules/io/sentry/main/sentry.properties file. See the configuration page for more details on external configuration.

dsn=___PUBLIC_DSN___

Minimum Log Level

Two log levels are used to configure this integration:

  1. Configure the lowest level required for a log message to become an event (minimumEventLevel) sent to Sentry.
  2. Configure the lowest level a message has to be to become a breadcrumb (minimumBreadcrumbLevel).

Breadcrumbs are kept in memory (by default the last 100 records) and are sent with events. For example, by default, if you log 100 entries with logger.config or logger.warn, no event is sent to Sentry. If you then log with logger.error, an event is sent to Sentry which includes those 100 config or warning messages. For this to work, SentryHandler needs to receive all log entries to decide what to keep as breadcrumb or send as event. Set the SentryHandler log level configuration to a value lower than what is set for the minimumBreadcrumbLevel and minimumEventLevel so that SentryHandler receives these log messages.

<subsystem xmlns="urn:jboss:domain:logging:8.0">
  // ...
  <custom-handler name="SENTRY" class="io.sentry.jul.SentryHandler" module="io.sentry">
    // ...
    <properties>
      <properties name="minimumEventLevel" value="INFO"/>
      <properties name="minimumBreadcrumbLevel" value="CONFIG"/>
    </properties>
  </custom-handler>
  // ...
</subsystem>

String Formatting Style

By default, MessageFormat#format method is used to render parameterized log messages. It can be changed to use String#format by setting printfStyle property to true:

<subsystem xmlns="urn:jboss:domain:logging:8.0">
  // ...
  <custom-handler name="SENTRY" class="io.sentry.jul.SentryHandler" module="io.sentry">
    // ...
    <properties>
      <properties name="printfStyle" value="true"/>
      <properties name="minimumBreadcrumbLevel" value="CONFIG"/>
    </properties>
  </custom-handler>
  // ...
</subsystem>
@srinisubramanian
Copy link

New to Sentry .... After creating all the configurations, events are still not sent unless I call Sentry.captureException(e) .. is it that the specific call needs to be made or the appender needs to send the exception automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment