feat: Report a per-http call metric#303
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
WalkthroughThis PR implements per-HTTP request telemetry tracking by introducing a new Changes
Sequence DiagramsequenceDiagram
participant Client as Client Code
participant HTTP as attemptHttpRequest
participant Axios as AxiosInstance
participant Telemetry as TelemetryEmitter
Client->>HTTP: Call with telemetryConfig
Note over HTTP: Record start time (performance.now())
HTTP->>Axios: Execute HTTP request
Axios-->>HTTP: Response/Error received
Note over HTTP: Calculate duration
HTTP->>HTTP: Build histogram attributes<br/>(host, scheme, URL, method, user-agent, status)
alt telemetry enabled
HTTP->>Telemetry: Emit histogram with duration<br/>and enriched attributes
end
HTTP-->>Client: Return response with retry count
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @SoulPancake , Please review it |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #303 +/- ##
=======================================
Coverage 89.55% 89.55%
=======================================
Files 25 25
Lines 1446 1475 +29
Branches 266 277 +11
=======================================
+ Hits 1295 1321 +26
- Misses 91 93 +2
- Partials 60 61 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new per-HTTP request telemetry metric to provide visibility into individual HTTP calls, including retry attempts. Previously, the SDK only emitted metrics at the SDK method level which aggregated all retries into a single measurement.
Changes:
- Added new
httpRequestDurationhistogram metric that emits per-HTTP request with detailed attributes including host, method, URL, scheme, user agent, and response status code - Updated telemetry configuration to include default settings and validation for the new metric
- Modified the retry loop in
attemptHttpRequest()to emit the metric after each HTTP call (both successful and failed attempts)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| telemetry/histograms.ts | Defines the new httpRequestDuration histogram with name, unit, and description |
| telemetry/metrics.ts | Adds HistogramHttpRequestDuration enum value for the new metric type |
| telemetry/configuration.ts | Adds default configuration and attribute validation for the new histogram metric |
| common.ts | Implements metric emission logic in the HTTP retry loop to capture duration and attributes for each individual HTTP request |
| tests/telemetry/histograms.test.ts | Adds unit test to verify the histogram definition properties |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @SoulPancake. * #303 (comment) The following files were modified: * `common.ts`
|
Hi @SoulPancake , Please review |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@SoulPancake , please review it |
|
@coderabbitai - we forgot to update the related otel documentation in https://github.com/openfga/js-sdk/blob/main/docs/opentelemetry.md - can you add a ticket for that? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
🏁 Script executed: Length of output: 44
|
|
Tip For best results, initiate chat on the files or code changes.
|
Description
What problem is being solved?
Currently, the SDK emits metrics at the SDK method level (e.g., fga-client.request.duration covers the entire SDK call including retries). Users want visibility into each individual HTTP request sent by the SDK to better understand performance characteristics, especially when retries occur.
How is it being solved?
Added a new histogram metric fga-client.http_request.duration that is emitted per-HTTP request (including each retry attempt), with attributes: host, method, URL, scheme, User-Agent, and response status code.
What changes are made to solve it?
httpRequestDurationhistogram totelemetry/histograms.tsHistogramHttpRequestDurationtoTelemetryMetricenum intelemetry/metrics.ts- Added default configuration and validation intelemetry/configuration.tsattemptHttpRequest()incommon.tsto emit the metric for each HTTP call within the retry looptests/telemetry/histograms.test.tsReferences
closes #158
Review Checklist
mainSummary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.