Skip to content

Logging and Monitoring Setup in Cursor

It is 2 AM and your pager goes off. The alert says “high error rate on orders API.” You open your monitoring dashboard and see a spike in 500 errors, but the logs just say “Internal Server Error” with no stack trace, no request ID, no context about which endpoint or which user was affected. You SSH into the production server, tail the logs, and find thousands of lines of unstructured text mixed with debug output that someone forgot to remove. Thirty minutes in, you still do not know what is broken.

This is the cost of skipping observability. Structured logging, application metrics, and distributed tracing are the difference between a 5-minute diagnosis and a 2-hour scramble. Cursor Agent can generate your entire observability stack because the patterns are well-defined: structured loggers, metric collectors, trace propagation, and alert rules all follow standard schemas that the AI generates reliably.

  • A structured logging setup with correlation IDs and request context
  • Application metrics collection with Prometheus-compatible instrumentation
  • Distributed tracing configuration for multi-service architectures
  • Alert rules that trigger on meaningful conditions, not noise
  • Copy-paste prompts for generating each observability layer

The foundation of observability is structured logging. Every log line should be machine-parseable JSON with consistent fields, so you can search, filter, and aggregate across your entire system.

After generation, verify that the logger produces the right output:

Test the logger by pasting this into Agent mode:
"Write a quick test that imports our logger, creates a child logger
with user_id context, logs an info message and an error with a stack trace.
Show me what the JSON output looks like for both development and production modes."

The most valuable logging improvement is adding business context. When you can search for all logs related to order ord_abc123, debugging becomes dramatically faster.

Metrics tell you what is happening across your system in aggregate. While logs show individual events, metrics show trends: request rates, error rates, latency distributions, and resource utilization.

For microservices architectures, distributed tracing connects a single user request across multiple services. A trace shows the complete journey: API gateway to auth service to orders service to payment service and back.

Metrics and traces are useless if nobody looks at them. Alerts bridge the gap between data collection and incident response. The key is alerting on symptoms (user-facing impact), not causes (high CPU).

Once you have metrics and traces, you need dashboards to visualize them. Cursor can generate dashboard configurations:

Logs are too verbose in production. If Agent generates debug-level logging everywhere, your log storage costs will spike. Set the default log level to info in production and debug only in development. Use the LOG_LEVEL environment variable to change it without redeploying.

Metrics have too many label combinations (cardinality explosion). If Agent uses user_id or request_id as a metric label, you will create millions of time series and your metrics storage will crash. Metric labels should be low-cardinality: HTTP method, status code, endpoint pattern (not the full URL with path parameters). Review every metric label Agent generates.

Traces are incomplete. If only some services have tracing configured, traces will have gaps. The trace context (traceparent header) must be propagated through every service in the request path. Ask Agent: “Verify that every outgoing HTTP call in our service includes the W3C traceparent header from the current trace context.”

Alerts fire too often (alert fatigue). Start with higher thresholds and only tighten them after you have baseline data. For new deployments, use “recording rules” to compute baselines for a week before enabling alerts.

Correlation IDs are missing. If your logs do not have correlation IDs, you cannot trace a request across services. The middleware from the first prompt generates request IDs, but you also need to propagate them in outgoing requests. Ask Agent: “Update our HTTP client to include the x-correlation-id header from async local storage in every outgoing request.”