Skip to content

feat: Report a per-http call metric#303

Merged
SoulPancake merged 6 commits into
openfga:mainfrom
Abishek-Newar:report-per-http-call
Feb 5, 2026
Merged

feat: Report a per-http call metric#303
SoulPancake merged 6 commits into
openfga:mainfrom
Abishek-Newar:report-per-http-call

Conversation

@Abishek-Newar

@Abishek-Newar Abishek-Newar commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

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?

  • Added httpRequestDuration histogram to telemetry/histograms.ts
  • Added HistogramHttpRequestDuration to TelemetryMetric enum in telemetry/metrics.ts - Added default configuration and validation in telemetry/configuration.ts
  • Modified attemptHttpRequest() in common.ts to emit the metric for each HTTP call within the retry loop
  • Added unit tests in tests/telemetry/histograms.test.ts

References

closes #158

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • New Features

    • Added HTTP request duration telemetry to track individual HTTP call performance with detailed monitoring metrics.
  • Tests

    • Added validation test for HTTP request duration histogram configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@Abishek-Newar
Abishek-Newar requested a review from a team as a code owner January 20, 2026 14:05
@coderabbitai

coderabbitai Bot commented Jan 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Walkthrough

This PR implements per-HTTP request telemetry tracking by introducing a new HistogramHttpRequestDuration metric. The metric measures individual HTTP request durations across all attempts, including retries, with rich contextual attributes (host, scheme, URL, method, user-agent, response status). Telemetry configuration is integrated into the HTTP retry layer to enable per-call instrumentation and histogram emission.

Changes

Cohort / File(s) Summary
Telemetry Infrastructure
telemetry/metrics.ts, telemetry/histograms.ts, telemetry/configuration.ts
Added new HistogramHttpRequestDuration metric enum member. Defined histogram metadata (name: "fga-client.http_request.duration", unit: "milliseconds"). Extended TelemetryConfiguration constructor to initialize and validate the new histogram metric with default attributes.
HTTP Retry Layer
common.ts
Enhanced attemptHttpRequest to accept optional telemetryConfig parameter containing telemetry configuration and user-agent. Integrated per-call duration measurement via performance.now() for each attempt. Added conditional histogram emission when telemetry is enabled, emitting request metrics with attributes (host, scheme, URL, method, user-agent, response status). Preserved existing retry logic and response structure.
Test Coverage
tests/telemetry/histograms.test.ts
Added test case validating httpRequestDuration histogram metadata (name, unit, description).

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding per-HTTP call telemetry metrics.
Linked Issues check ✅ Passed The PR fully implements issue #158 requirements: creates fga-client.http_request.duration metric, emits it per HTTP request with required attributes (host, method, URL, scheme, User-Agent, status), and integrates into retry logic.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing per-HTTP call metrics: telemetry configuration, histogram definitions, metric enums, and HTTP request instrumentation with tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

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

@Abishek-Newar

Copy link
Copy Markdown
Contributor Author

Hi @SoulPancake , Please review it

@codecov-commenter

codecov-commenter commented Jan 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.55%. Comparing base (c639c5d) to head (5b34562).

Files with missing lines Patch % Lines
telemetry/configuration.ts 60.00% 1 Missing and 1 partial ⚠️
common.ts 96.42% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

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 httpRequestDuration histogram 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.

Comment thread telemetry/histograms.ts Outdated
@coderabbitai

coderabbitai Bot commented Jan 20, 2026

Copy link
Copy Markdown

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #304

coderabbitai Bot added a commit that referenced this pull request Jan 20, 2026
Docstrings generation was requested by @SoulPancake.

* #303 (comment)

The following files were modified:

* `common.ts`
Comment thread common.ts Outdated
@Abishek-Newar

Copy link
Copy Markdown
Contributor Author

Hi @SoulPancake , Please review

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

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.

Comment thread telemetry/histograms.ts Outdated
Comment thread common.ts Outdated
@Abishek-Newar

Copy link
Copy Markdown
Contributor Author

@SoulPancake , please review it

Comment thread telemetry/attributes.ts

@SoulPancake SoulPancake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LG

@SoulPancake
SoulPancake added this pull request to the merge queue Feb 5, 2026
Merged via the queue into openfga:main with commit 932d4ab Feb 5, 2026
11 checks passed
@dosubot

dosubot Bot commented Feb 5, 2026

Copy link
Copy Markdown

Related Documentation

Checked 5 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@rhamzeh rhamzeh mentioned this pull request Feb 9, 2026
4 tasks
@rhamzeh

rhamzeh commented Feb 13, 2026

Copy link
Copy Markdown
Member

@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?

@coderabbitai

coderabbitai Bot commented Feb 13, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@rhamzeh I'll create a GitHub issue to track the documentation update for the new metric.


🏁 Script executed:

#!/bin/bash

# Create a GitHub issue for updating the OpenTelemetry documentation
gh issue create \
  --repo openfga/js-sdk \
  --title "docs: Update OpenTelemetry documentation for new http_request.duration metric" \
  --body "## Description

The OpenTelemetry documentation at \`docs/opentelemetry.md\` needs to be updated to include information about the new \`fga-client.http_request.duration\` histogram metric that was added in PR `#303`.

## Context

PR `#303` introduced a new per-HTTP-request metric (\`HistogramHttpRequestDuration\`) that emits telemetry for each individual HTTP request, including retry attempts. The documentation should be updated to reflect this new metric alongside the existing metrics.

## References

- PR: https://github.com/openfga/js-sdk/pull/303
- Comment: https://github.com/openfga/js-sdk/pull/303#issuecomment-$(gh api repos/openfga/js-sdk/pulls/303/comments --jq '.[].id' | tail -1)
- Requested by: `@rhamzeh`

## File to Update

- \`docs/opentelemetry.md\`" \
  --assignee rhamzeh

Length of output: 44


@rhamzeh I've created issue #322 to track updating the OpenTelemetry documentation for the new fga-client.http_request.duration metric. The issue has been assigned to you.

@coderabbitai

coderabbitai Bot commented Feb 13, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@rhamzeh, issue #322 has been created to track updating the OpenTelemetry documentation in docs/opentelemetry.md for the new fga-client.http_request.duration metric. The issue is assigned to you and references this PR.

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.

Report a per-http call metric

5 participants