Skip to content

fix: More informative logging on github webhook delivery#412

Merged
adityachoudhari26 merged 1 commit intomainfrom
better-webhook-logging
Mar 24, 2025
Merged

fix: More informative logging on github webhook delivery#412
adityachoudhari26 merged 1 commit intomainfrom
better-webhook-logging

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Mar 24, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling across integrations to provide clearer, more descriptive error messages.
    • Improved logging to capture detailed context when unexpected issues occur.
    • Updated messaging to identify missing job details accurately during processing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2025

Walkthrough

This pull request enhances error handling and logging across multiple modules. In the webhook route, a logger is introduced to capture error details and the error extraction process is refined. In the workflow handler, a missing job now triggers a thrown error with contextual details, rather than silently returning. Additionally, the job update function now produces a more descriptive error message by including the job ID when a job is not found.

Changes

Files Change Summary
apps/webservice/.../webhook/route.ts
apps/webservice/.../webhook/workflow/handler.ts
In the webhook modules, introduced a child logger for improved logging in the POST method and refined error extraction. The workflow handler now throws a detailed error (including job externalId and name) when a job is missing.
packages/job-dispatch/src/job-update.ts Updated the thrown error in updateJob to include the missing job's ID for better clarity.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WebhookRoute
    participant Logger

    Client->>WebhookRoute: POST webhook event
    Note right of WebhookRoute: Process event and detect error
    WebhookRoute->>Logger: Log error details (using child logger)
    WebhookRoute->>Client: Return error response (HTTP 500)
Loading
sequenceDiagram
    participant WorkflowHandler
    participant Caller

    WorkflowHandler->>WorkflowHandler: Fetch job
    alt Job is found
        WorkflowHandler-->>Caller: Proceed with job processing
    else Job is not found
        WorkflowHandler-->>Caller: Throw error with externalId & name
    end
Loading

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

I'm a little rabbit in the code,
Hopping through errors where messages explode.
With logging so clear and errors so bright,
I leap over bugs both day and night.
Carrots and commits, a delightful sight! 🐰🥕


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1046bdf and 0c337bc.

📒 Files selected for processing (3)
  • apps/webservice/src/app/api/github/webhook/route.ts (2 hunks)
  • apps/webservice/src/app/api/github/webhook/workflow/handler.ts (1 hunks)
  • packages/job-dispatch/src/job-update.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • packages/job-dispatch/src/job-update.ts
  • apps/webservice/src/app/api/github/webhook/workflow/handler.ts
  • apps/webservice/src/app/api/github/webhook/route.ts
🧬 Code Definitions (1)
apps/webservice/src/app/api/github/webhook/workflow/handler.ts (1)
packages/db/src/schema/job.ts (1)
  • job (74-106)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Lint
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (5)
packages/job-dispatch/src/job-update.ts (1)

94-94: Improved error message clarity

The change enhances the error message by including the job ID, which will make debugging and troubleshooting easier when a job isn't found.

apps/webservice/src/app/api/github/webhook/workflow/handler.ts (1)

63-64: Enhanced error handling for job not found scenarios

Previously, the function would silently return when a job was null, potentially making debugging difficult. Now it throws an informative error with specific context (externalId and name), which will make it much easier to diagnose issues.

apps/webservice/src/app/api/github/webhook/route.ts (3)

6-6: Added logger import

Good addition of the logger import which will be used for improved error reporting.


12-13: Created contextual logger instance

Creating a child logger with the module name "github-webhook" is a good practice as it will make it easier to filter and identify logs from this specific component.


34-36: Improved error handling with proper logging

The error handling has been enhanced to:

  1. Properly extract error messages regardless of the error type
  2. Log errors before returning them in the response
  3. Provide more context in the error response

This change improves the debugging experience and aligns with the PR objectives.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

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.

@adityachoudhari26 adityachoudhari26 merged commit 4f6d616 into main Mar 24, 2025
9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the better-webhook-logging branch March 24, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant