From 6790add2d675cb6fbd78776e19ccc1128822725d Mon Sep 17 00:00:00 2001 From: Jaz Volpert Date: Wed, 14 Feb 2024 08:23:49 +0000 Subject: [PATCH] Wrap robust HTTP client with OTEL --- models/models.go | 13 ++----------- util/http.go | 3 +++ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/models/models.go b/models/models.go index 1aaf13e2..9781e75b 100644 --- a/models/models.go +++ b/models/models.go @@ -2,10 +2,8 @@ package models import ( "database/sql" - "net/http" "time" - "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "gorm.io/gorm" bsky "github.com/bluesky-social/indigo/api/bsky" @@ -124,21 +122,14 @@ type PDS struct { } func ClientForPds(pds *PDS) *xrpc.Client { - c := http.Client{ - Transport: otelhttp.NewTransport(http.DefaultTransport), - Timeout: time.Minute * 5, - } - if pds.SSL { return &xrpc.Client{ - Client: &c, - Host: "https://" + pds.Host, + Host: "https://" + pds.Host, } } return &xrpc.Client{ - Client: &c, - Host: "http://" + pds.Host, + Host: "http://" + pds.Host, } } diff --git a/util/http.go b/util/http.go index 18c3094a..e4d4a8d9 100644 --- a/util/http.go +++ b/util/http.go @@ -6,7 +6,9 @@ import ( "net/http" "time" + "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-retryablehttp" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" ) type LeveledSlog struct { @@ -45,6 +47,7 @@ func RobustHTTPClient() *http.Client { logger := LeveledSlog{inner: slog.Default().With("subsystem", "RobustHTTPClient")} retryClient := retryablehttp.NewClient() + retryClient.HTTPClient.Transport = otelhttp.NewTransport(cleanhttp.DefaultPooledTransport()) retryClient.RetryMax = 3 retryClient.RetryWaitMin = 1 * time.Second retryClient.RetryWaitMax = 10 * time.Second -- 2.51.2