Skip to main content

Metrics

Godspeed supports Prometheus-based metrics out of the box. These metrics help you monitor the performance and behavior of your services, including request rates, latencies, and Prisma database query statistics.

When Are Metrics Available?

Metrics are exposed automatically at the /metrics endpoint once OpenTelemetry (OTEL) is enabled.

To enable metrics:

OTEL_ENABLED=true

Default Behavior

When OTEL is enabled:

  • The /metrics endpoint is registered by default.
  • It exposes:
    • HTTP request metrics (via the Express plugin)
    • Prisma datasource metrics (if configured)

How to Customize Metrics Behavior

You can customize metric collection in your HTTP event source (http.yaml) like so:

type: express
port: 3000
metrics:

metricsPath: '/metrics'
requestDurationBuckets: [0.2, 0.5, 1, 1.5, 2, 2.5] # Opttional: Custom latency buckets (in seconds)
requestLengthBuckets: [128, 256, 512, 1024] # Optional: Track incoming request sizes
responseLengthBuckets: [256, 512, 1024, 2048] # Optional: Track outgoing response sizes

Overriding /metrics Endpoint (Optional)

If you want full control (e.g., to combine multiple metrics like HTTP + multiple Prisma clients), you can disable the default metrics route and define your own:

1. In http.yaml:

metrics:
metricsPath: '/custom-metrics'

2. In your express.ts event source:

client.get('/metrics', async (req, res) => {
const expressMetrics = await promClient.register.metrics();
const prismaMetrics = await prismaClient.$metrics.prometheus();
res.set('Content-Type', promClient.register.contentType);
res.end(`${expressMetrics}\n${prismaMetrics}`);
});

What Metrics Are Available?

HTTP Metrics (via Express)

Automatically exposed when OTEL is enabled:

  • http_requests_total
  • http_request_duration_seconds
  • http_request_size_bytes
  • http_response_size_bytes

These metrics include labels like method, route, and status_code.

Prisma Metrics (via $metrics.prometheus())

If you have registered prisma metrics manually by setting upa middleware, then, you get:

  • prisma_client_queries_total
  • prisma_client_queries_active
  • prisma_client_queries_wait
  • ...and more depending on your query workload

Testing Metrics

Once your app is running with OTEL enabled:

curl http://localhost:3000/metrics

You should see all registered Prometheus metrics.

Use tools like Prometheus, Grafana, or Datadog to scrape and visualize this data.


Example Output Snippet

# HELP http_request_duration_seconds Duration of HTTP requests
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{method="GET",route="/helloworld",status_code="200",le="1"} 10

# HELP prisma_client_queries_total Total number of Prisma client queries executed
# TYPE prisma_client_queries_total counter
prisma_client_queries_total{datasource="main"} 1023

Summary

With a few lines of configuration, Godspeed enables robust Prometheus-based observability:

  • Plug-and-play setup with OTEL
  • Customizable bucket metrics for request profiling
  • Flexible override of the default /metrics endpoint

Start observing, debugging, and scaling your services with real-time insights today!


info

Metrics for custom plugins

Follow this Github issue to know how prometheus based metrics can be exposed for the other custom eventsource and datasource plugins.