Troubleshooting
Common issues and how to debug them in production.
Logs not appearing in Loki
1. Check Loki readiness
- Verify Loki is reachable:
curl -f http://localhost:3100/ready- If you see warnings like:
Loki not reachable at http://loki:3100 — logs will be dropped until Loki is available
in your service logs, confirm:
lokiHostis correct for the environment.- Network rules allow connections from your service to Loki.
2. Confirm labels and queries
In Grafana’s Explore view:
- Use a simple LogQL query first:
{app="backend"} | json- If nothing appears:
- Check that
serviceNameinLokiLoggerModule.registermatchesappin your dashboards and queries. - Confirm retention (30 days by default in the provided config) has not expired.
- Check that
No trace IDs on logs
If logs appear but lack traceId/spanId:
- Ensure
LokiLoggerModule.apply(app)is called exactly once inmain.ts. - Confirm that your HTTP requests are routed through the Express adapter used by Nest (no custom server bypassing the middleware).
- Verify that your logs are emitted inside a request scope:
- Logs from background jobs or cron tasks do not have a request
TraceContextand therefore will not havetraceId/spanIdunless you create one explicitly.
- Logs from background jobs or cron tasks do not have a request
Frontend not linked to backend traces
Symptoms:
- Frontend requests do not show up in the same trace as backend logs.
x-loki-trace-idheader missing from requests.
Checklist:
attachSessionInterceptoris attached to the same Axios instance used for API calls.- The backend exposes headers via CORS:
app.enableCors({
exposedHeaders: ["x-loki-trace-id", "x-parent-span-id"],
});- Gateway and downstream services use the same
traceHeaderandparentSpanHeadersettings. - Browser devtools → Network → Request headers show
x-loki-trace-idpresent.
Trace viewer returns “Trace not found”
The / _trace /api/:traceId endpoint can return 404 when:
- The trace is older than Loki retention.
- No logs exist for that trace ID (typo or service not using the logger yet).
traceViewerServicesis misconfigured and does not include all relevant services.
Steps:
- Confirm the ID exists in Loki with:
{app="backend"} | json | traceId="<TRACE_ID>"- Update
traceViewerServicesto include all services for the journey:
traceViewerServices: 'backend,auth-service,customer-support',/metrics endpoint not found
If Prometheus reports 404 scraping /metrics:
- Verify
enableMetrics: trueinLokiLoggerModule.register. - Check that the
metricsPathmatches what Prometheus is scraping:- Default path is
/metrics. - In Docker,
prometheus.ymlusesmetrics_path: '/metrics'.
- Default path is
High log volume or Loki performance issues
If Loki queries become slow or return “exceeded max entries”, you can:
- Tighten log level (
logLevel: 'info'or'warn'in production). - Disable noisy logs (e.g. avoid
@Log({ args: true })on very hot paths). - Adjust Loki configuration:
max_entries_limit_per_querysplit_queries_by_interval- Retention and compaction settings.
Use the provided Grafana dashboards (e.g. per‑service log volume and query performance) to identify heavy services and endpoints.
Need help or want to support the project? Visit Support us.
Last updated on