Skip to content

fix: disable http req duration metric by default#281

Open
SoulPancake wants to merge 6 commits intomainfrom
fix/disable-http-req-duration
Open

fix: disable http req duration metric by default#281
SoulPancake wants to merge 6 commits intomainfrom
fix/disable-http-req-duration

Conversation

@SoulPancake
Copy link
Member

@SoulPancake SoulPancake commented Mar 4, 2026

Description

Disables the duration metric by default ( makes it opt-in )
openfga/dotnet-sdk#173 (review)

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

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

  • Bug Fixes
    • The fga-client.http_request.duration metric is now disabled by default to improve performance. Users can enable it via telemetry configuration if monitoring is required.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

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.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3fd1bf40-d421-4ee0-a0e6-78ae986eb1c1

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This change disables the fga-client.http_request.duration metric by default in the telemetry configuration. The metric can still be enabled via explicit configuration. Guards are added to safely handle nil metric configurations, and tests verify the default-disabled behavior.

Changes

Cohort / File(s) Summary
Configuration
telemetry/configuration.go, telemetry/configuration_test.go
Sets METRIC_HISTOGRAM_HTTP_REQUEST_DURATION to nil by default, disabling the HTTP request duration histogram metric. Test added to verify the metric is nil in default configuration.
Runtime Behavior
telemetry/metrics.go, telemetry/metrics_test.go
Adds early guard in HTTPRequestDuration to return nil when metric configuration is nil or disabled. Existing test now requires explicit configuration to enable the metric; new tests validate default-disabled and explicitly-enabled behavior.
Documentation
CHANGELOG.md
Documents that fga-client.http_request.duration metric is disabled by default and can be enabled via telemetry configuration.

Possibly related PRs


🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly matches the main objective of the changeset: disabling the HTTP request duration metric by default across configuration, tests, and metrics handling code.

✏️ 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
  • Commit unit tests in branch fix/disable-http-req-duration
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.70%. Comparing base (7e50860) to head (9237ee9).

❌ Your project status has failed because the head coverage (33.70%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #281      +/-   ##
==========================================
+ Coverage   33.63%   33.70%   +0.06%     
==========================================
  Files         115      115              
  Lines        9831     9826       -5     
==========================================
+ Hits         3307     3312       +5     
+ Misses       6260     6244      -16     
- Partials      264      270       +6     

☔ 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.

@SoulPancake SoulPancake marked this pull request as ready for review March 4, 2026 07:56
@SoulPancake SoulPancake requested a review from a team as a code owner March 4, 2026 07:56
Copilot AI review requested due to automatic review settings March 4, 2026 07:56
@dosubot
Copy link

dosubot bot commented Mar 4, 2026

Related Documentation

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

How did I do? Any feedback?  Join Discord

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
telemetry/metrics_test.go (1)

292-330: Strengthen disabled-path assertions to verify no instrument creation.

The subtests check returned histogram is nil, which is good. Consider also asserting that no histogram was created in the meter to catch future regressions in side effects.

♻️ Suggested test hardening
 func TestHTTPRequestDuration_DisabledByDefault(t *testing.T) {
-	mockMeter := &MockMeter{
-		counters:   make(map[string]metric.Int64Counter),
-		histograms: make(map[string]metric.Float64Histogram),
-	}
-
 	t.Run("nil configuration", func(t *testing.T) {
+		mockMeter := &MockMeter{
+			counters:   make(map[string]metric.Int64Counter),
+			histograms: make(map[string]metric.Float64Histogram),
+		}
 		metrics := &Metrics{
 			Meter:         mockMeter,
 			Histograms:    make(map[string]metric.Float64Histogram),
 			Configuration: nil,
 		}
@@
 		if histogram != nil {
 			t.Fatalf("Expected nil histogram when metric is disabled (nil config), but got non-nil")
 		}
+		if len(mockMeter.histograms) != 0 {
+			t.Fatalf("Expected no histogram instruments to be created when disabled")
+		}
 	})
 
 	t.Run("nil metric config (disabled by default)", func(t *testing.T) {
+		mockMeter := &MockMeter{
+			counters:   make(map[string]metric.Int64Counter),
+			histograms: make(map[string]metric.Float64Histogram),
+		}
 		metrics := &Metrics{
 			Meter:      mockMeter,
 			Histograms: make(map[string]metric.Float64Histogram),
 			// METRIC_HISTOGRAM_HTTP_REQUEST_DURATION is nil — this is the default.
 			Configuration: &MetricsConfiguration{
@@
 		if histogram != nil {
 			t.Fatalf("Expected nil histogram when metric is disabled, but got non-nil")
 		}
+		if len(mockMeter.histograms) != 0 {
+			t.Fatalf("Expected no histogram instruments to be created when disabled")
+		}
 	})
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@telemetry/metrics_test.go` around lines 292 - 330, The test only asserts the
returned histogram is nil but should also assert that no histogram instrument
was created on the meter; update TestHTTPRequestDuration_DisabledByDefault
(inside both subtests) to inspect the MockMeter (mockMeter.histograms) after
calling Metrics.HTTPRequestDuration and assert it has no entries (or that the
expected histogram key is not present) to catch side-effect regressions; place
these assertions immediately after the existing nil-checks in the two subtests
and use the MockMeter.histograms map to verify no instrument creation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@telemetry/metrics_test.go`:
- Around line 292-330: The test only asserts the returned histogram is nil but
should also assert that no histogram instrument was created on the meter; update
TestHTTPRequestDuration_DisabledByDefault (inside both subtests) to inspect the
MockMeter (mockMeter.histograms) after calling Metrics.HTTPRequestDuration and
assert it has no entries (or that the expected histogram key is not present) to
catch side-effect regressions; place these assertions immediately after the
existing nil-checks in the two subtests and use the MockMeter.histograms map to
verify no instrument creation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 144cbeb5-89a8-4996-b9b6-1281bb4c1c04

📥 Commits

Reviewing files that changed from the base of the PR and between f6840bf and 1c866c8.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • telemetry/configuration.go
  • telemetry/configuration_test.go
  • telemetry/metrics.go
  • telemetry/metrics_test.go

Copy link
Contributor

Copilot AI left a comment

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 makes the fga-client.http_request.duration OpenTelemetry histogram opt-in by disabling it in the default telemetry configuration, and ensuring the SDK skips recording when it’s not enabled.

Changes:

  • Disable METRIC_HISTOGRAM_HTTP_REQUEST_DURATION in DefaultTelemetryConfiguration() by defaulting it to nil.
  • Skip creating/recording the HTTP request duration histogram when the metric isn’t enabled in configuration.
  • Add/adjust tests to validate enabled behavior and “disabled by default” behavior, and document the change in the changelog.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
telemetry/metrics.go Skips recording/creating the HTTP request duration histogram unless explicitly enabled.
telemetry/metrics_test.go Updates existing test to explicitly enable the metric; adds tests verifying disabled-by-default behavior.
telemetry/configuration.go Sets the HTTP request duration metric config to nil in defaults (opt-in).
telemetry/configuration_test.go Asserts the HTTP request duration metric is nil (disabled) by default.
CHANGELOG.md Notes behavior change under Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 102 to +106
func (m *Metrics) HTTPRequestDuration(value float64, attrs map[*Attribute]string) (metric.Float64Histogram, error) {
// If the metric is not configured (nil), skip recording entirely — it is disabled by default.
if m.Configuration == nil || m.Configuration.METRIC_HISTOGRAM_HTTP_REQUEST_DURATION == nil {
return nil, nil
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

HTTPRequestDuration now returns (nil, nil) when the metric is disabled. Since the return type is an interface, callers may not expect a nil histogram and could dereference it without checking. Consider returning a no-op histogram (or at least a consistent non-nil histogram while skipping Record) to keep the method contract consistent/safe, or ensure this nil-return convention is applied consistently across other metric methods as well.

Copilot uses AI. Check for mistakes.

## [Unreleased](https://github.com/openfga/go-sdk/compare/v0.7.5...HEAD)

- fix: The `fga-client.http_request.duration` metric is now disabled by default. Users can enable it via telemetry configuration if needed.
Copy link
Member

Choose a reason for hiding this comment

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

While it is a correction in behaviour, I think we should we call this out as a breaking change?


func (m *Metrics) HTTPRequestDuration(value float64, attrs map[*Attribute]string) (metric.Float64Histogram, error) {
// If the metric is not configured (nil), skip recording entirely — it is disabled by default.
if m.Configuration == nil || m.Configuration.METRIC_HISTOGRAM_HTTP_REQUEST_DURATION == nil {
Copy link
Member

Choose a reason for hiding this comment

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

I find it weird that we don't have this check already as to disable a metric you have to set nil already? Do we not actually support disabling metrics given no other codepath has this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep I think there are no other opt-in metrics right now
So this is a first
And the other ones are like enabled by default so this check never triggers for them ( they don't have the check there )

@SoulPancake SoulPancake requested a review from ewanharris March 10, 2026 10:10
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.

4 participants