Debugging Next.js Best Practices: Logs and Tracing
Next.js gives you static pages, cached components, and dynamic renders — each shows up differently in your observability tooling. This session teaches you what to expect from each, how to query it, and when to alert on it.
Modules
1 The App & Decision Framework
Tour the app and its four route types: static, cached, dynamic, and user-specific. Learn when to reach for a metric, a log, or a span.
- Metric → counting and alerting (page.view by route type)
- Log → investigating a specific event (auth.login with context)
- Span → timing within a request (db.query, cache lookup)
- What Sentry and Vercel already capture for you
2 Structured Logs
Query wide events in Sentry Logs. Each log packs one operation’s full context — user, result, duration — so you can filter by any dimension and click through to its trace.
- auth.login — filter by result, group by user
- schedule.add — find the most popular talks
- cache.miss — which cache key, which path
- Log → trace: click any log to see the full request
3 Traces Across Route Types
Compare trace waterfalls across the four rendering strategies. See what server work each generates — from zero spans on a static page to full DB queries on a dynamic one.
- Static (/workshop): render only, no DB, no cache
- Cached hit (/): suspense-cache lookup, no DB
- Cached miss (/): db.query spans + cache write-back
- Dynamic (/my-schedule): auth + DB every request
4 Metrics & Dashboards
Build a dashboard from the command line with the Sentry CLI. Group page views by route type, track cache miss rates, and visualize auth patterns.
- sentry dashboard create + widget add
- page.view grouped by route_type and path
- cache.miss rate vs total page views
- Sentry MCP server for natural language queries
5 Alerts
Create a monitor on login failures from the Sentry UI. Review the framework: metrics for counting, logs for context, traces for timing.
- Log-based monitor: auth failures > threshold
- Metric-based monitor: cache miss rate spike
- Each signal has one job — don’t make one do another’s
Prerequisites
- Completed 101 workshop
- Sentry account with a Next.js project
- Sentry CLI installed
Tools
Sentry CLI
Create dashboards, query logs, and view traces from the terminal.
Sentry MCP Server
Query Sentry data with natural language through your AI editor.
Monitors & Alerts
Threshold-based monitors on logs and metrics with Slack/PagerDuty/email actions.
FAQs
tracePropagationTargets inside the Sentry.init inside instrumentation-client.ts
![[Workshop] Building and Monitoring AI Agents and MCP servers](/_astro/building-mcp-servers-workshop-1280x720__1_-min.B4DlFij4.jpg)
