Skip to content

[Enhancement] Add support for OpenTelemetry Zero-Code Instrumentation Agent #201

@dyeam0

Description

@dyeam0

Checklist

Describe the problem you'd like to have solved

To improve the out-of-the-box observability experience for developers, the Java SDK should be enhanced to support the OpenTelemetry (Otel) zero-code instrumentation agent.

Context

Many teams using Java rely on the Otel agent for automatic, consistent telemetry collection across their services without needing to add manual instrumentation code to their applications. Supporting this common use case would allow developers to get valuable metrics from the OpenFGA SDK just as they do for other auto-instrumented libraries, significantly lowering the effort to monitor the SDK's performance.

Currently, the SDK initializes its telemetry with OpenTelemetry.noop(), which does not integrate with a global provider that may have been configured by an agent.

Describe the ideal solution

The SDK should be updated to check for and use the globally registered MeterProvider if one exists. This change would make the SDK's telemetry "plug-and-play" for users of the Otel Java agent. With this enhancement, users running the agent would automatically see OpenFGA client metrics without writing any additional telemetry configuration code in their application.

Implementation Details

The implementation would involve changing how the MeterProvider is retrieved.

File: src/main/java/dev/openfga/sdk/telemetry/Metrics.java
Line: 38

Current Implementation:

meter = OpenTelemetry.noop().getMeterProvider().get(InstrumentationScope.NAME, InstrumentationScope.VERSION);

Proposed Change:

meter = GlobalOpenTelemetry.getMeterProvider().get(InstrumentationScope.NAME, InstrumentationScope.VERSION);

This change would allow the SDK to correctly use the MeterProvider that the Otel Java agent registers globally, enabling seamless metric collection in a zero-code instrumentation environment.

Alternatives and current workarounds

Manual Instrumentation (not ideal for those using zero-code instrumentation): A user can bypass the agent for the FGA SDK by manually instantiating and configuring an OpenTelemetry object in their application code, as described in the SDK documentation. The significant drawback is that this defeats the primary benefit of using a zero-code agent and adds boilerplate configuration that the agent is meant to eliminate.

For users whose policy requires strict adherence to zero-code instrumentation, there is no viable workaround to get metrics from the SDK.

References

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions