tracer: improve tracing wrapper
Some checks failed
lint / lint (pull_request) Failing after 1m28s
pr / test (pull_request) Failing after 2m40s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2023-09-01 15:25:25 +03:00
parent fcc29f9eac
commit d3f9078bec
2 changed files with 63 additions and 100 deletions

View File

@@ -2,11 +2,9 @@ package tracer
import (
"context"
"reflect"
"go.unistack.org/micro/v4/logger"
"go.unistack.org/micro/v4/options"
rutil "go.unistack.org/micro/v4/util/reflect"
)
type SpanStatus int
@@ -95,41 +93,12 @@ type EventOptions struct {
Labels []interface{}
}
func WithSpanLabels(ls ...interface{}) options.Option {
return func(src interface{}) error {
v, err := options.Get(src, ".Labels")
if err != nil {
return err
} else if rutil.IsZero(v) {
v = reflect.MakeSlice(reflect.TypeOf(v), 0, len(ls)).Interface()
}
cv := reflect.ValueOf(v)
for _, l := range ls {
reflect.Append(cv, reflect.ValueOf(l))
}
err = options.Set(src, cv, ".Labels")
return err
}
func WithEventLabels(labels ...interface{}) options.Option {
return options.Labels(labels...)
}
// EventOption func signature
type EventOption func(o *EventOptions)
func WithEventLabels(ls ...interface{}) options.Option {
return func(src interface{}) error {
v, err := options.Get(src, ".Labels")
if err != nil {
return err
} else if rutil.IsZero(v) {
v = reflect.MakeSlice(reflect.TypeOf(v), 0, len(ls)).Interface()
}
cv := reflect.ValueOf(v)
for _, l := range ls {
reflect.Append(cv, reflect.ValueOf(l))
}
err = options.Set(src, cv, ".Labels")
return err
}
func WithSpanLabels(labels ...interface{}) options.Option {
return options.Labels(labels...)
}
func WithSpanKind(k SpanKind) options.Option {