Skip to content

📈 feat: Add Prometheus Metrics Endpoint + AWS Credential Providers#13111

Merged
danny-avila merged 9 commits into
devfrom
danny-avila/oss-metrics-prom-aws
May 13, 2026
Merged

📈 feat: Add Prometheus Metrics Endpoint + AWS Credential Providers#13111
danny-avila merged 9 commits into
devfrom
danny-avila/oss-metrics-prom-aws

Conversation

@danny-avila

@danny-avila danny-avila commented May 13, 2026

Copy link
Copy Markdown
Owner

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.

  • Added a createMetrics helper in @librechat/api that collects default Prometheus metrics and records HTTP request counts and durations with normalized route labels.
  • Mounted /metrics in the API server with bearer-token protection via METRICS_SECRET; when the secret is unset, the route consistently returns 401.
  • Added prom-client to the backend and API package
  • Kept the Smithy transitive lock entry at the pre-existing non-churning version so the API build does not emit circular-dependency warnings.
  • Covered path normalization and /metrics authorization behavior with focused tests.
  • added @aws-sdk/credential-providers to allow IRSA access to bedrock

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • npm ci --no-audit --no-fund
  • npm run build:api
  • output=$(npm run build:api 2>&1); printf '%s\n' "$output" | grep -q "Circular depend" && echo CIRCULAR_CHECK_FAIL || echo CIRCULAR_CHECK_PASS
  • cd packages/api && npx jest src/app/metrics.spec.ts --runInBand --coverage=false
  • cd api && npx jest server/index.metrics.spec.js --runInBand --forceExit

Test Configuration:

  • Node.js from the local workspace
  • MongoDB provided by mongodb-memory-server for the server route test

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules.

Copilot AI review requested due to automatic review settings May 13, 2026 08:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) in packages/api.
  • Mounts /metrics in 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": "*",
Comment on lines +49 to +53
res.on('finish', () => {
const labels = { method: req.method, path: normalizePath(req.path), status: res.statusCode };
httpRequests.inc(labels);
end(labels);
});
Comment thread api/server/index.js
Comment on lines 113 to +116
app.get('/health', (_req, res) => res.status(200).send('OK'));

/* Middleware */
app.use(metricsMiddleware);
@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13111 index is now live on the MCP server.
Deploy run

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13111 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila changed the base branch from main to dev May 13, 2026 17:12
…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
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/api/src/app/metrics.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13111 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila force-pushed the danny-avila/oss-metrics-prom-aws branch from b11e4a0 to b15f8f9 Compare May 13, 2026 19:40
@danny-avila danny-avila changed the title 📈 feat: Add Prometheus Metrics Endpoint 📈 feat: Add Prometheus Metrics Endpoint + AWS Credentials Provider May 13, 2026
@danny-avila danny-avila changed the title 📈 feat: Add Prometheus Metrics Endpoint + AWS Credentials Provider 📈 feat: Add Prometheus Metrics Endpoint + AWS Credential Providers May 13, 2026
@danny-avila danny-avila marked this pull request as ready for review May 13, 2026 19:47
@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13111 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/api/src/app/metrics.ts
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/data-schemas/package.json Outdated
Comment thread packages/api/src/app/metrics.ts Outdated
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/api/src/app/metrics.ts Outdated
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13111 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila merged commit 34dd8d5 into dev May 13, 2026
13 checks passed
@danny-avila danny-avila deleted the danny-avila/oss-metrics-prom-aws branch May 13, 2026 20:49
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request May 15, 2026
…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
patricia2510 pushed a commit to lexaeon-org/libre-chat that referenced this pull request May 21, 2026
…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
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.

2 participants