Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions infra/grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM grafana/grafana:11.1.4
FROM grafana/grafana:11.1.4

# Copy provisioning configs
COPY provisioning /etc/grafana/provisioning
11 changes: 11 additions & 0 deletions infra/grafana/provisioning/dashboards/dashboards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: "default"
orgId: 1
folder: ""
type: file
disableDeletion: false
updateIntervalSeconds: 30
options:
path: /etc/grafana/provisioning/dashboards
71 changes: 71 additions & 0 deletions infra/grafana/provisioning/dashboards/nodejs-dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"id": null,
"title": "Node.js App Observability",
"tags": ["nodejs", "prometheus"],
"timezone": "browser",
"schemaVersion": 36,
"version": 1,
"refresh": "10s",
"panels": [
{
"type": "graph",
"title": "CPU Usage (%)",
"targets": [
{
"expr": "process_cpu_user_seconds_total",
"legendFormat": "CPU User Time",
"refId": "A"
}
],
"id": 1
},
{
"type": "graph",
"title": "Memory Usage (MB)",
"targets": [
{
"expr": "process_resident_memory_bytes / 1024 / 1024",
"legendFormat": "Resident Memory",
"refId": "A"
}
],
"id": 2
},
{
"type": "graph",
"title": "HTTP Requests per Second",
"targets": [
{
"expr": "rate(http_requests_total[1m])",
"legendFormat": "{{method}} {{route}}",
"refId": "A"
}
],
"id": 3
},
{
"type": "graph",
"title": "Error Rate (5xx per Second)",
"targets": [
{
"expr": "rate(http_requests_total{status=~\"5..\"}[5m])",
"legendFormat": "Errors (5xx)",
"refId": "A"
}
],
"id": 4
},
{
"type": "graph",
"title": "95th Percentile Latency",
"targets": [
{
"expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))",
"legendFormat": "p95 latency",
"refId": "A"
}
],
"id": 5
}
]
}
8 changes: 8 additions & 0 deletions infra/grafana/provisioning/datasources/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: 1

datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
6 changes: 6 additions & 0 deletions infra/prometheus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM prom/prometheus:v2.53.0

# Copy custom config
COPY prometheus.yml /etc/prometheus/prometheus.yml
# force rebuild
ARG CACHEBUST=1
12 changes: 12 additions & 0 deletions infra/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: "mydev"
metrics_path: /metrics
scheme: https # Render apps use HTTPS
static_configs:
- targets:
- "mydev-staging.onrender.com"
- "mydev-prod.onrender.com"
40 changes: 39 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"dependencies": {
"@sentry/node": "^7.120.4",
"@sentry/tracing": "^7.120.4",
"express": "^4.21.2"
"express": "^4.21.2",
"prom-client": "^15.1.3"
},
"devDependencies": {
"eslint": "^8.57.1",
Expand Down
22 changes: 22 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,25 @@ services:
value: 10000
- key: SENTRY_DSN
sync: false

- type: web
name: prometheus
env: docker
plan: free
rootDir: ./infra/prometheus
dockerfilePath: Dockerfile
autoDeploy: false
envVars:
- key: PORT
value: 9090

- type: web
name: grafana
env: docker
plan: free
rootDir: ./infra/grafana
dockerfilePath: Dockerfile
autoDeploy: false
envVars:
- key: PORT
value: 3000
38 changes: 30 additions & 8 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
const express = require("express");
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const client = require("prom-client");

const app = express();

// Initialize Sentry (v7 API)
// --- Prometheus Setup ---
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics(); // Collect Node.js process metrics

// Custom counter
const httpRequestCounter = new client.Counter({
name: "http_requests_total",
help: "Total number of HTTP requests",
labelNames: ["method", "route", "status"],
});

// Middleware to count requests
app.use((req, res, next) => {
res.on("finish", () => {
httpRequestCounter.labels(req.method, req.path, res.statusCode).inc();
});
next();
});

// Expose /metrics endpoint for Prometheus
app.get("/metrics", async (req, res) => {
res.set("Content-Type", client.register.contentType);
res.end(await client.register.metrics());
});

// --- Sentry Setup (v7) ---
Sentry.init({
dsn: process.env.SENTRY_DSN || "",
integrations: [
new Tracing.Integrations.Express({ app }), // works fine with v7
],
tracesSampleRate: 1.0, // lower this in prod (e.g. 0.1)
integrations: [new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
});

// Request handler (before routes)
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());

Expand All @@ -22,13 +45,12 @@ app.get("/", (req, res) => {
res.send("You are safe in Wizfi's Pipeline!");
});

// Debug route to test Sentry (ESLint safe)
// Debug route
app.get("/debug-sentry", (req, res) => {
res.status(500).send("Triggering Sentry debug error...");
throw new Error("Debug Sentry error!");
});

// Error handler (after routes)
app.use(Sentry.Handlers.errorHandler());

module.exports = app;
Loading