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";
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM