feat: trace delegated routing http client (#11017)
Dennis Trautwein committed
Oct 24, 2025 at 10:21 UTC
886ac220050284a6a922cf4f18b984740283c259
1 file changed
+24
-2
routing/delegated.go
+24
-2
@@ -6,6 +6,8 @@ import (
6
"errors"
7
"fmt"
8
"net/http"
9
+ "path"
10
+ "strings"
11
12
drclient "github.com/ipfs/boxo/routing/http/client"
13
"github.com/ipfs/boxo/routing/http/contentrouter"
@@ -24,6 +26,7 @@ import (
26
"github.com/libp2p/go-libp2p/core/routing"
27
ma "github.com/multiformats/go-multiaddr"
28
"go.opencensus.io/stats/view"
29
+ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
30
)
31
32
var log = logging.Logger("routing/delegated")
@@ -187,8 +190,27 @@ func httpRoutingFromConfig(conf config.Router, extraHTTP *ExtraHTTPParams) (rout
190
191
delegateHTTPClient := &http.Client{
192
Transport: &drclient.ResponseBodyLimitedTransport{
190
- RoundTripper: transport,
191
- LimitBytes: 1 << 20,
193
+ RoundTripper: otelhttp.NewTransport(transport,
194
+ otelhttp.WithSpanNameFormatter(func(operation string, req *http.Request) string {
195
+ if req.Method == http.MethodGet {
196
+ switch {
197
+ case strings.HasPrefix(req.URL.Path, "/routing/v1/providers"):
198
+ return "DelegatedHTTPClient.FindProviders"
199
+ case strings.HasPrefix(req.URL.Path, "/routing/v1/peers"):
200
+ return "DelegatedHTTPClient.FindPeers"
201
+ case strings.HasPrefix(req.URL.Path, "/routing/v1/ipns"):
202
+ return "DelegatedHTTPClient.GetIPNS"
203
+ }
204
+ } else if req.Method == http.MethodPut {
205
+ switch {
206
+ case strings.HasPrefix(req.URL.Path, "/routing/v1/ipns"):
207
+ return "DelegatedHTTPClient.PutIPNS"
208
+ }
209
+ }
210
+ return "DelegatedHTTPClient." + path.Dir(req.URL.Path)
211
+ }),
212
+ ),
213
+ LimitBytes: 1 << 20,
214
},
215
}
216