Pull Request: Add /metrics Endpoint with Request Tracking#78
Open
human-77 wants to merge 3 commits intoOpenZeppelin:mainfrom
Open
Pull Request: Add /metrics Endpoint with Request Tracking#78human-77 wants to merge 3 commits intoOpenZeppelin:mainfrom
human-77 wants to merge 3 commits intoOpenZeppelin:mainfrom
Conversation
Basic test for /metrics/route.ts
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
If it's not possible do the merge without signing the CLA I won't mind if you guys just clone my repo and add to the project. It's just three files.
|
Author
|
I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement |
|
Any prediction on when will this be merged? My team needs observability. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a Prometheus-compatible metrics endpoint to monitor server health and track HTTP requests by route and status code.
Changes
1. route.ts
Implements a
/metricsendpoint that exposes server metrics in Prometheus format, including:up)process_cpu_seconds_total)http_requests_by_status)This endpoint can be scraped by Prometheus or other monitoring tools to track application performance and health.
2. requestCounter.ts
Provides a lightweight in-memory request counter utility with two main functions:
incrementCounter(route, statusCode): Records each HTTP request with its route and status codegetStatusCounters(): Retrieves the accumulated request statisticsUses
globalThisto persist counters across module hot-reloads in development, ensuring metrics aren't lost during the session.3. metrics.test.ts
Adds a basic test suite for the metrics endpoint to ensure:
/metricsendpoint responds successfullyUse Case
These changes enable observability for the MCP server, allowing developers and operators to: