如何将 Java Wildfly Swarm 应用程序与 Sentry 集成?
How to integrate Java Wildfly Swarm applications with Sentry?
我们有一个 Java Wildfly Swarm application and I'm trying to configure it to report Sentry 事件。
参考版本:
- Wildfly BOM: org.wildfly.bom:wildfly-javaee7:10.1.0.Final
- Swarm 插件: org.wildfly.swarm:wildfly-swarm-plugin:2017.12.1
我添加了以下配置:
<!-- pom.xml -->
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.13</version>
</dependency>
# project-defautls.yml
swarm:
logging:
pattern-formatters:
LOG_FORMATTER:
pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p (%t) [%c.%M()] %s%e%n"
console-handlers:
CONSOLE:
named-formatter: LOG_FORMATTER
level: INFO
custom-handlers:
SENTRY:
module: com.sentry.jul
attribute-class: io.sentry.jul.SentryHandler
named-formatter: LOG_FORMATTER
level: INFO
root-logger:
handlers:
- CONSOLE
- SENTRY
<!-- module.xml -->
<module xmlns="urn:jboss:module:1.3" name="com.sentry.jul">
<resources>
<artifact name="io.sentry:sentry:1.7.13" />
</resources>
</module>
# Environment variable
SENTRY_DSN=***********
应用程序正常启动,但以下代码片段未生成 Sentry 事件:
try {
throw new Exception("Testing...");
} catch(Exception e) {
logger.log(Level.SEVERE, "ERROR {0}", e.getMessage());
}
另一方面,当我通过 code 配置 Sentry 并生成一个事件时它工作正常:
Sentry.init(System.getenv("SENTRY_DSN"));
SentryClient sentry = SentryClientFactory.sentryClient();
try {
throw new Exception("Testing...");
} catch(Exception e) {
sentry.sendException(e);
}
出了什么问题?
调试代码后我发现我的模块定义不完整。我不得不添加其他工件和依赖项:
<module xmlns="urn:jboss:module:1.3" name="com.sentry.jul">
<resources>
<artifact name="io.sentry:sentry:1.7.13" />
<artifact name="com.fasterxml.jackson.core:jackson-core:2.8.7" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.servlet.api" />
<module name="org.slf4j"/>
</dependencies>
</module>
我还注意到没有必要保持对 Sentry 的项目依赖。
就这些了!
我们有一个 Java Wildfly Swarm application and I'm trying to configure it to report Sentry 事件。
参考版本:
- Wildfly BOM: org.wildfly.bom:wildfly-javaee7:10.1.0.Final
- Swarm 插件: org.wildfly.swarm:wildfly-swarm-plugin:2017.12.1
我添加了以下配置:
<!-- pom.xml -->
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.13</version>
</dependency>
# project-defautls.yml
swarm:
logging:
pattern-formatters:
LOG_FORMATTER:
pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p (%t) [%c.%M()] %s%e%n"
console-handlers:
CONSOLE:
named-formatter: LOG_FORMATTER
level: INFO
custom-handlers:
SENTRY:
module: com.sentry.jul
attribute-class: io.sentry.jul.SentryHandler
named-formatter: LOG_FORMATTER
level: INFO
root-logger:
handlers:
- CONSOLE
- SENTRY
<!-- module.xml -->
<module xmlns="urn:jboss:module:1.3" name="com.sentry.jul">
<resources>
<artifact name="io.sentry:sentry:1.7.13" />
</resources>
</module>
# Environment variable
SENTRY_DSN=***********
应用程序正常启动,但以下代码片段未生成 Sentry 事件:
try {
throw new Exception("Testing...");
} catch(Exception e) {
logger.log(Level.SEVERE, "ERROR {0}", e.getMessage());
}
另一方面,当我通过 code 配置 Sentry 并生成一个事件时它工作正常:
Sentry.init(System.getenv("SENTRY_DSN"));
SentryClient sentry = SentryClientFactory.sentryClient();
try {
throw new Exception("Testing...");
} catch(Exception e) {
sentry.sendException(e);
}
出了什么问题?
调试代码后我发现我的模块定义不完整。我不得不添加其他工件和依赖项:
<module xmlns="urn:jboss:module:1.3" name="com.sentry.jul">
<resources>
<artifact name="io.sentry:sentry:1.7.13" />
<artifact name="com.fasterxml.jackson.core:jackson-core:2.8.7" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.servlet.api" />
<module name="org.slf4j"/>
</dependencies>
</module>
我还注意到没有必要保持对 Sentry 的项目依赖。
就这些了!