简体   繁体   English

Sentry in Spring 1.X 根本就不行

[英]Sentry in Spring 1.X simply does not work

We have a spring 1.5.17 app and are trying to simply integrate Sentry.我们有一个 spring 1.5.17 应用程序,正在尝试简单地集成 Sentry。 Because this is an older version of Spring (no upgrading isn't a possiblity), we're following Sentry's Legacy SDK 1.7 directions here .因为这是 Spring 的旧版本(没有升级是不可能的),我们在这里遵循 Sentry's Legacy SDK 1.7的说明。 It's quite straightforward.这很简单。

Configuration配置

Here is pom.这是 pom。 We use other spring libraries like logging/actuator/jpa as well but not showing for clarity.我们也使用其他 spring 库,例如 logging/actuator/jpa,但为清楚起见未显示。 All the same spring version.所有相同的 spring 版本。

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.5.17.RELEASE</version>
</dependency>

Additionally, added sentry.properties file under src/main/resources .此外,在src/main/resources下添加了sentry.properties文件。

enabled=true
dsn=***
environment=uat
sample.rate=1.0
stacktrace.app.packages=com.pls
stacktrace.hidecommon=false

Application应用

Created a boilerplate configuration file overwriting the two beans as per sentry docs.根据 sentry 文档创建了一个覆盖两个 bean 的样板配置文件。

@Configuration
public class SentryConfig {

    @Bean
    public HandlerExceptionResolver sentryExceptionResolver() {
        return new io.sentry.spring.SentryExceptionResolver();
    }

    @Bean
    public ServletContextInitializer sentryServletContextInitializer() {
        return new io.sentry.spring.SentryServletContextInitializer();
    }
}

Via breakpoints, I've confirmed that these beans are initializing and they are getting the properties from sentry.properties correctly.通过断点,我已经确认这些 bean 正在初始化并且它们正在正确地从sentry.properties获取属性。 A related thread , I found that if I manually make SentryClient.captureEvent(event) calls, then events show up in sentry.一个相关的线程,我发现如果我手动进行SentryClient.captureEvent(event)调用,那么事件会显示在哨兵中。 This means that the sentry client is setup correctly and working, but spring isn't actually ever calling .captureEvent() .这意味着哨兵客户端已正确设置并正常工作,但 spring 实际上并未调用.captureEvent()

To confirm my suspicion, I stepped into the SentryExceptionResolver bean and confirmed the code never hits this breakpoint.为了证实我的怀疑,我进入了 SentryExceptionResolver bean 并确认代码从未命中此断点。

在此处输入图像描述

I've tried to trigger the breakpoint by throwing dummy errors in a @RestController ie.我试图通过在@RestController ie 中抛出虚拟错误来触发断点。

@GET
@Path("/test")
public Object throwError(){
  LOGGER.error("ERROR BEING LOGGED");
  throw new RuntimeException("ERROR THROWN");
}

While this error is certainly thrown in the console logs, it does NOT trigger the .capture() codepath.虽然这个错误肯定会在控制台日志中抛出,但它不会触发.capture()代码路径。

Logging?记录?

The related thread mentions something with logging modules, but I don't understand how that's related. 相关线程提到了一些与日志记录模块相关的内容,但我不明白这是如何相关的。 sentry-spring dependency is loading all the app needs and the client is being initialized, just never actually called!! sentry-spring依赖项正在加载所有应用程序需求并且正在初始化客户端,只是从未真正调用过!!

Regardless, I tried adding various logging dependencies (eg. logback as described in this sentry doc ) to no avail.无论如何,我尝试添加各种日志记录依赖项(例如 this sentry doc中描述的 logback )无济于事。 What could possibly be missing from my configuration??!?我的配置中可能缺少什么??!?

In case it matters, we do use spring-boot-starter-logging...以防万一,我们确实使用 spring-boot-starter-logging ...

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
</dependency>

Note that when I add sentry-logback dependency, the app doesnt load.请注意,当我添加sentry-logback依赖项时,应用程序不会加载。

在此处输入图像描述

It seems you are using JAX-RS and not Spring MVC.看来您使用的是 JAX-RS 而不是 Spring MVC。 There is no JAX-RS - Sentry integration working out of the box.没有开箱即用的 JAX-RS - Sentry 集成。

To forward exceptions to Sentry you can also use sentry-logback integration.要将异常转发给 Sentry,您还可以使用sentry-logback集成。 You can configure Logback to forward any logger error to Sentry.您可以配置 Logback 将任何记录器错误转发给 Sentry。 The drawback of not having Spring integration there too is that errors are not decorated with contextual information from the HTTP request.没有 Spring 集成的缺点也是错误没有用来自 HTTP 请求的上下文信息进行修饰。

I am having exactly same issue however I am working with the Sentry 6.13.0 version and a spring-boot version is 2.7.8我遇到了完全相同的问题,但是我使用的是 Sentry 6.13.0 版本,spring-boot 版本是 2.7.8

I am not sure if they have fixed this in the newer version.我不确定他们是否已在较新版本中修复此问题。

However, I am looking and might update the note here when I get somewhere.但是,我正在寻找并且可能会在我到达某个地方时更新此处的注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM