Skip to content

fix(api): add HTTPException handler for observability#2542

Merged
daryllimyt merged 2 commits intomainfrom
fix/log-http-exceptions
Apr 20, 2026
Merged

fix(api): add HTTPException handler for observability#2542
daryllimyt merged 2 commits intomainfrom
fix/log-http-exceptions

Conversation

@daryllimyt
Copy link
Copy Markdown
Contributor

@daryllimyt daryllimyt commented Apr 20, 2026

Summary

  • Add custom exception handler for HTTPException that logs 4xx/5xx errors with tenant context
  • Use logger.warning for 4xx, logger.error for 5xx
  • Include role context (workspace_id, org_id, user_id), path, method, status_code, and detail

Context

When investigating customer issues (e.g., git sync 400 errors), we could only see HTTP access logs like:

GET /api/workflows/sync/branches ... 400 Bad Request

The actual error detail (e.g., "Git repository URL not configured") was returned to the client but not logged server-side.

Test plan

  • Deploy to staging and trigger a 400 error (e.g., call sync/branches without git_repo_url configured)
  • Verify the error detail appears in logs with role context

Summary by cubic

Add a custom FastAPI HTTPException handler that logs 4xx as warnings and 5xx as errors with tenant role context and request info, and delegates response formatting to FastAPI’s default handler. Registered globally so API errors are logged with path, method, status, and detail while clients receive the standard JSON response.

Written for commit 5bb40bb. Summary will update on new commits.

Add custom exception handler for HTTPException that logs 4xx/5xx errors
with tenant context (role, workspace_id, org_id). This improves
observability for API errors that were previously only visible in HTTP
access logs without details.

- Use logger.warning for 4xx, logger.error for 5xx
- Include role context, path, method, status_code, and detail
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 18:06 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 18:06 — with GitHub Actions Inactive
@zeropath-ai
Copy link
Copy Markdown

zeropath-ai Bot commented Apr 20, 2026

No security or compliance issues detected. Reviewed everything up to 5bb40bb.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► app.py
    Add HTTP exception handler
► common.py
    Implement custom HTTP exception handler for logging

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f97d556d81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tracecat/api/common.py Outdated
@blacksmith-sh
Copy link
Copy Markdown
Contributor

blacksmith-sh Bot commented Apr 20, 2026

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
test_large_collection_regressions/test_scatter_gather_massive_payload_50x2mb_e2e View Logs

Fix in Cursor

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 2 files

Confidence score: 2/5

  • There is a high-confidence, user-facing regression risk in tracecat/api/app.py: the global custom HTTPException handler changes FastAPI semantics by dropping exception headers and always returning a body, which can break auth challenges and HTTP no-body status behavior.
  • The issue in tracecat/api/common.py is similarly severe (7/10, confidence 9/10): missing propagation of HTTPException headers can strip critical protocol headers like WWW-Authenticate and Retry-After, impacting auth and rate-limit flows.
  • Given both findings are concrete and protocol-impacting rather than cosmetic, this is higher merge risk until header propagation and response-shape compatibility are corrected.
  • Pay close attention to tracecat/api/app.py and tracecat/api/common.py - custom exception handling must preserve FastAPI/HTTP header and body semantics.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tracecat/api/app.py">

<violation number="1" location="tracecat/api/app.py:583">
P1: Registering the custom HTTPException handler globally changes FastAPI’s response semantics: it drops exception headers and always returns a body, which can break auth challenges and HTTP compliance for no-body status codes.</violation>
</file>

<file name="tracecat/api/common.py">

<violation number="1" location="tracecat/api/common.py:45">
P1: Propagate `HTTPException` headers in the custom handler; otherwise auth/rate-limit semantics can break (e.g., missing `WWW-Authenticate` or `Retry-After`).</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread tracecat/api/app.py
Comment thread tracecat/api/common.py Outdated
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 18:22 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 18:22 — with GitHub Actions Inactive
@daryllimyt daryllimyt merged commit 6572281 into main Apr 20, 2026
16 of 17 checks passed
@daryllimyt daryllimyt deleted the fix/log-http-exceptions branch April 20, 2026 18:34
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