Skip to content

Commit

Permalink
swarm: fix relationship between spans in open tracing (ethereum#19236)
Browse files Browse the repository at this point in the history
* swarm/network: propagate span with ctx

* swarm/network: try to stop stream.send.request spans on time

* swarm/storage: add chunk ref as a log to netstore.fetcher span
  • Loading branch information
nonsense authored and zelig committed Mar 8, 2019
1 parent ceeb047 commit 2cfe0be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions swarm/network/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package network

import (
"context"
"fmt"
"sync"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/swarm/tracing"
"github.com/opentracing/opentracing-go"
)

const (
Expand Down Expand Up @@ -318,6 +321,14 @@ func (f *Fetcher) doRequest(gone chan *enode.ID, peersToSkip *sync.Map, sources
gone <- sourceID
case <-f.ctx.Done():
}

// finish the request span
spanId := fmt.Sprintf("stream.send.request.%v.%v", *sourceID, req.Addr)
span := tracing.ShiftSpanByKey(spanId)

if span != nil {
defer span.(opentracing.Span).Finish()
}
}()
return sources, nil
}
2 changes: 1 addition & 1 deletion swarm/network/stream/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8,
// SendPriority sends message to the peer using the outgoing priority queue
func (p *Peer) SendPriority(ctx context.Context, msg interface{}, priority uint8) error {
defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("peer.sendpriority_t.%d", priority), nil).UpdateSince(time.Now())
tracing.StartSaveSpan(ctx)
ctx = tracing.StartSaveSpan(ctx)
metrics.GetOrRegisterCounter(fmt.Sprintf("peer.sendpriority.%d", priority), nil).Inc(1)
wmsg := WrappedPriorityMsg{
Context: ctx,
Expand Down
3 changes: 3 additions & 0 deletions swarm/storage/netstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/swarm/log"
"github.com/ethereum/go-ethereum/swarm/spancontext"
"github.com/opentracing/opentracing-go"
olog "github.com/opentracing/opentracing-go/log"

lru "github.com/hashicorp/golang-lru"
)
Expand Down Expand Up @@ -215,6 +216,8 @@ func (n *NetStore) getOrCreateFetcher(ctx context.Context, ref Address) *fetcher
cctx,
"netstore.fetcher",
)

sp.LogFields(olog.String("ref", ref.String()))
fetcher := newFetcher(sp, ref, n.NewNetFetcherFunc(cctx, ref, peers), destroy, peers, n.closeC)
n.fetchers.Add(key, fetcher)

Expand Down

0 comments on commit 2cfe0be

Please sign in to comment.