-
Notifications
You must be signed in to change notification settings - Fork 661
/
traced_state.go
75 lines (59 loc) · 1.96 KB
/
traced_state.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package validators
import (
"context"
"fmt"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/trace"
)
var _ State = (*tracedState)(nil)
type tracedState struct {
s State
getMinimumHeightTag string
getCurrentHeightTag string
getSubnetIDTag string
getValidatorSetTag string
tracer trace.Tracer
}
func Trace(s State, name string, tracer trace.Tracer) State {
return &tracedState{
s: s,
getMinimumHeightTag: fmt.Sprintf("%s.GetMinimumHeight", name),
getCurrentHeightTag: fmt.Sprintf("%s.GetCurrentHeight", name),
getSubnetIDTag: fmt.Sprintf("%s.GetSubnetID", name),
getValidatorSetTag: fmt.Sprintf("%s.GetValidatorSet", name),
tracer: tracer,
}
}
func (s *tracedState) GetMinimumHeight(ctx context.Context) (uint64, error) {
ctx, span := s.tracer.Start(ctx, s.getMinimumHeightTag)
defer span.End()
return s.s.GetMinimumHeight(ctx)
}
func (s *tracedState) GetCurrentHeight(ctx context.Context) (uint64, error) {
ctx, span := s.tracer.Start(ctx, s.getCurrentHeightTag)
defer span.End()
return s.s.GetCurrentHeight(ctx)
}
func (s *tracedState) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error) {
ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes(
attribute.Stringer("chainID", chainID),
))
defer span.End()
return s.s.GetSubnetID(ctx, chainID)
}
func (s *tracedState) GetValidatorSet(
ctx context.Context,
height uint64,
subnetID ids.ID,
) (map[ids.NodeID]*GetValidatorOutput, error) {
ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes(
attribute.Int64("height", int64(height)),
attribute.Stringer("subnetID", subnetID),
))
defer span.End()
return s.s.GetValidatorSet(ctx, height, subnetID)
}