Production
Advanced

Production Observability and Security

Instrument a Next.js app so production failures are debuggable, measurable, and recoverable.

40 min
2 sections
observability
security
opentelemetry
incident-response
1
2

01. Trace the business workflow

Section 1 of 2

Logs and traces should follow the user workflow across Server Components, Server Actions, Route Handlers, queues, and external APIs. Include request ID, tenant ID, actor ID, resource ID, and operation name, but never secrets or raw tokens.

typescript
// instrumentation.ts
export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await import("./instrumentation-node");
  }
}

// Example trace attributes for a ticket assignment
{
  "request.id": "req_01J...",
  "tenant.id": "org_123",
  "actor.id": "user_456",
  "operation": "ticket.assign",
  "ticket.id": "tick_789"
}
Back to Course