Skip to content

Commit

Permalink
fix: api client should set default telemetry if not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames committed Jan 21, 2025
1 parent 9b6f886 commit ac935fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type service struct {
// NewAPIClient creates a new API client. Requires a userAgent string describing your application.
// optionally a custom http.Client to allow for advanced features such as caching.
func NewAPIClient(cfg *Configuration) *APIClient {
if cfg.Telemetry == nil {
cfg.Telemetry = telemetry.DefaultTelemetryConfiguration()
}
if cfg.HTTPClient == nil {
if cfg.Credentials == nil {
cfg.HTTPClient = http.DefaultClient
Expand Down
23 changes: 23 additions & 0 deletions api_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package openfga

import (
"github.com/openfga/go-sdk/telemetry"
"net/http"
"testing"
"time"
)

func TestApiClientCreatedWithDefaultTelemetry(t *testing.T) {
cfg := Configuration{
HTTPClient: &http.Client{Timeout: 10 * time.Second},
ApiUrl: "http://localhost:8080/",
}
_ = NewAPIClient(&cfg)

telemetry1 := telemetry.Get(telemetry.TelemetryFactoryParameters{Configuration: cfg.Telemetry})
telemetry2 := telemetry.Get(telemetry.TelemetryFactoryParameters{Configuration: cfg.Telemetry})

if telemetry1 != telemetry2 {
t.Fatalf("Telemetry instance should be the same")
}
}

0 comments on commit ac935fb

Please sign in to comment.