-
Notifications
You must be signed in to change notification settings - Fork 671
/
traced_consensus.go
50 lines (38 loc) · 1.22 KB
/
traced_consensus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowman
import (
"context"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/utils/bag"
)
var _ Consensus = (*tracedConsensus)(nil)
type tracedConsensus struct {
Consensus
tracer trace.Tracer
}
func Trace(consensus Consensus, tracer trace.Tracer) Consensus {
return &tracedConsensus{
Consensus: consensus,
tracer: tracer,
}
}
func (c *tracedConsensus) Add(ctx context.Context, blk Block) error {
ctx, span := c.tracer.Start(ctx, "tracedConsensus.Add", oteltrace.WithAttributes(
attribute.Stringer("blkID", blk.ID()),
attribute.Int64("height", int64(blk.Height())),
))
defer span.End()
return c.Consensus.Add(ctx, blk)
}
func (c *tracedConsensus) RecordPoll(ctx context.Context, votes bag.Bag[ids.ID]) error {
ctx, span := c.tracer.Start(ctx, "tracedConsensus.RecordPoll", oteltrace.WithAttributes(
attribute.Int("numVotes", votes.Len()),
attribute.Int("numBlkIDs", len(votes.List())),
))
defer span.End()
return c.Consensus.RecordPoll(ctx, votes)
}