github.com/MetalBlockchain/metalgo@v1.11.9/snow/validators/traced_state.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package validators 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 14 oteltrace "go.opentelemetry.io/otel/trace" 15 ) 16 17 var _ State = (*tracedState)(nil) 18 19 type tracedState struct { 20 s State 21 getMinimumHeightTag string 22 getCurrentHeightTag string 23 getSubnetIDTag string 24 getValidatorSetTag string 25 tracer trace.Tracer 26 } 27 28 func Trace(s State, name string, tracer trace.Tracer) State { 29 return &tracedState{ 30 s: s, 31 getMinimumHeightTag: name + ".GetMinimumHeight", 32 getCurrentHeightTag: name + ".GetCurrentHeight", 33 getSubnetIDTag: name + ".GetSubnetID", 34 getValidatorSetTag: name + ".GetValidatorSet", 35 tracer: tracer, 36 } 37 } 38 39 func (s *tracedState) GetMinimumHeight(ctx context.Context) (uint64, error) { 40 ctx, span := s.tracer.Start(ctx, s.getMinimumHeightTag) 41 defer span.End() 42 43 return s.s.GetMinimumHeight(ctx) 44 } 45 46 func (s *tracedState) GetCurrentHeight(ctx context.Context) (uint64, error) { 47 ctx, span := s.tracer.Start(ctx, s.getCurrentHeightTag) 48 defer span.End() 49 50 return s.s.GetCurrentHeight(ctx) 51 } 52 53 func (s *tracedState) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error) { 54 ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes( 55 attribute.Stringer("chainID", chainID), 56 )) 57 defer span.End() 58 59 return s.s.GetSubnetID(ctx, chainID) 60 } 61 62 func (s *tracedState) GetValidatorSet( 63 ctx context.Context, 64 height uint64, 65 subnetID ids.ID, 66 ) (map[ids.NodeID]*GetValidatorOutput, error) { 67 ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes( 68 attribute.Int64("height", int64(height)), 69 attribute.Stringer("subnetID", subnetID), 70 )) 71 defer span.End() 72 73 return s.s.GetValidatorSet(ctx, height, subnetID) 74 }