Skip to content

fix: don't modify the configuration in the Metrics constructor - #411

Open
cvas22 wants to merge 1 commit into
openfga:mainfrom
cvas22:fix/292-metrics-config-mutation
Open

cvas22 wants to merge 1 commit into
openfga:mainfrom
cvas22:fix/292-metrics-config-mutation

Conversation

@cvas22

@cvas22 cvas22 commented Nov 5, 2026

Copy link
Copy Markdown

Description

The Metrics constructor set a new TelemetryConfiguration on the Configuration passed to it when it had none (#292). A Configuration shared with other code paths was thereby modified as a side effect of creating metrics.

Change:

  • Metrics keeps its own default TelemetryConfiguration and uses it whenever the configuration has none. It still reads the configuration on each call, so a telemetry configuration set later is picked up as before, but it never writes to it.
  • Attributes.prepare has a new overload that takes the TelemetryConfiguration, which Metrics uses with the resolved configuration. The existing prepare(attributes, metric, Configuration) delegates to it, so its behavior is unchanged.

The metrics recorded are the same as before: with no telemetry configuration, the defaults apply, as they did when the constructor set them.

Fixes #292

Testing

Two new cases in MetricsTest:

  • creating Metrics and recording a metric leaves the configuration's telemetry configuration unchanged
  • with no telemetry configuration, the default one is used: the credentials counter is recorded, and the configuration's telemetry configuration stays null

I haven't run the Gradle build locally, so I'm relying on CI for compilation and the test run.

When the configuration had no telemetry configuration, the Metrics
constructor set a new default one on it. A configuration shared with
other code paths was thereby changed as a side effect. Fall back to a
default telemetry configuration inside Metrics instead, and let
Attributes.prepare take the telemetry configuration directly.

Fixes openfga#292

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 requested a review from a team as a code owner November 5, 2026 09:40
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f43ac16-5055-45ce-9b70-87cca7c7c002
Commits

Reviewing files that changed from the base of the PR and between bc745c9 and 18a94c2.

Files selected for processing: 3

  • src/main/java/dev/openfga/sdk/telemetry/Attributes.java
  • src/main/java/dev/openfga/sdk/telemetry/Metrics.java
  • src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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.

Bug: Metrics constructor mutates the Configuration object passed to it

1 participant