반응형

Sentry Project 생성

  • Sentry > Projects > Create Project
  • Popular > SPRING BOOT 선택
  • Project name : spring-sentry-test
  • Create Project 클릭하여 생성

application.properties

  • 생성시 이동한 페이지에서 아래 정보 확인 가능
  • 추후에 Sentry > Settings > Projects > spring-sentry-test > Client Keys에서도 확인 가능
sentry.dsn=http://2001dedc1de14412b72245f08cc8848d@192.168.56.12:9000/4
sentry.traces-sample-rate=1.0
sentry.logging.minimum-event-level=info
sentry.logging.minimum-breadcrumb-level=info

Gradle

dependencies {
    ...
    implementation 'io.sentry:sentry-spring-boot-starter:5.4.2'
    implementation 'io.sentry:sentry-logback:5.4.2'
}

ExampleSesrvice

@Slf4j
@Service
public class ExampleService {
    public void example1() {
        log.info("Hello World1");
    }

    public void example2() {
        Message message = new Message();
        message.setMessage("Hello World2");

        SentryEvent event = new SentryEvent();
        event.setTag("test_id", UUID.randomUUID().toString());
        event.setLevel(SentryLevel.WARNING);
        event.setMessage(message);

        Sentry.captureEvent(event);
    }

    public void example3() {
        try {
            throw new Exception("This is a test.");
        } catch (Exception e) {
            Sentry.captureException(e);
        }
    }
}

Test

  • 아래 테스트 실행 후 Sentry > Issues에 남겨진 로그 확인
@SpringBootTest
public class SentryTest {
    @Autowired
    private ExampleService exampleService;

    @Test
    public void testService() {
        exampleService.example1();
        exampleService.example2();
        exampleService.example3();
    }
}
반응형

'Development > Sentry' 카테고리의 다른 글

[Sentry] 설치하기  (0) 2021.06.27

+ Recent posts