Skip to content

Commit

Permalink
add custom span & add tx finishing
Browse files Browse the repository at this point in the history
  • Loading branch information
asadkovich committed Dec 18, 2021
1 parent 51da2d0 commit 0be8148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions evmcore/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package evmcore

import (
"errors"
"github.com/Fantom-foundation/go-opera/tracing"
"math"
"math/big"
"math/rand"
Expand Down Expand Up @@ -1773,6 +1774,8 @@ func (t *txLookup) Remove(hash common.Hash) {
t.lock.Lock()
defer t.lock.Unlock()

defer tracing.FinishTx(hash, "txLookup.Remove()")

tx, ok := t.locals[hash]
if !ok {
tx, ok = t.remotes[hash]
Expand Down
17 changes: 15 additions & 2 deletions tracing/tx-tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ package tracing

import (
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/opentracing/opentracing-go"
)

// txSpan wraps opentracing span and stores additional payload
type txSpan struct {
opentracing.Span
begin time.Time
}

var (
enabled bool
txSpans = make(map[common.Hash]opentracing.Span)
txSpans = make(map[common.Hash]txSpan)
txSpansMu sync.RWMutex

noopSpan = opentracing.NoopTracer{}.StartSpan("")
Expand All @@ -35,9 +42,13 @@ func StartTx(tx common.Hash, operation string) {
return
}

span := opentracing.StartSpan("lifecycle")
span := txSpan{
Span: opentracing.StartSpan("lifecycle"),
begin: time.Now(),
}
span.SetTag("txhash", tx.String())
span.SetTag("enter", operation)

txSpans[tx] = span
}

Expand All @@ -55,7 +66,9 @@ func FinishTx(tx common.Hash, operation string) {
}

span.SetTag("exit", operation)
span.SetTag("time.millis", time.Since(span.begin).Milliseconds())
span.Finish()

delete(txSpans, tx)
}

Expand Down

0 comments on commit 0be8148

Please sign in to comment.