Skip to content

Commit

Permalink
[Feat] : sentry 모니터링
Browse files Browse the repository at this point in the history
  • Loading branch information
wellbeing-dough committed Feb 14, 2024
1 parent da2d5a0 commit 656255b
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ build/bootJarMainClassName

firebase-service-key.json

### 로깅
logs

*.yml
application.yml
!application-prod.yml
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ dependencies {

// firebase
implementation 'com.google.firebase:firebase-admin:9.2.0'

// sentry
implementation 'io.sentry:sentry-spring-boot-starter:7.3.0'
implementation 'io.sentry:sentry-logback:5.3.0'
}

//querydsl 추가
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/kr/co/studyhubinu/studyhubserver/TestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package kr.co.studyhubinu.studyhubserver;

import io.sentry.Sentry;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

@GetMapping("/v1/asd/12")
public ResponseEntity<HttpStatus> test() {
try {
throw new Exception("This is a test.");
} catch (Exception e) {
Sentry.captureException(e);
}
return ResponseEntity.ok().build();
}
}
11 changes: 10 additions & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ cloud:

firebase:
project:
id: ${firebase.project.id}
id: ${firebase.project.id}

sentry:
dsn: ${sentry_dsn_value}
traces-sample-rate: 1.0
exception-resolver-order: -2147483647 #including ones handled by @ExceptionHandler annotated methods.
debug: true
logging:
enabled: true
minimum-event-level: warn
110 changes: 110 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<property name="LOGS_ABSOLUTE_PATH" value="./logs"/>
<property name="LOG_PATTERN" value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %highlight(%-5level) %logger{36} - %msg%n"/>

<property name="MAX_HISTORY" value="30"/>
<property name="PERFORMANCE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} %-5level %msg%n"/>

<!-- Console Appender -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
</appender>

<appender name="INFO_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOGS_ABSOLUTE_PATH}/info.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<Pattern>${LOG_PATTERN}</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS_ABSOLUTE_PATH}/info.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>${MAX_HISTORY}</maxHistory>
</rollingPolicy>
</appender>

<appender name="WARN_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOGS_ABSOLUTE_PATH}/warn.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<Pattern>${LOG_PATTERN}</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS_ABSOLUTE_PATH}/warn.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>${MAX_HISTORY}</maxHistory>
</rollingPolicy>
</appender>

<appender name="ERROR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOGS_ABSOLUTE_PATH}/error.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<Pattern>${LOG_PATTERN}</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS_ABSOLUTE_PATH}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>${MAX_HISTORY}</maxHistory>
</rollingPolicy>
</appender>

<appender name="PERFORMANCE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS_ABSOLUTE_PATH}/performance.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS_ABSOLUTE_PATH}/performance.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>15MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<charset>utf8</charset>
<Pattern>${PERFORMANCE_LOG_PATTERN}</Pattern>
</encoder>
</appender>

<appender name="Sentry" class="io.sentry.logback.SentryAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>

<root level="ERROR">
<appender-ref ref="Sentry" />
</root>

<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="INFO_LOG"/>
<appender-ref ref="WARN_LOG"/>
<appender-ref ref="ERROR_LOG"/>
</root>

</configuration>

0 comments on commit 656255b

Please sign in to comment.