diff --git a/cmd/swarm/swarm-smoke/feed_upload_and_sync.go b/cmd/swarm/swarm-smoke/feed_upload_and_sync.go index eddce78888..9823dc0542 100644 --- a/cmd/swarm/swarm-smoke/feed_upload_and_sync.go +++ b/cmd/swarm/swarm-smoke/feed_upload_and_sync.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "crypto/md5" "fmt" "io" @@ -18,8 +19,10 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/swarm/spancontext" "github.com/ethereum/go-ethereum/swarm/storage/feed" colorable "github.com/mattn/go-colorable" + opentracing "github.com/opentracing/opentracing-go" "github.com/pborman/uuid" cli "gopkg.in/urfave/cli.v1" ) @@ -304,6 +307,11 @@ func feedUploadAndSync(c *cli.Context) error { } func fetchFeed(topic string, user string, endpoint string, original []byte, ruid string) error { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ctx, sp := spancontext.StartSpan(ctx, "feed-and-sync.fetch") + defer sp.Finish() + log.Trace("sleeping", "ruid", ruid) time.Sleep(3 * time.Second) @@ -312,6 +320,12 @@ func fetchFeed(topic string, user string, endpoint string, original []byte, ruid tn := time.Now() reqUri := endpoint + "/bzz-feed:/?topic=" + topic + "&user=" + user req, _ := http.NewRequest("GET", reqUri, nil) + + opentracing.GlobalTracer().Inject( + sp.Context(), + opentracing.HTTPHeaders, + opentracing.HTTPHeadersCarrier(req.Header)) + trace := &httptrace.ClientTrace{ GetConn: func(_ string) { log.Trace("http get request (feed) - GetConn") @@ -365,6 +379,7 @@ func fetchFeed(topic string, user string, endpoint string, original []byte, ruid } req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) transport := http.DefaultTransport + //transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} res, err := transport.RoundTrip(req) diff --git a/cmd/swarm/swarm-smoke/upload_and_sync.go b/cmd/swarm/swarm-smoke/upload_and_sync.go index 792f5cfb31..15dfee3cf6 100644 --- a/cmd/swarm/swarm-smoke/upload_and_sync.go +++ b/cmd/swarm/swarm-smoke/upload_and_sync.go @@ -18,6 +18,7 @@ package main import ( "bytes" + "context" "crypto/md5" crand "crypto/rand" "errors" @@ -34,6 +35,8 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/swarm/spancontext" + opentracing "github.com/opentracing/opentracing-go" "github.com/pborman/uuid" cli "gopkg.in/urfave/cli.v1" @@ -135,14 +138,24 @@ func uploadAndSync(c *cli.Context) error { // fetch is getting the requested `hash` from the `endpoint` and compares it with the `original` file func fetch(hash string, endpoint string, original []byte, ruid string) error { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ctx, sp := spancontext.StartSpan(ctx, "upload-and-sync.fetch") + defer sp.Finish() + log.Trace("sleeping", "ruid", ruid) time.Sleep(3 * time.Second) - log.Trace("http get request", "ruid", ruid, "api", endpoint, "hash", hash) tn := time.Now() reqUri := endpoint + "/bzz:/" + hash + "/" req, _ := http.NewRequest("GET", reqUri, nil) + + opentracing.GlobalTracer().Inject( + sp.Context(), + opentracing.HTTPHeaders, + opentracing.HTTPHeadersCarrier(req.Header)) + trace := &httptrace.ClientTrace{ GetConn: func(_ string) { log.Trace("http get request - GetConn") @@ -195,7 +208,9 @@ func fetch(hash string, endpoint string, original []byte, ruid string) error { } req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) transport := http.DefaultTransport + //transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + res, err := transport.RoundTrip(req) if err != nil { log.Error(err.Error(), "ruid", ruid) diff --git a/swarm/api/http/middleware.go b/swarm/api/http/middleware.go index 3800212c21..42dd34cf5b 100644 --- a/swarm/api/http/middleware.go +++ b/swarm/api/http/middleware.go @@ -11,7 +11,8 @@ import ( "github.com/ethereum/go-ethereum/swarm/api" "github.com/ethereum/go-ethereum/swarm/log" "github.com/ethereum/go-ethereum/swarm/sctx" - "github.com/ethereum/go-ethereum/swarm/spancontext" + opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/ext" "github.com/pborman/uuid" ) @@ -94,7 +95,11 @@ func InstrumentOpenTracing(h http.Handler) http.Handler { return } spanName := fmt.Sprintf("http.%s.%s", r.Method, uri.Scheme) - ctx, sp := spancontext.StartSpan(r.Context(), spanName) + wireContext, _ := opentracing.GlobalTracer().Extract( + opentracing.HTTPHeaders, + opentracing.HTTPHeadersCarrier(r.Header)) + sp, ctx := opentracing.StartSpanFromContext(r.Context(), spanName, ext.RPCServerOption(wireContext)) + defer sp.Finish() h.ServeHTTP(w, r.WithContext(ctx)) })