github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowman/traced_consensus.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package snowman
     5  
     6  import (
     7  	"context"
     8  
     9  	"go.opentelemetry.io/otel/attribute"
    10  
    11  	"github.com/MetalBlockchain/metalgo/ids"
    12  	"github.com/MetalBlockchain/metalgo/trace"
    13  	"github.com/MetalBlockchain/metalgo/utils/bag"
    14  
    15  	oteltrace "go.opentelemetry.io/otel/trace"
    16  )
    17  
    18  var _ Consensus = (*tracedConsensus)(nil)
    19  
    20  type tracedConsensus struct {
    21  	Consensus
    22  	tracer trace.Tracer
    23  }
    24  
    25  func Trace(consensus Consensus, tracer trace.Tracer) Consensus {
    26  	return &tracedConsensus{
    27  		Consensus: consensus,
    28  		tracer:    tracer,
    29  	}
    30  }
    31  
    32  func (c *tracedConsensus) RecordPoll(ctx context.Context, votes bag.Bag[ids.ID]) error {
    33  	ctx, span := c.tracer.Start(ctx, "tracedConsensus.RecordPoll", oteltrace.WithAttributes(
    34  		attribute.Int("numVotes", votes.Len()),
    35  		attribute.Int("numBlkIDs", len(votes.List())),
    36  	))
    37  	defer span.End()
    38  
    39  	return c.Consensus.RecordPoll(ctx, votes)
    40  }