-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32b1835
commit 2340273
Showing
3 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package avalanche | ||
|
||
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" | ||
) | ||
|
||
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, vtx Vertex) error { | ||
ctx, span := c.tracer.Start(ctx, "tracedConsensus.Add", oteltrace.WithAttributes( | ||
attribute.Stringer("vtxID", vtx.ID()), | ||
)) | ||
defer span.End() | ||
|
||
return c.Consensus.Add(ctx, vtx) | ||
} | ||
|
||
func (c *tracedConsensus) RecordPoll(ctx context.Context, votes ids.UniqueBag) error { | ||
var allVotes ids.BitSet64 | ||
for _, vote := range votes { | ||
allVotes.Union(vote) | ||
} | ||
|
||
ctx, span := c.tracer.Start(ctx, "tracedConsensus.RecordPoll", oteltrace.WithAttributes( | ||
attribute.Int("numVotes", allVotes.Len()), | ||
attribute.Int("numVtxIDs", len(votes)), | ||
)) | ||
defer span.End() | ||
|
||
return c.Consensus.RecordPoll(ctx, votes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2019-2022, 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" | ||
) | ||
|
||
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 ids.Bag) 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) | ||
} |