66 "errors"
77 "fmt"
88 "net/http"
9+ "path"
10+ "strings"
911
1012 drclient "github.com/ipfs/boxo/routing/http/client"
1113 "github.com/ipfs/boxo/routing/http/contentrouter"
@@ -24,6 +26,7 @@ import (
2426 "github.com/libp2p/go-libp2p/core/routing"
2527 ma "github.com/multiformats/go-multiaddr"
2628 "go.opencensus.io/stats/view"
29+ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2730)
2831
2932var log = logging .Logger ("routing/delegated" )
@@ -187,8 +190,27 @@ func httpRoutingFromConfig(conf config.Router, extraHTTP *ExtraHTTPParams) (rout
187190
188191 delegateHTTPClient := & http.Client {
189192 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 ,
192214 },
193215 }
194216
0 commit comments