tracer: update wrapper

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2023-09-01 08:41:23 +03:00
parent e724425ce2
commit fcc29f9eac
5 changed files with 104 additions and 53 deletions

View File

@@ -91,7 +91,9 @@ type SpanOptions struct {
}
// EventOptions contains event options
type EventOptions struct{}
type EventOptions struct {
Labels []interface{}
}
func WithSpanLabels(ls ...interface{}) options.Option {
return func(src interface{}) error {
@@ -110,6 +112,26 @@ func WithSpanLabels(ls ...interface{}) options.Option {
}
}
// 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 WithSpanKind(k SpanKind) options.Option {
return func(src interface{}) error {
return options.Set(src, k, ".Kind")