Skip to content

Commit

Permalink
Merge pull request #193 from 9uttery/feat/#192
Browse files Browse the repository at this point in the history
[Configuration] Sentry 관련 설정
  • Loading branch information
mingeun0507 authored May 18, 2024
2 parents 6ddaaef + 0f9c8cd commit 1ac6f11
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 16 deletions.
62 changes: 47 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
buildscript {
ext {
queryDslVersion = "5.0.0"
}
repositories {
mavenCentral()
}
ext {
queryDslVersion = "5.0.0"
}
repositories {
mavenCentral()
}
}

plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'io.sentry.jvm.gradle' version '4.5.1'
}

group = 'com.guttery'
Expand All @@ -32,7 +33,6 @@ repositories {

dependencies {
// Spring Boot 의존성
// JPA, Redis, Security, Validation, Web, Cache, Mail, Thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-security'
Expand All @@ -58,8 +58,8 @@ dependencies {

// QueryDSL
implementation "com.querydsl:querydsl-jpa:5.0.0:jakarta"
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
// annotationProcessor "io.github.mingeun0507:querydsl-apt-for-records:5.0.0.M1"
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
//annotationProcessor "io.github.mingeun0507:querydsl-apt-for-records:5.0.0.M1"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

Expand All @@ -79,11 +79,15 @@ dependencies {
// DB
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
implementation "org.springframework.boot:spring-boot-starter-data-mongodb"

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

// Sentry
implementation 'io.sentry:sentry-jdbc:6.29.0'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
Expand All @@ -97,16 +101,44 @@ tasks.named('test') {
useJUnitPlatform()
}

def generated = layout.buildDirectory.dir("generated/querydsl").get().asFile
def generated = file("$buildDir/generated/querydsl")

tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(generated))
sourceSets {
main {
java {
srcDirs += generated
}
}
}

sourceSets {
main.java.srcDirs += [generated]
task createGeneratedDir {
doLast {
if (!generated.exists()) {
generated.mkdirs()
}
}
}

tasks.withType(JavaCompile) {
dependsOn createGeneratedDir
options.annotationProcessorGeneratedSourcesDirectory = generated
}

clean {
delete file(generated)
delete file(generated)
}

sentry {
includeSourceContext = true
org = "9uttery"
projectName = "madii"
authToken = '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'
}

tasks.named('sentryCollectSourcesJava').configure {
dependsOn compileJava, compileTestJava
}

tasks.named('generateSentryBundleIdJava').configure {
dependsOn compileJava
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ private CustomException(ErrorDetails errorDetails) {
}

public static CustomException of(ErrorDetails errorDetails) {
return new CustomException(errorDetails);
final CustomException customException = new CustomException(errorDetails);
SentryCapturingHelper.captureException(customException);
return customException;
}

public int getErrorDetailsStatus() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.guttery.madii.common.exception;

import io.sentry.Sentry;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SentryCapturingHelper {
private static final String SPRING_PROFILE_ACTIVE = "spring.profiles.active";
private static final String SENTRY_ENABLED_PROFILE = "prod";

public static void captureException(Exception e) {
if (isSentryEnabled()) {
Sentry.captureException(e);
}
}

private static boolean isSentryEnabled() {
if (System.getProperty(SPRING_PROFILE_ACTIVE) == null) {
return false;
}

return System.getProperty(SPRING_PROFILE_ACTIVE).equals(SENTRY_ENABLED_PROFILE);
}

}

0 comments on commit 1ac6f11

Please sign in to comment.