Skip to content

chore: integrate Prometheus#129

Open
kevcodez wants to merge 4 commits intomainfrom
k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant
Open

chore: integrate Prometheus#129
kevcodez wants to merge 4 commits intomainfrom
k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant

Conversation

@kevcodez
Copy link
Collaborator

@kevcodez kevcodez commented Feb 18, 2026

  • Integrate Prometheus and expose via /metrics endpoint
  • Add custom metrics to help identify operational issues
  • Added missing log in case of server errors
  • Increases webhook max size to 10 MB
  • Bumped deps to resolve security warning
  • Metrics for pg pool to potentially flag bottleneck

- Integrate Prometheus and expose via /metrics endpoint
- Add custom metrics to help identify operational issues
- Added missing log in case of server errors
- Increases webhook max size to 10 MB
- Bumped deps to resolve security warning
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Prometheus metrics for webhook processing, delays, DB pool stats and internal server errors; exposed at /metrics and toggleable via PROMETHEUS_METRICS_ENABLED
  • Improvements

    • Webhook processing now records and exposes event-type and processing latency
    • Increased maximum webhook payload size
    • Error handling improved to avoid leaking internal details
  • Tests

    • Added test coverage for the /metrics endpoint
  • Chores

    • Updated dependency versions across the repo

Walkthrough

This PR integrates Prometheus into the Fastify app and adds business metrics for webhook processing. A new prometheus module defines counters, a histogram, and gauges; orb-sync-lib now returns { eventType, timeSinceEventCreatedMs }. Webhook handling records processed counts and delay, the Fastify app conditionally registers a /metrics endpoint (controlled by PROMETHEUS_METRICS_ENABLED) and wires prom-client to fastify-metrics. A custom error handler increments an internal-server-error metric for 5xx errors. Dependency version bumps and a test validating /metrics exposure were added.

Sequence Diagram(s)

sequenceDiagram
  participant Sender as Webhook Sender
  participant Fastify as Fastify App
  participant OrbSync as orb-sync-lib
  participant Prom as Prometheus (prom-client / /metrics)

  Sender->>Fastify: POST /webhooks (payload, headers)
  Fastify->>OrbSync: processWebhook(payload, headers)
  OrbSync-->>Fastify: { eventType, timeSinceEventCreatedMs }
  Fastify->>Prom: webhooksProcessedCounter.inc(eventType)
  Fastify->>Prom: webhookDelayMsHistogram.observe(eventType, timeSinceEventCreatedMs)
  Note right of Fastify: On 5xx errors -> internalServerErrorsCounter.inc()
  Prom->>Client: GET /metrics (scrape)
Loading

Assessment against linked issues

Objective Addressed Explanation
Integrate Prometheus client into fastify-app [BILLING-2055]
Expose /metrics endpoint [BILLING-2055]
Include webhook delay metric [BILLING-2055]
Expose additional business metrics [BILLING-2055]

Out-of-scope changes

Code Change Explanation
Tooling dependency version bumps (package.json) Root-level tooling and TypeScript/eslint/turbo version bumps are unrelated to the Prometheus integration objective.
JSON formatting changes in webhook test fixture (apps/node-fastify/src/test/orb/subscription.json) Whitespace/linebreak-only reformatting of test fixture does not affect the Prometheus integration requirements.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/node-fastify/src/prometheus.ts`:
- Line 6: The CI fails because explicit "as any" casts are used when
constructing prom-client metrics; replace those casts with the correct
prom-client types: change the type of the config parameter/variable to the
appropriate prom-client config interface (e.g., client.CounterConfiguration) and
remove "as any" so you call new client.Counter(config) with a properly typed
config; do the same for the other occurrence (line 11) using the corresponding
prom-client metric config type (use client.<MetricName>Configuration or import
the specific type) and update any variable signatures so TypeScript infers the
correct types instead of using "any".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments