Telemetry subsystem design improvements (umbrella)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Refactoring
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- java
- Bereich
- backend-api-design, observability-sre
Rechercherichtung
Beginnen Sie mit Design Issue 2 und lesen Sie src/main/java/dev/openfga/sdk/telemetry/Metrics.java, verfolgen Sie anschließend die Konstruktion der Konfiguration durch OpenFgaApi.java und HttpRequestAttempt.java. Prüfen Sie OAuth2Client.java und die TelemetryConfiguration API anhand der sechs aufgeführten Design Issues. Erledigt ist die Aufgabe, wenn die Maintainer der abgestimmten Architektur zustimmen und für jede ausgewählte Änderung die Ergebnisse in Bezug auf Kompatibilität, Testbarkeit und telemetry-spec festgelegt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Note: This analysis was performed by AI with human assistance. The criticisms and proposed solutions below may warrant further discussion before acting on them.
Context
PR #290 fixes the immediate issue from #209 (sharing a single Telemetry instance per SDK client). During a comprehensive audit of the telemetry subsystem, several additional design limitations were identified. This umbrella issue tracks the larger improvements that require coordinated refactoring.
Related standalone bug fixes
These can be addressed independently in small PRs:
- #291 — All telemetry attributes exported as strings instead of correct types
- #292 —
Metricsconstructor mutates theConfigurationobject passed to it - #293 — No telemetry recorded for failed requests
Design Issues
1. ConfigurationOverride telemetry settings are silently ignored
Files: OpenFgaApi.java, HttpRequestAttempt.java
Every OpenFgaApi method accepts a ConfigurationOverride. When used, it creates a new Configuration via this.configuration.override(configurationOverride). However, the shared this.telemetry was constructed from the original configuration. So if an override changes telemetry settings, those changes are silently ignored.
Options:
- A)
Telemetry/Metricsmethods accept aConfigurationparameter at recording time (not just at construction) - B)
HttpRequestAttemptcreates a request-scopedTelemetrywhen an override is detected - C) Document that
ConfigurationOverridedoes not affect telemetry (if acceptable)
2. Users cannot provide their own OpenTelemetry instance
File: src/main/java/dev/openfga/sdk/telemetry/Metrics.java:26
Metrics hardcodes GlobalOpenTelemetry.get().getMeterProvider().get("openfga-sdk"). Users have no way to pass their own OpenTelemetry or MeterProvider instance.
Problems:
- Forces global state — Users must call
buildAndRegisterGlobal(). Non-global instances (common in multi-tenant setups, testing) silently produce no metrics. - Violates OTel best practices — The OTel Java library instrumentation guide says libraries should accept an
OpenTelemetryinstance rather than using the global singleton. - Untestable — No way to inject an in-memory meter for unit/integration tests.
Recommended fix: Allow ClientConfiguration to accept an optional OpenTelemetry instance, falling back to GlobalOpenTelemetry.get() if none is provided (backward-compatible):
ClientConfiguration config = new ClientConfiguration()
.apiUrl("https://...")
.openTelemetry(myOtelInstance); // optional
3. OAuth2Client creates a separate Telemetry instance
File: src/main/java/dev/openfga/sdk/api/auth/OAuth2Client.java:44
OAuth2Client creates its own Configuration copy and its own Telemetry. While PR #290 fixed the per-request issue, the credentialsRequest counter (line 61) still records against OAuth2Client's own separate Metrics instance. Credential request counts may not aggregate correctly with the parent client's metrics if the OTel implementation is sensitive to meter identity.
4. Telemetry class is unnecessary indirection
Telemetry is a thin wrapper that only lazily creates a Metrics instance. If it's not going to provide additional facilities (traces, logs, spans), it could be collapsed into Metrics directly, simplifying the API.
5. Missing fga-client.request.count metric from spec
The cross-SDK telemetry spec includes fga-client.request.count as a counter (disabled by default). The Java SDK doesn't implement it. The Python SDK added it in PR #135. While disabled by default, it should exist for spec parity and for users who want to enable it.
6. Poor DX — TelemetryConfiguration API is hard to use
The current configuration API requires:
Map<Metric, Map<Attribute, Optional<Object>>>
Problems:
- Unreadable type signature — Intimidating and hard to remember; 20+ lines of boilerplate for simple customization.
Optional<Object>serves no purpose — Every usage passesOptional.empty(). The data structure is effectively aSet<Attribute>disguised as aMap<Attribute, Optional<Object>>.- No builder/fluent API — No way to express
.disableAttribute(Attributes.URL_FULL). - All-or-nothing customization — To disable a single attribute on a single metric, users must copy the default map, mutate it, and reconstruct the full metrics map.
Recommended improvement: Add a builder pattern:
TelemetryConfiguration.builder()
.metric(Histograms.REQUEST_DURATION, attrs -> attrs
.defaults()
.without(Attributes.URL_FULL))
.metric(Counters.CREDENTIALS_REQUEST) // all defaults
.build();
Or at minimum, provide helper methods like withoutAttribute(Metric, Attribute) and withoutMetric(Metric).
Suggested Approach
These design issues are interrelated and would benefit from coordinated refactoring. A suggested ordering:
- Design Issue 2 (accept
OpenTelemetryinstance) — foundational, unblocks testability - Design Issue 4 (simplify
Telemetry→Metrics) — reduces surface area for other changes - Design Issue 3 (OAuth2Client telemetry sharing) — depends on design decisions from above
- Design Issue 1 (ConfigurationOverride telemetry) — requires clarity on config architecture
- Design Issue 5 (add
fga-client.request.count) — straightforward once plumbing is settled - Design Issue 6 (builder API for TelemetryConfiguration) — can be done at any point
- Vorherrschende Sprache
- Java
- Sterne
- 54
- Forks
- 26
- Ø Merge
- 2 T. 15 Std.
- Gemergte PRs (30 T.)
- 11
Entwicklungsumgebung
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openfga/java-sdk
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
openfga/java-sdk#370 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
openfga/java-sdk#361 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in openfga/java-sdk
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
oracle/javavscode#652 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
OpenAPITools/openapi-generator#25014 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
AloisSeckar/demos-java#380 ·