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";
    }
}
posted @ 2021-02-23 17:38  临冬城城主  阅读(1576)  评论(0编辑  收藏  举报