-
Notifications
You must be signed in to change notification settings - Fork 661
/
traced_engine.go
42 lines (32 loc) · 996 Bytes
/
traced_engine.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
// Copyright (C) 2019-2023, 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/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/trace"
)
var _ Engine = (*tracedEngine)(nil)
type tracedEngine struct {
common.Engine
engine Engine
tracer trace.Tracer
}
func TraceEngine(engine Engine, tracer trace.Tracer) Engine {
return &tracedEngine{
Engine: common.TraceEngine(engine, tracer),
engine: engine,
tracer: tracer,
}
}
func (e *tracedEngine) GetBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error) {
ctx, span := e.tracer.Start(ctx, "tracedEngine.GetBlock", oteltrace.WithAttributes(
attribute.Stringer("blkID", blkID),
))
defer span.End()
return e.engine.GetBlock(ctx, blkID)
}