SpringBoot集成Sentry

添加maven依賴

在pom.xml裏添加:

<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-spring-boot-starter</artifactId>
    <version>4.0.0</version>
</dependency>

<!--此時添加是爲了防止後邊報錯-->
<dependency>
    <groupId>org.aspectj</groupId >
    <artifactId>aspectjweaver</artifactId >
    <version>1.8.9</version>
</dependency>

添加sentry的dsn地址

src/main/application.properties:

sentry.dsn=http://143f0c822e844bd7815273caa25446ab@ip:port/4

或者在src/main/application.yml:

sentry:
  dsn:http://143f0c822e844bd7815273caa25446ab@ip:port/4

測試效果

package com.x.xx.xxx;


import io.sentry.Sentry;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Hello {

    @RequestMapping("/index")
    public String index(){
        try {
            throw new Exception("This is a test.");
        } catch (Exception e) {
            Sentry.captureException(e);
        }
        return "Test";
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章