Monitoring & Metrics
Wisp.place includes built-in observability with automatic Grafana integration for logs and metrics. Monitor request performance, track errors, and analyze usage patterns across both the main backend and hosting service.
Quick Start
Section titled “Quick Start”Set environment variables to enable Grafana export:
# Grafana CloudGRAFANA_LOKI_URL=https://logs-prod-xxx.grafana.netGRAFANA_LOKI_TOKEN=glc_xxx
GRAFANA_PROMETHEUS_URL=https://prometheus-prod-xxx.grafana.net/api/promGRAFANA_PROMETHEUS_TOKEN=glc_xxx
# Self-hosted GrafanaGRAFANA_LOKI_USERNAME=your-usernameGRAFANA_LOKI_PASSWORD=your-passwordRestart services. Metrics and logs now flow to Grafana automatically.
Metrics Collected
Section titled “Metrics Collected”HTTP Requests
Section titled “HTTP Requests”http_requests_total- Total request count by path, method, statushttp_request_duration_ms- Request duration histogramerrors_total- Error count by service
Performance Stats
Section titled “Performance Stats”- P50, P95, P99 response times
- Requests per minute
- Error rates
- Average duration by endpoint
Log Aggregation
Section titled “Log Aggregation”Logs are sent to Loki with automatic categorization:
{job="main-app"} |= "error" # OAuth and upload errors{job="hosting-service"} |= "cache" # Cache operations{service="hosting-service", level="warn"} # Warnings onlyService Identification
Section titled “Service Identification”Each service is tagged separately:
main-app- OAuth, uploads, domain managementhosting-service- Firehose, caching, content serving
Configuration Options
Section titled “Configuration Options”Environment Variables
Section titled “Environment Variables”# RequiredGRAFANA_LOKI_URL # Loki endpointGRAFANA_PROMETHEUS_URL # Prometheus endpoint (add /api/prom for OTLP)
# Authentication (use one)GRAFANA_LOKI_TOKEN # Bearer token (Grafana Cloud)GRAFANA_LOKI_USERNAME # Basic auth (self-hosted)GRAFANA_LOKI_PASSWORD
# OptionalGRAFANA_BATCH_SIZE=100 # Batch size before flushGRAFANA_FLUSH_INTERVAL=5000 # Flush interval in msProgrammatic Setup
Section titled “Programmatic Setup”import { initializeGrafanaExporters } from '@wisp/observability'
initializeGrafanaExporters({ lokiUrl: 'https://logs.grafana.net', lokiAuth: { bearerToken: 'token' }, prometheusUrl: 'https://prometheus.grafana.net/api/prom', prometheusAuth: { bearerToken: 'token' }, serviceName: 'my-service', batchSize: 100, flushIntervalMs: 5000})Grafana Dashboard Queries
Section titled “Grafana Dashboard Queries”Request Performance
Section titled “Request Performance”# Average response time by endpointavg by (path) ( rate(http_request_duration_ms_sum[5m]) / rate(http_request_duration_ms_count[5m]))
# Request ratesum(rate(http_requests_total[1m])) by (service)
# Error ratesum(rate(errors_total[5m])) by (service) /sum(rate(http_requests_total[5m])) by (service)Log Analysis
Section titled “Log Analysis”# Recent errors{job="main-app"} |= "error" | json
# Slow requests (>1s){job="hosting-service"} |~ "duration.*[1-9][0-9]{3,}"
# Failed OAuth attempts{job="main-app"} |= "OAuth" |= "failed"Troubleshooting
Section titled “Troubleshooting”Logs not appearing
Section titled “Logs not appearing”- Check
GRAFANA_LOKI_URLis correct (no trailing/loki/api/v1/push) - Verify authentication token/credentials
- Look for connection errors in service logs
Metrics missing
Section titled “Metrics missing”- Ensure
GRAFANA_PROMETHEUS_URLincludes/api/promsuffix - Check firewall rules allow outbound HTTPS
- Verify OpenTelemetry export errors in logs
High memory usage
Section titled “High memory usage”- Reduce
GRAFANA_BATCH_SIZE(default: 100) - Lower
GRAFANA_FLUSH_INTERVALto flush more frequently
Local Development
Section titled “Local Development”Metrics and logs are stored in-memory when Grafana isn’t configured. Access them via:
http://localhost:8000/api/observability/logshttp://localhost:8000/api/observability/metricshttp://localhost:8000/api/observability/errors
Testing Integration
Section titled “Testing Integration”Run integration tests to verify setup:
cd packages/@wisp/observabilitybun test src/integration-test.test.ts
# Test with live GrafanaGRAFANA_LOKI_URL=... GRAFANA_LOKI_USERNAME=... GRAFANA_LOKI_PASSWORD=... \bun test src/integration-test.test.ts