Skip to content

feat: add gateway logs to project details#4014

Merged
chronark merged 12 commits intomainfrom
project-details-logs
Sep 25, 2025
Merged

feat: add gateway logs to project details#4014
chronark merged 12 commits intomainfrom
project-details-logs

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Sep 23, 2025

What does this PR do?

This PR shows build steps when someone first deploy's project, after the deployment status is set to "Ready", we switch to "Gateway Logs'. In the future we can add a switch for "Gateway Logs" | "Runtime Logs" since now we have a unified response for displaying logs.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Deploy something
  • Test the gateway logs by calling demo_api routes. Test filtering and searching them.
  • Its hard to test build steps because its so fast and there are only 3 steps so if you are testing locally you can switch the hook manually and see the results.

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary
Screen.Recording.2025-09-23.at.15.09.40.mov

@vercel
Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
dashboard Ready Ready Preview Comment Sep 25, 2025 1:36pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
engineering Ignored Ignored Preview Sep 25, 2025 1:36pm

@changeset-bot
Copy link

changeset-bot bot commented Sep 23, 2025

⚠️ No Changeset found

Latest commit: ec61e22

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

📝 Walkthrough

Walkthrough

Adds a dual-source deployment logs model (build steps vs gateway logs) controlled by deployment status, introduces a TRPC build-steps endpoint, removes legacy buildLogs and a deployment sub-router, and updates UI/hook wiring, types, formatting, and small UI/styling tweaks.

Changes

Cohort / File(s) Summary
ActiveDeployment UI
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx
Derives showBuildSteps from deployment status, passes it to the logs hook, toggles labels ("Build logs" / "Gateway logs"), formats timestamps, changes export signature, and swaps Card import path.
Deployment logs hook
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx
Adds showBuildSteps prop; introduces unified LogEntry shape and storedLogs Map; conditionally queries buildSteps or gateway logs; normalizes, sorts, caps, filters, and counts logs; updates loading/expand/scroll timing constants.
TRPC: new build-steps endpoint
apps/dashboard/lib/trpc/routers/deploy/deployment/build-steps.ts
New getDeploymentBuildSteps procedure with logEntry schema and exported types; queries DB for deployment build steps and returns { logs }, handling NOT_FOUND and internal errors.
TRPC wiring update
apps/dashboard/lib/trpc/routers/index.ts
Replaces getDeploymentBuildLogs with getDeploymentBuildSteps on the deployment router surface (exposes buildSteps).
Removed legacy build-logs
apps/dashboard/lib/trpc/routers/deploy/deployment/buildLogs.ts
Deleted old in-memory getDeploymentBuildLogs, its types, and related exports.
Removed deployment sub-router
apps/dashboard/lib/trpc/routers/deploy/deployment/index.ts
Deleted the deployment sub-router file and its exported deploymentRouter.
FilterButton prop tweak
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/filter-button.tsx
FilterButtonProps.count changed from number to `number
Gateway logs styles
apps/dashboard/app/(app)/projects/[projectId]/gateway-logs/components/table/utils/get-row-class.ts
Adjusted warning icon base size class from size-3 to size-[13px] mb-[1px].
Domain link
apps/dashboard/app/(app)/projects/[projectId]/details/domain-row.tsx
Wraps domain display in next/link to open in a new tab and preserve the ShareUpRight icon.
go demo favicon guard
go/demo_api/main.go
Adds early return for /favicon requests in root handler.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Card as ActiveDeploymentCard
  participant Hook as useDeploymentLogs
  participant TRPC as trpc (buildSteps / logs.queryLogs)
  participant DB as Database

  User->>Card: Open Active Deployment view
  Card->>Hook: useDeploymentLogs({ deploymentId, showBuildSteps })
  alt showBuildSteps = true
    Hook->>TRPC: deploy.deployment.buildSteps(deploymentId)
    TRPC->>DB: Query build steps
    DB-->>TRPC: Steps
    TRPC-->>Hook: { logs: [{id,timestamp,message}] }
  else showBuildSteps = false
    Hook->>TRPC: logs.queryLogs({ deploymentId })
    TRPC->>DB: Query gateway logs
    DB-->>TRPC: Log rows
    TRPC-->>Hook: Logs (status, time, path, ...)
  end
  Hook->>Hook: Normalize entries → storedLogs Map → sort & cap → compute counts/filteredLogs
  Hook-->>Card: { logs, logCounts, isLoading, isExpanded, ... }
  Card-->>User: Render Build logs or Gateway logs list
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • chronark
  • mcstepp
  • perkinsjr
  • imeyer

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description includes the main summary, type of change, testing instructions, and checklist sections from the template but omits the required “Fixes #” line and leaves all checklist items unchecked, indicating incomplete template usage. Additionally, the Type of change section marks every category, which is inconsistent with standard practice. Because key template elements are missing or incorrectly filled, the description does not fully adhere to the repository’s standards. Please add a “Fixes #” line or reference an existing issue, update the checklist items to reflect completed tasks, and refine the Type of change section to only include the relevant categories.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary feature added by this pull request—namely, the inclusion of gateway logs in the project details view—and follows a conventional commit prefix. It clearly indicates the scope and intent of the change without unnecessary detail or noise. This makes it easy for reviewers and future readers to understand the main purpose at a glance.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch project-details-logs

📜 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 768eec6 and ec61e22.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/projects/[projectId]/details/domain-row.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/(app)/projects/[projectId]/details/domain-row.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Build / Build
  • GitHub Check: Vercel Agent Review
  • GitHub Check: Analyze (javascript-typescript)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@ogzhanolguncu ogzhanolguncu marked this pull request as ready for review September 25, 2025 09:47
@github-actions
Copy link
Contributor

github-actions bot commented Sep 25, 2025

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@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: 5

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc42f31 and 88f8f4f.

📒 Files selected for processing (6)
  • apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (3 hunks)
  • apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx (7 hunks)
  • apps/dashboard/lib/trpc/routers/deploy/deployment/build-steps.ts (1 hunks)
  • apps/dashboard/lib/trpc/routers/deploy/deployment/buildLogs.ts (0 hunks)
  • apps/dashboard/lib/trpc/routers/deploy/deployment/index.ts (0 hunks)
  • apps/dashboard/lib/trpc/routers/index.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • apps/dashboard/lib/trpc/routers/deploy/deployment/index.ts
  • apps/dashboard/lib/trpc/routers/deploy/deployment/buildLogs.ts
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-07-25T19:09:43.284Z
Learnt from: mcstepp
PR: unkeyed/unkey#3662
File: apps/dashboard/lib/trpc/routers/deployment/list.ts:11-11
Timestamp: 2025-07-25T19:09:43.284Z
Learning: In apps/dashboard/lib/trpc/routers/deployment/list.ts, the listDeployments procedure intentionally queries the versions table rather than a deployments table. The user mcstepp indicated that renaming the table would require a database migration, which was deferred for the current PR focused on UI features.

Applied to files:

  • apps/dashboard/lib/trpc/routers/index.ts
  • apps/dashboard/lib/trpc/routers/deploy/deployment/build-steps.ts
📚 Learning: 2025-07-25T19:11:00.208Z
Learnt from: mcstepp
PR: unkeyed/unkey#3662
File: apps/dashboard/lib/trpc/routers/deployment/getOpenApiDiff.ts:110-147
Timestamp: 2025-07-25T19:11:00.208Z
Learning: In apps/dashboard/lib/trpc/routers/deployment/getOpenApiDiff.ts, the user mcstepp prefers to keep mock data fallbacks in POC/demonstration code for simplicity, even if it wouldn't be production-ready. This aligns with the PR being work-in-progress for demonstration purposes.

Applied to files:

  • apps/dashboard/lib/trpc/routers/index.ts
🧬 Code graph analysis (4)
apps/dashboard/lib/trpc/routers/index.ts (1)
apps/dashboard/lib/trpc/routers/deploy/deployment/build-steps.ts (1)
  • getDeploymentBuildSteps (23-70)
apps/dashboard/lib/trpc/routers/deploy/deployment/build-steps.ts (2)
apps/dashboard/lib/trpc/trpc.ts (4)
  • t (8-8)
  • requireUser (10-21)
  • requireWorkspace (23-36)
  • withRatelimit (122-138)
apps/dashboard/lib/db.ts (1)
  • db (5-26)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (2)
apps/dashboard/providers/query-time-provider.tsx (1)
  • useQueryTime (74-80)
apps/dashboard/lib/trpc/server.ts (1)
  • trpc (7-14)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx (2)
apps/dashboard/app/(app)/projects/[projectId]/layout-provider.tsx (1)
  • useProjectLayout (13-19)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (1)
  • useDeploymentLogs (50-223)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Build / Build
  • GitHub Check: Test API / API Test Local
🔇 Additional comments (1)
apps/dashboard/lib/trpc/routers/index.ts (1)

40-41: No TRPC callers to buildLogs remain
Search returned only protobuf‐generated buildLogs fields (builder.pb.go/.ts); no deploy.deployment.buildLogs usage detected.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/filter-button.tsx (1)

30-32: Prevent badge overflow for larger counts

Fixed width can clip values like 1.2k/10k. Use min-width and padding.

-    <div className="rounded w-[22px] h-[18px] flex items-center justify-center text-[10px] leading-4 bg-gray-6 text-black dark:text-white">
+    <div className="rounded min-w-[22px] h-[18px] px-1 flex items-center justify-center text-[10px] leading-4 bg-gray-6 text-black dark:text-white">
       {count}
     </div>
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx (1)

249-252: Use stable keys for log rows

message-index keys cause unnecessary re-renders and incorrect DOM reuse. Prefer the log.id you already compute.

-                  {filteredLogs.map((log, index) => (
+                  {filteredLogs.map((log) => (
                     <div
-                      key={`${log.message}-${index}`}
+                      key={log.id}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88f8f4f and 0b3709a.

📒 Files selected for processing (3)
  • apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/filter-button.tsx (2 hunks)
  • apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (3 hunks)
  • apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx (3)
apps/dashboard/app/(app)/projects/[projectId]/layout-provider.tsx (1)
  • useProjectLayout (13-19)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (1)
  • useDeploymentLogs (51-224)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/filter-button.tsx (1)
  • FilterButton (13-34)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (3)
apps/dashboard/providers/query-time-provider.tsx (1)
  • useQueryTime (74-80)
apps/dashboard/lib/trpc/server.ts (1)
  • trpc (7-14)
apps/dashboard/app/(app)/projects/[projectId]/gateway-logs/constants.ts (1)
  • EXCLUDED_HOSTS (8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Build / Build
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Vercel Agent Review
🔇 Additional comments (9)
apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/filter-button.tsx (1)

7-7: Prop type update LGTM

Allowing number | string for count fits the formatted counts use-case.

apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/hooks/use-deployment-logs.tsx (5)

266-268: Confirm timestamp unit (ms vs s) to avoid wrong time display

If build/gateway timestamps are seconds, format(new Date(ts)) will render ~1970 or future dates. Ensure ts is in ms or multiply by 1000 at ingestion.

Would you like me to scan the TRPC types for buildSteps.logs.timestamp and logs.queryLogs.time to confirm units and add normalization at the mapping site?


156-160: Filter correctly by mode (don’t show build logs under warnings/errors in gateway mode)

Currently includes all build logs when “warnings”/“errors” are selected. Respect showBuildSteps.

-    if (logFilter === "warnings") {
-      filtered = logs.filter((log) => log.type === "build" || log.level === "warning");
-    } else if (logFilter === "errors") {
-      filtered = logs.filter((log) => log.type === "build" || log.level === "error");
-    }
+    if (logFilter === "warnings") {
+      filtered = showBuildSteps
+        ? logs.filter((log) => log.type === "build")
+        : logs.filter((log) => log.type === "gateway" && log.level === "warning");
+    } else if (logFilter === "errors") {
+      filtered = showBuildSteps
+        ? logs.filter((log) => log.type === "build")
+        : logs.filter((log) => log.type === "gateway" && log.level === "error");
+    }
@@
-  }, [logs, logFilter, searchTerm]);
+  }, [logs, logFilter, searchTerm, showBuildSteps]);

129-134: Keep the newest logs when trimming

Ascending sort + slice(0, MAX) discards newest entries. Retain the last N.

-        const sortedEntries = Array.from(newMap.entries())
-          .sort((a, b) => a[1].timestamp - b[1].timestamp)
-          .slice(0, MAX_STORED_LOGS);
+        const sortedEntries = Array.from(newMap.entries())
+          .sort((a, b) => a[1].timestamp - b[1].timestamp)
+          .slice(-MAX_STORED_LOGS);

59-62: Reset cached logs on mode switch to avoid cross-contamination

When switching from build steps to gateway logs, stale build entries remain until gateway data arrives. Clear cache on showBuildSteps change.

   const [storedLogs, setStoredLogs] = useState<Map<string, LogEntry>>(new Map());
   const scrollRef = useRef<HTMLDivElement>(null);
   const { queryTime: timestamp } = useQueryTime();
 
+  useEffect(() => {
+    setStoredLogs(new Map());
+  }, [showBuildSteps]);

71-88: Verify gateway logs time window
Confirm that passing identical startTime and endTime yields an empty range in the server logic; if so, remove both parameters and either rely solely on since or compute startTime as timestamp – since.

apps/dashboard/app/(app)/projects/[projectId]/details/active-deployment-card/index.tsx (3)

83-86: Good: clear UI split between build vs gateway

Deriving showBuildSteps from deployment.status keeps the component stateless regarding source selection.


190-206: Counts formatting integration LGTM

Using formatNumber aligns with the prop change to allow string counts and improves readability.


266-269: Verify timestamp unit before formatting

Ensure log.timestamp is ms. If seconds, multiply by 1000 here or normalize in the hook.

If needed, I can update the hook’s mappers to standardize to ms for both sources and add unit tests.

Copy link
Contributor

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b3709a and b3ed35a.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/projects/[projectId]/gateway-logs/components/table/utils/get-row-class.ts (1 hunks)
  • go/demo_api/main.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/dashboard/app/(app)/projects/[projectId]/gateway-logs/components/table/utils/get-row-class.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Build / Build
  • GitHub Check: Vercel Agent Review
  • GitHub Check: Analyze (javascript-typescript)

@chronark
Copy link
Collaborator

The gateway logs on the main page should be in reverse order
everywhere except here we're showing the latest at the top

CleanShot 2025-09-25 at 14 06 31@2x

looks nice otherwise
@ogzhanolguncu

@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2025
18 tasks
@ogzhanolguncu
Copy link
Contributor Author

@chronark done

@chronark chronark merged commit ee34d90 into main Sep 25, 2025
18 checks passed
@chronark chronark deleted the project-details-logs branch September 25, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants