Files
superlist/docs/openobserve-dashboard.json
Jose Selesan dd9cf4ce43 feat(api): ship logs and HTTP metrics to OpenObserve
Replace Pino with LogTape and add OpenTelemetry metrics, both pushed to
OpenObserve over OTLP/HTTP when OPENOBSERVE_URL is set (console only otherwise).

- lib/logger.ts: console sink (pretty in dev, JSON lines in production) plus an
  OpenObserve sink via @logtape/otel. Each request runs inside
  withContext({ requestId }), so every record logged during it carries the id.
- The request middleware logs method, path, route pattern, status, durationMs,
  userId and user agent, at error/warning/info by status (/api/health at debug).
- lib/metrics.ts: http.server.request.duration (histogram, 5 ms to 10 s) and
  http.server.active_requests, attributed by method, route pattern and status,
  exported every METRICS_EXPORT_INTERVAL_MS (15 s).
- lib/openobserve.ts holds the shared endpoint and Basic auth settings; logs and
  metrics are flushed on SIGINT/SIGTERM.
- docs/openobserve-dashboard.md explains the dashboard and its queries, and
  docs/openobserve-dashboard.json can be imported as is.
- New variables are declared in turbo.json, the .env examples and the compose.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 11:59:17 -03:00

556 lines
17 KiB
JSON

{
"version": 8,
"title": "Superlist API",
"description": "Métricas HTTP de la API (OTLP) y requests lentos (logs)",
"role": "",
"owner": "",
"created": "1970-01-01T00:00:00Z",
"dashboardId": "",
"defaultDatetimeDuration": {
"type": "relative",
"relativeTimePeriod": "1h",
"startTime": null,
"endTime": null
},
"variables": {
"list": [],
"showDynamicFilters": false
},
"tabs": [
{
"tabId": "default",
"name": "Default",
"panels": [
{
"id": "Panel_rps",
"type": "line",
"title": "Requests por segundo por ruta",
"description": "Sin /api/health",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "default",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "sum by (http_route) (rate(http_server_request_duration_count{service_name=\"superlist-api\", http_route!=\"/api/health\"}[5m]))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_count",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "{http_route}",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 0,
"y": 0,
"w": 24,
"h": 9,
"i": 1
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_latency",
"type": "line",
"title": "Latencia p50 / p95 / p99",
"description": "Percentiles interpolados en buckets de 5 ms a 10 s",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "seconds",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "histogram_quantile(0.5, sum by (le) (rate(http_server_request_duration_bucket{http_route!=\"/api/health\"}[5m])))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_bucket",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "p50",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
},
{
"query": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_bucket{http_route!=\"/api/health\"}[5m])))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_bucket",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "p95",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
},
{
"query": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_bucket{http_route!=\"/api/health\"}[5m])))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_bucket",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "p99",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 24,
"y": 0,
"w": 24,
"h": 9,
"i": 2
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_errors",
"type": "metric",
"title": "Tasa de error 5xx",
"description": "Porcentaje de requests con status 5xx (vacío = 0 %)",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "percent",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "0",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "100 * sum(rate(http_server_request_duration_count{http_response_status_code=~\"5..\"}[5m])) / sum(rate(http_server_request_duration_count[5m]))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_count",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "5xx %",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 0,
"y": 9,
"w": 12,
"h": 9,
"i": 3
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_active",
"type": "metric",
"title": "Requests en curso",
"description": "SSE no cuenta: responde enseguida",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "default",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "0",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "sum(http_server_active_requests)",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_active_requests",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "en curso",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 12,
"y": 9,
"w": 12,
"h": 9,
"i": 4
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_status",
"type": "stacked",
"title": "Requests por status",
"description": "Requests/s por código de respuesta (sin /api/health)",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "default",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "sum by (http_response_status_code) (rate(http_server_request_duration_count{http_route!=\"/api/health\"}[5m]))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_count",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "{http_response_status_code}",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 24,
"y": 9,
"w": 24,
"h": 9,
"i": 5
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_p95_route",
"type": "line",
"title": "p95 por ruta",
"description": "Para encontrar el endpoint lento",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "seconds",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "histogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_bucket{http_route!=\"/api/health\"}[5m])))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_bucket",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "{http_route}",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 0,
"y": 18,
"w": 24,
"h": 9,
"i": 6
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_avg_route",
"type": "line",
"title": "Latencia media por ruta",
"description": "sum / count de la duración",
"config": {
"show_legends": true,
"legends_position": null,
"unit": "seconds",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "",
"mark_line": [],
"override_config": []
},
"queryType": "promql",
"queries": [
{
"query": "sum by (http_route) (rate(http_server_request_duration_sum{http_route!=\"/api/health\"}[5m])) / sum by (http_route) (rate(http_server_request_duration_count{http_route!=\"/api/health\"}[5m]))",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "http_server_request_duration_sum",
"stream_type": "metrics",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "{http_route}",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 24,
"y": 18,
"w": 24,
"h": 9,
"i": 7
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
},
{
"id": "Panel_slowest",
"type": "table",
"title": "Requests más lentos",
"description": "Desde los logs: usa requestid en Logs para ver el detalle",
"config": {
"show_legends": false,
"legends_position": null,
"unit": "default",
"decimals": 2,
"axis_border_show": false,
"line_thickness": 1.5,
"connect_nulls": false,
"no_value_replacement": "",
"mark_line": [],
"override_config": []
},
"queryType": "sql",
"queries": [
{
"query": "SELECT _timestamp, method, path, status, durationms, requestid FROM \"superlist\" WHERE durationms IS NOT NULL AND path != '/api/health' ORDER BY durationms DESC LIMIT 20",
"vrlFunctionQuery": "",
"customQuery": true,
"joins": [],
"fields": {
"stream": "superlist",
"stream_type": "logs",
"x": [],
"y": [],
"z": [],
"breakdown": [],
"filter": {
"filterType": "group",
"logicalOperator": "AND",
"conditions": []
}
},
"config": {
"promql_legend": "",
"layer_type": "scatter",
"weight_fixed": 1,
"limit": 0,
"min": 0,
"max": 100,
"time_shift": []
}
}
],
"layout": {
"x": 0,
"y": 27,
"w": 48,
"h": 12,
"i": 8
},
"htmlContent": "",
"markdownContent": "",
"customChartContent": ""
}
]
}
]
}