-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
40 lines (36 loc) · 1.13 KB
/
trace.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
package hbase
import (
"context"
"io"
"github.com/tsuna/gohbase/hrpc"
"github.com/peterlearn/kratos/pkg/net/trace"
)
// TraceHook create new hbase trace hook.
func TraceHook(component, instance string) HookFunc {
var internalTags []trace.Tag
internalTags = append(internalTags, trace.TagString(trace.TagComponent, component))
internalTags = append(internalTags, trace.TagString(trace.TagDBInstance, instance))
internalTags = append(internalTags, trace.TagString(trace.TagPeerService, "hbase"))
internalTags = append(internalTags, trace.TagString(trace.TagSpanKind, "client"))
return func(ctx context.Context, call hrpc.Call, customName string) func(err error) {
noop := func(error) {}
root, ok := trace.FromContext(ctx)
if !ok {
return noop
}
if customName == "" {
customName = call.Name()
}
span := root.Fork("", "Hbase:"+customName)
span.SetTag(internalTags...)
statement := string(call.Table()) + " " + string(call.Key())
span.SetTag(trace.TagString(trace.TagDBStatement, statement))
return func(err error) {
if err == io.EOF {
// reset error for trace.
err = nil
}
span.Finish(&err)
}
}
}