-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
57 lines (45 loc) · 853 Bytes
/
util.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
package tracing
import (
"context"
"runtime"
oteltrace "go.opentelemetry.io/otel/trace"
)
type errorHandler struct{}
// Handle default error handler when span send failed
func (errorHandler) Handle(err error) {
logs.Err(err).Msg("tracer exporter error")
}
const (
KeyErrMsg = "err_msg"
)
// SetIfErr add error info
func SetIfErr(span oteltrace.Span, err error) {
if span == nil || err == nil {
return
}
span.RecordError(err)
}
// SetIfCtxErr record context error
func SetIfCtxErr(span oteltrace.Span, ctx context.Context) {
if span == nil || ctx == nil {
return
}
err := ctx.Err()
if err == nil {
return
}
SetIfErr(span, err)
span.SpanContext()
}
func queueSize() int {
const min = 1000
const max = 16000
n := (runtime.GOMAXPROCS(0) / 2) * 1000
if n < min {
return min
}
if n > max {
return max
}
return n
}