📈 feat: Add Prometheus Metrics Endpoint + AWS Credential Providers#13111
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class Prometheus instrumentation to LibreChat’s API runtime by introducing a /metrics endpoint (bearer-token guarded) and a shared createMetrics helper in @librechat/api, plus corresponding dependency and test updates.
Changes:
- Introduces
createMetrics()(default Prometheus collectors + HTTP count/duration metrics with path normalization) inpackages/api. - Mounts
/metricsin the API server and adds Jest coverage for auth behavior and path normalization. - Adds
prom-client(and also@aws-sdk/credential-providers) to relevant package manifests/lockfile.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/data-schemas/package.json | Adds @aws-sdk/credential-providers as a peer dependency. |
| packages/api/src/app/metrics.ts | Implements Prometheus registry, default collectors, HTTP metrics middleware, and /metrics router with bearer auth. |
| packages/api/src/app/metrics.spec.ts | Adds unit tests for path normalization behavior. |
| packages/api/src/app/index.ts | Exports the new metrics module. |
| packages/api/package.json | Adds prom-client as a dependency of @librechat/api. |
| package-lock.json | Locks new dependencies (prom-client, AWS credential providers, transitive deps). |
| api/server/index.metrics.spec.js | Adds integration-style tests for /metrics authorization and content type. |
| api/server/index.js | Wires createMetrics() into server startup, registers middleware, mounts /metrics. |
| api/package.json | Adds prom-client and @aws-sdk/credential-providers to API server dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "@aws-sdk/credential-providers": "^3.1025.0", | ||
| "jsonwebtoken": "^9.0.2", | ||
| "klona": "^2.0.6", | ||
| "librechat-data-provider": "*", |
| res.on('finish', () => { | ||
| const labels = { method: req.method, path: normalizePath(req.path), status: res.statusCode }; | ||
| httpRequests.inc(labels); | ||
| end(labels); | ||
| }); |
| app.get('/health', (_req, res) => res.status(200).send('OK')); | ||
|
|
||
| /* Middleware */ | ||
| app.use(metricsMiddleware); |
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
…ectly - Bump `@smithy/core` to version 3.24.1 - Update `@aws-sdk/credential-providers` to version 3.1045.0 - Reintroduce `prom-client` dependency in package.json - Remove unnecessary dependencies from package.json
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0ab8071375
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
GitNexus: 🚀 deployedThe |
b11e4a0 to
b15f8f9
Compare
GitNexus: 🚀 deployedThe |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7870834e3a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb01a7170d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 867158e721
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
GitNexus: 🚀 deployedThe |
…anny-avila#13111) * feat: add prometheus metrics endpoint * fix: format metrics route spec * chore: update dependencies in package.json and package-lock.json correctly - Bump `@smithy/core` to version 3.24.1 - Update `@aws-sdk/credential-providers` to version 3.1045.0 - Reintroduce `prom-client` dependency in package.json - Remove unnecessary dependencies from package.json * chore: import order * fix: declare s3 presigner peer dependency * fix: normalize shared link metrics path * fix: bound metrics path labels * fix: tighten metrics auth and peers * fix: collapse partial metrics paths
…anny-avila#13111) * feat: add prometheus metrics endpoint * fix: format metrics route spec * chore: update dependencies in package.json and package-lock.json correctly - Bump `@smithy/core` to version 3.24.1 - Update `@aws-sdk/credential-providers` to version 3.1045.0 - Reintroduce `prom-client` dependency in package.json - Remove unnecessary dependencies from package.json * chore: import order * fix: declare s3 presigner peer dependency * fix: normalize shared link metrics path * fix: bound metrics path labels * fix: tighten metrics auth and peers * fix: collapse partial metrics paths
Summary
I added a generic Prometheus metrics endpoint and moved the supporting observability dependencies into OSS so downstream forks do not need to carry those package deltas.
createMetricshelper in@librechat/apithat collects default Prometheus metrics and records HTTP request counts and durations with normalized route labels./metricsin the API server with bearer-token protection viaMETRICS_SECRET; when the secret is unset, the route consistently returns401.prom-clientto the backend and API package/metricsauthorization behavior with focused tests.@aws-sdk/credential-providersto allow IRSA access to bedrockChange Type
Testing
npm ci --no-audit --no-fundnpm run build:apioutput=$(npm run build:api 2>&1); printf '%s\n' "$output" | grep -q "Circular depend" && echo CIRCULAR_CHECK_FAIL || echo CIRCULAR_CHECK_PASScd packages/api && npx jest src/app/metrics.spec.ts --runInBand --coverage=falsecd api && npx jest server/index.metrics.spec.js --runInBand --forceExitTest Configuration:
mongodb-memory-serverfor the server route testChecklist