Skip to content

Conversation

@KiSeungMin
Copy link
Member

@KiSeungMin KiSeungMin commented Aug 6, 2025

✔️ 연관 이슈

📝 작업 내용

  • 에러 발생 시 Discord Webhook 알림 전송 기능 구현
  • 예외 로그 및, 발생 위치 정보를 포함합니다.
  • EC2 배포 환경에서만 알림을 보내도록 기능을 구현했습니다.
    • 로컬 환경에서는 에러가 발생해도 알림이 가지 않습니다.

스크린샷 (선택)

image

Summary by CodeRabbit

  • 신규 기능

    • 예외 발생 시 Discord 웹훅을 통해 오류 알림을 전송하는 기능이 추가되었습니다.
  • 기타

    • EC2 배포 성공 시 Discord 알림 메시지의 브랜치명이 "main"으로 변경되었습니다.

@KiSeungMin KiSeungMin self-assigned this Aug 6, 2025
@KiSeungMin KiSeungMin added the 💡 feature 기능 구현 및 개발 label Aug 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

Java 코드에 Discord 웹훅 에러 알림 기능이 추가되었습니다. 새로운 DTO 레코드가 생성되어 Discord 웹훅 페이로드 구조를 정의하며, 글로벌 예외 처리기에서 예외 발생 시 Discord로 알림을 전송하도록 변경되었습니다. GitHub Actions 워크플로우의 Discord 성공 메시지도 일부 수정되었습니다.

Changes

Cohort / File(s) Change Summary
Discord 웹훅 페이로드 DTO 추가
src/main/java/com/wayble/server/common/dto/DiscordWebhookPayload.java
Discord 웹훅 메시지 구조를 위한 DiscordWebhookPayload 및 중첩 레코드(Embed, Field) 신설
글로벌 예외 처리기 Discord 알림 연동
src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java
예외 발생 시 Discord 웹훅으로 에러 알림을 전송하는 기능 추가 및 관련 메서드(sendToDiscord) 구현, Spring 프로필 조건 처리
CI/CD 워크플로우 메시지 수정
.github/workflows/cd-develop.yml
EC2 배포 성공 시 Discord 알림 메시지의 브랜치명을 "develop"에서 "main"으로 변경

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant GlobalExceptionHandler
    participant DiscordWebhook

    Client->>Server: 요청 전송
    Server-->>GlobalExceptionHandler: 예외 발생
    GlobalExceptionHandler->>DiscordWebhook: 에러 정보 웹훅 전송 (develop 프로필일 때)
    GlobalExceptionHandler-->>Client: 에러 응답 반환
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
디스코드 웹훅 알림 기능 구현 (#102)

Assessment against linked issues: Out-of-scope changes

(해당 사항 없음)

Possibly related PRs

  • [CI] 61 workflows 웹훅 추가 #62: .github/workflows/cd-develop.yml에서 Discord 웹훅 알림 로직을 처음 추가한 PR로, 워크플로우 알림 관련 직접적인 연관성이 있습니다.

Poem

🐇
에러가 나면 토끼가 뛴다,
디스코드로 소식 전하러 간다.
새 페이로드 품고, 예외를 실어,
개발자 방에 알림이 울려.
오늘도 서버는 안심하고 뛴다!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7811fdf and 73cee64.

📒 Files selected for processing (1)
  • src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/seungmin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (2)

90-100: Discord 전송 실패에 대한 로깅 개선 필요.

Discord 웹훅 전송 실패 시 e.getMessage()만 로깅하고 있는데, 디버깅에 필요한 정보가 부족합니다. HTTP 상태 코드나 응답 내용도 함께 로깅하면 문제 해결에 도움이 됩니다.

로깅 정보를 개선해보세요:

        } catch (Exception e){
-            log.error(e.getMessage());
+            log.error("Discord 웹훅 전송 실패: {}, URL: {}", e.getMessage(), discordWebhookUrl, e);
        }

31-31: RestTemplate 빈 주입 권장.

new RestTemplate()로 인스턴스를 직접 생성하는 대신 Spring의 빈으로 관리하는 것이 좋습니다. 이렇게 하면 커넥션 풀링, 타임아웃 설정, 인터셉터 등을 구성할 수 있습니다.

RestTemplate을 빈으로 주입받도록 변경:

-    private final RestTemplate restTemplate = new RestTemplate();
+    private final RestTemplate restTemplate;

그리고 생성자에서 주입받거나 별도 Configuration 클래스에서 @bean으로 정의하세요.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b6bfb6 and 7811fdf.

📒 Files selected for processing (3)
  • .github/workflows/cd-develop.yml (1 hunks)
  • src/main/java/com/wayble/server/common/dto/DiscordWebhookPayload.java (1 hunks)
  • src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (3 hunks)
🔇 Additional comments (4)
src/main/java/com/wayble/server/common/dto/DiscordWebhookPayload.java (1)

5-17: Discord 웹훅 구조체 설계가 잘 되어있습니다.

Record 클래스를 사용하여 불변성과 간결함을 보장하고, Discord 웹훅 API의 중첩된 구조를 적절히 모델링했습니다. 필수 필드들(content, embeds, title, description 등)이 모두 포함되어 있어 완성도 높은 DTO입니다.

src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (2)

68-71: 프로파일 체크 로직이 정확합니다.

env.acceptsProfiles(Profiles.of("develop")) 사용으로 develop 프로파일에서만 Discord 알림을 보내도록 제한한 것이 PR 목적에 부합합니다. 로컬 환경에서는 알림이 발송되지 않아 불필요한 노이즈를 방지할 수 있습니다.


33-37: Discord 웹훅 URL 설정 확인 필요

application 설정 파일(application.yml/.properties 등)에서 discord.webhook-url 프로퍼티가 누락된 것 같습니다.
@Value("${discord.webhook-url}") 주입 시 해당 설정이 없으면 애플리케이션 구동 실패 또는 NullPointerException이 발생할 수 있습니다.

  • 검토 대상:
    • src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (33행 @Value("${discord.webhook-url}"))
  • 조치 제안:
    • application-{profile}.yml/.properties에 discord.webhook-url 추가
    • @Value("${discord.webhook-url:}") 와 같이 기본값 처리
    • @ConditionalOnProperty(name="discord.webhook-url") 활용

설정 파일에 해당 프로퍼티가 올바르게 포함되어 있는지 확인 부탁드립니다.

.github/workflows/cd-develop.yml (1)

189-189: 브랜치 정보 확인 완료: 워크플로우는 pull_request 이벤트의 branches: ["main"]에서 트리거되므로, Discord 메시지의 “브랜치: main” 변경은 적절합니다.

Comment on lines +74 to +85
DiscordWebhookPayload.Embed embed = new DiscordWebhookPayload.Embed(
"🚨 서버 에러 발생",
"```" + ex.getMessage() + "```",
timestamp,
List.of(
new DiscordWebhookPayload.Embed.Field("URL", path, false),
new DiscordWebhookPayload.Embed.Field("Status", status.toString(), true),
new DiscordWebhookPayload.Embed.Field("Time", timestamp, true),
new DiscordWebhookPayload.Embed.Field("Exception", ex.getClass().getSimpleName(), true)
)
);
DiscordWebhookPayload payload = new DiscordWebhookPayload(null, List.of(embed));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

민감한 정보 노출 위험성 점검.

예외 메시지를 그대로 Discord로 전송하고 있는데, 스택 트레이스나 내부 시스템 정보가 포함될 수 있습니다. 보안상 민감한 정보가 외부로 노출될 위험이 있습니다.

예외 메시지를 필터링하거나 요약하는 로직을 추가하는 것을 고려해보세요:

-                "```" + ex.getMessage() + "```",
+                "```" + sanitizeErrorMessage(ex.getMessage()) + "```",

그리고 메시지 정화 메서드를 추가:

private String sanitizeErrorMessage(String message) {
    if (message == null) return "Unknown error";
    // 민감한 정보 패턴 제거 (예: SQL, 파일 경로, IP 주소 등)
    return message.length() > 500 ? message.substring(0, 500) + "..." : message;
}
🤖 Prompt for AI Agents
In src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java
around lines 74 to 85, the exception message is sent directly to Discord,
risking exposure of sensitive information. To fix this, create a
sanitizeErrorMessage method that filters or truncates the message to remove
sensitive data or limit length, then replace ex.getMessage() with
sanitizeErrorMessage(ex.getMessage()) in the embed description. This ensures
only safe, summarized error details are sent externally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💡 feature 기능 구현 및 개발

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants