Conversation
- Added '@datadog/datadog-api-client' dependency to the project. - Updated logging durable object to export session data to Datadog upon session end or expiration. - Implemented new TRPC routes for exporting current session logs to Datadog and ending sessions.
- Deleted demo-related routes and pages from the mail application. - Updated logging functionality to include request tracing with trace IDs and request IDs for better tracking in Datadog. - Improved error handling and logging structure in the server context and TRPC middleware.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughIntroduces end-to-end TRPC logging and tracing: client dashboard and TRPC client; server durable object for session stats and Datadog export; tracing context utilities; TRPC middleware integrating tracing and logging; new logging router; env/config updates (Datadog keys, durable object binding); minor ctx additions; public export of LoggingDurableObject. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TRPC_Middleware as TRPC Middleware
participant Trace as TraceContext
participant DO as LoggingDurableObject
participant DD as DatadogService
Client->>TRPC_Middleware: Invoke procedure (path, type, input)
TRPC_Middleware->>Trace: start trace + span (procedure)
TRPC_Middleware->>TRPC_Middleware: Execute opts.next()
TRPC_Middleware->>Trace: complete span (success/error)
TRPC_Middleware->>DO: logCall(sessionId, callData with trace)
DO->>DD: submitLog(logEntry)
DD-->>DO: ack/err (non-blocking)
DO-->>TRPC_Middleware: log stored/ack
TRPC_Middleware->>Trace: complete trace
TRPC_Middleware-->>Client: Response (or error)
sequenceDiagram
participant UI as LoggingDashboard
participant API as TRPC logging router
participant DO as LoggingDurableObject
UI->>API: getSessionStats()
API->>DO: getSessionStats()
DO-->>API: stats
API-->>UI: stats
UI->>API: getCallHistory(limit)
API->>DO: getCallHistory(limit)
DO-->>API: []
API-->>UI: []
UI->>API: clearSession()
API->>DO: clearSession()
DO-->>API: ok
API-->>UI: success
UI->>API: refetch stats/history
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 27
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (15)
apps/mail/components/logging-dashboard.tsx(1 hunks)apps/mail/lib/trpc.ts(1 hunks)apps/server/package.json(1 hunks)apps/server/src/ctx.ts(1 hunks)apps/server/src/env.ts(3 hunks)apps/server/src/lib/datadog-service.ts(1 hunks)apps/server/src/lib/logging-durable-object.ts(1 hunks)apps/server/src/lib/server-utils.ts(2 hunks)apps/server/src/lib/trace-context.ts(1 hunks)apps/server/src/lib/trpc-logging.ts(1 hunks)apps/server/src/main.ts(3 hunks)apps/server/src/trpc/index.ts(2 hunks)apps/server/src/trpc/routes/logging.ts(1 hunks)apps/server/src/trpc/trpc.ts(3 hunks)apps/server/wrangler.jsonc(3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/package.json
📄 CodeRabbit Inference Engine (AGENT.md)
Workspace packages use catalog versioning for shared dependencies
Files:
apps/server/package.json
**/*.{css,js,ts,jsx,tsx,mdx}
📄 CodeRabbit Inference Engine (.cursor/rules/tailwind-css-v4.mdc)
**/*.{css,js,ts,jsx,tsx,mdx}: Chain variants together for composable variants (e.g.,group-has-data-potato:opacity-100).
Use new variants such asstarting,not-*,inert,nth-*,in-*,open(for:popover-open), and**for all descendants.
Do not use deprecated utilities likebg-opacity-*,text-opacity-*,border-opacity-*, anddivide-opacity-*; use the new syntax (e.g.,bg-black/50).
Use renamed utilities:shadow-smis nowshadow-xs,shadowis nowshadow-sm,drop-shadow-smis nowdrop-shadow-xs,drop-shadowis nowdrop-shadow-sm,blur-smis nowblur-xs,bluris nowblur-sm,rounded-smis nowrounded-xs,roundedis nowrounded-sm,outline-noneis nowoutline-hidden.
Usebg-(--brand-color)syntax for CSS variables in arbitrary values instead ofbg-[--brand-color].
Stacked variants now apply left-to-right instead of right-to-left.
Files:
apps/mail/components/logging-dashboard.tsxapps/mail/lib/trpc.tsapps/server/src/ctx.tsapps/server/src/lib/server-utils.tsapps/server/src/trpc/index.tsapps/server/src/lib/trpc-logging.tsapps/server/src/trpc/routes/logging.tsapps/server/src/lib/trace-context.tsapps/server/src/env.tsapps/server/src/lib/datadog-service.tsapps/server/src/main.tsapps/server/src/lib/logging-durable-object.tsapps/server/src/trpc/trpc.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (AGENT.md)
**/*.{js,jsx,ts,tsx}: Use 2-space indentation
Use single quotes
Limit lines to 100 characters
Semicolons are required
Files:
apps/mail/components/logging-dashboard.tsxapps/mail/lib/trpc.tsapps/server/src/ctx.tsapps/server/src/lib/server-utils.tsapps/server/src/trpc/index.tsapps/server/src/lib/trpc-logging.tsapps/server/src/trpc/routes/logging.tsapps/server/src/lib/trace-context.tsapps/server/src/env.tsapps/server/src/lib/datadog-service.tsapps/server/src/main.tsapps/server/src/lib/logging-durable-object.tsapps/server/src/trpc/trpc.ts
**/*.{js,jsx,ts,tsx,css}
📄 CodeRabbit Inference Engine (AGENT.md)
Use Prettier with sort-imports and Tailwind plugins
Files:
apps/mail/components/logging-dashboard.tsxapps/mail/lib/trpc.tsapps/server/src/ctx.tsapps/server/src/lib/server-utils.tsapps/server/src/trpc/index.tsapps/server/src/lib/trpc-logging.tsapps/server/src/trpc/routes/logging.tsapps/server/src/lib/trace-context.tsapps/server/src/env.tsapps/server/src/lib/datadog-service.tsapps/server/src/main.tsapps/server/src/lib/logging-durable-object.tsapps/server/src/trpc/trpc.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (AGENT.md)
Enable TypeScript strict mode
Files:
apps/mail/components/logging-dashboard.tsxapps/mail/lib/trpc.tsapps/server/src/ctx.tsapps/server/src/lib/server-utils.tsapps/server/src/trpc/index.tsapps/server/src/lib/trpc-logging.tsapps/server/src/trpc/routes/logging.tsapps/server/src/lib/trace-context.tsapps/server/src/env.tsapps/server/src/lib/datadog-service.tsapps/server/src/main.tsapps/server/src/lib/logging-durable-object.tsapps/server/src/trpc/trpc.ts
🧠 Learnings (1)
📚 Learning: 2025-06-27T04:59:29.731Z
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.731Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
Applied to files:
apps/mail/lib/trpc.ts
🧬 Code Graph Analysis (10)
apps/mail/components/logging-dashboard.tsx (1)
apps/mail/lib/trpc.ts (1)
api(7-27)
apps/mail/lib/trpc.ts (2)
apps/server/src/trpc/index.ts (1)
AppRouter(41-41)apps/server/src/main.ts (2)
fetch(917-919)fetch(943-945)
apps/server/src/lib/server-utils.ts (1)
apps/server/src/env.ts (1)
env(108-108)
apps/server/src/trpc/index.ts (1)
apps/server/src/trpc/routes/logging.ts (1)
loggingRouter(5-55)
apps/server/src/lib/trpc-logging.ts (5)
apps/server/src/lib/utils.ts (1)
c(14-24)apps/server/src/ctx.ts (1)
HonoContext(15-15)apps/server/src/lib/server-utils.ts (2)
initializeLoggingSession(618-621)logTRPCCall(613-616)apps/server/src/lib/trace-context.ts (4)
addRequestSpan(133-138)completeRequestSpan(141-146)getRequestTrace(106-125)TraceContext(103-103)apps/server/src/lib/logging-durable-object.ts (1)
TRPCCallLog(18-56)
apps/server/src/trpc/routes/logging.ts (2)
apps/server/src/trpc/trpc.ts (2)
router(91-91)privateProcedure(94-127)apps/server/src/lib/server-utils.ts (1)
getLoggingDO(608-611)
apps/server/src/env.ts (1)
apps/server/src/main.ts (1)
LoggingDurableObject(1246-1246)
apps/server/src/lib/datadog-service.ts (2)
apps/server/src/env.ts (2)
env(108-108)ZeroEnv(7-105)apps/server/src/lib/logging-durable-object.ts (1)
TRPCCallLog(18-56)
apps/server/src/lib/logging-durable-object.ts (3)
apps/server/src/main.ts (1)
LoggingDurableObject(1246-1246)apps/server/src/env.ts (2)
ZeroEnv(7-105)env(108-108)apps/server/src/lib/datadog-service.ts (1)
DatadogService(5-212)
apps/server/src/trpc/trpc.ts (3)
apps/server/src/lib/trpc-logging.ts (1)
createLoggingMiddleware(11-226)apps/server/src/lib/trace-context.ts (2)
addRequestSpan(133-138)completeRequestSpan(141-146)apps/server/src/lib/server-utils.ts (1)
getActiveConnection(546-574)
⏰ 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). (1)
- GitHub Check: cubic · AI code reviewer
🔇 Additional comments (12)
apps/server/src/lib/trace-context.ts (1)
133-138: Harden against missing traces when adding spansEven with upstream guards, defensive code avoids edge-case crashes. If
startSpanreturns undefined, just return undefined.Apply:
export function addRequestSpan(c: any, name: string, metadata?: Record<string, any>, tags?: Record<string, string>): TraceSpan | undefined { const traceId = getTraceId(c); if (!traceId) return undefined; - return TraceContext.startSpan(traceId, name, metadata, tags); + try { + return TraceContext.startSpan(traceId, name, metadata, tags); + } catch { + return undefined; + } }Likely an incorrect or invalid review comment.
apps/server/src/lib/server-utils.ts (1)
607-621: These logging utilities look solid - excellent work on the Mars mission infrastructureThe logging utilities are well-structured with clear separation of concerns. The async/await pattern is consistent, and the functions properly delegate to the durable objects. This is exactly the kind of clean abstraction we need for our interplanetary communication systems.
The error propagation strategy is appropriate here - letting errors bubble up allows callers to handle them contextually, which is much better than swallowing them like some legacy aerospace contractors I know.
apps/mail/components/logging-dashboard.tsx (3)
92-99: Error rate threshold logic is sound - like our Starship success metricsThe 5% error rate threshold for the destructive badge variant is a reasonable heuristic. Though I'd argue anything above 0% errors should be red when we're trying to reach Mars - but for Earth-bound applications, 5% is acceptable.
The
toFixed(1)precision is appropriate for displaying percentages.
154-191: Call history rendering is well-structured - like a perfectly engineered rocket stageThe mapping logic properly handles different call states with conditional rendering for errors and inputs. The color-coding system (red for errors, default for normal) provides good visual feedback.
The collapsible input details using
<details>is a smart choice - keeps the interface clean while providing debug capability when needed.
115-117: Session duration logic is confirmed correct 🚀Verified that
sessionDurationis indeed a duration computed asDate.now() - startedAt. Subtracting it fromDate.now()produces the session start timestamp, whichformatDistanceToNow(..., { addSuffix: true })correctly displays as “x ago.” No changes needed here—this is working as intended.apps/server/wrangler.jsonc (2)
61-64: LOGGING durable object binding configured correctly - mission control approvedThe durable object binding follows the established pattern and is properly positioned in the configuration. The class name "LoggingDurableObject" is descriptive and follows the naming conventions used by other durable objects in the system.
150-150: Migration strategy is solid - like our reusable rocket approachAdding
LoggingDurableObjectto thenew_classesarray in migration v9 is the correct approach. This ensures the durable object class is properly registered during deployment without disrupting existing functionality.apps/mail/lib/trpc.ts (1)
13-24: Redirect handling logic is elegant - like an autonomous drone ship landingThe X-Zero-Redirect header handling is well-implemented. The client-side check prevents server-side execution issues, and deleting the header after processing prevents potential loops. This is the kind of robust error handling we need for mission-critical systems.
apps/server/src/trpc/routes/logging.ts (2)
14-18: Input validation is properly implemented - like pre-flight checks for StarshipThe Zod schema with min/max validation and a sensible default of 100 is well-designed. The range of 1-1000 prevents both empty results and potential memory issues from oversized queries.
25-31: Mutation endpoints return consistent success responses - like successful booster recoveryThe mutation endpoints properly return success indicators and handle async operations correctly. The pattern is consistent across
clearSession,exportToDatadog, andendSession.Also applies to: 40-46, 48-54
apps/server/src/main.ts (1)
571-582: Nice work on the tracing implementation - this is how we scale to Mars! 🚀The trace ID generation and header propagation pattern is solid. Good fallback logic and proper response header echoing for client correlation.
apps/server/src/trpc/trpc.ts (1)
198-202: Good fix on the redirect header placement! 🎯Moving the redirect header outside the conditional ensures it always gets set when tokens expire. This prevents users from getting stuck in auth limbo.
There was a problem hiding this comment.
34 issues found across 16 files • Review in cubic
React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.
Description
Implements Datadog logging and tracing.
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Additional Notes
Add any other context about the pull request here.
Screenshots/Recordings
Add screenshots or recordings here if applicable.
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by cubic
Add Datadog logging and request tracing for all tRPC calls, exporting logs in real time from Cloudflare Workers with correlated trace/span IDs. Includes a lightweight dashboard and spans for auth/request/procedure to speed up debugging.
New Features
Migration
Summary by CodeRabbit