tracer: fix span options #160

Merged
vtolstov merged 2 commits from tracer into v3 2022-12-24 18:20:59 +03:00
3 changed files with 13 additions and 34 deletions
Showing only changes of commit 26a2d18766 - Show all commits

View File

@ -35,7 +35,7 @@ type noopSpan struct {
ctx context.Context ctx context.Context
tracer Tracer tracer Tracer
name string name string
labels []Label opts SpanOptions
} }
func (s *noopSpan) Finish(opts ...SpanOption) { func (s *noopSpan) Finish(opts ...SpanOption) {
@ -56,8 +56,8 @@ func (s *noopSpan) SetName(name string) {
s.name = name s.name = name
} }
func (s *noopSpan) SetLabels(labels ...Label) { func (s *noopSpan) SetLabels(labels ...interface{}) {
s.labels = labels s.opts.Labels = labels
} }
// NewTracer returns new memory tracer // NewTracer returns new memory tracer

View File

@ -3,7 +3,9 @@ package tracer
import "go.unistack.org/micro/v3/logger" import "go.unistack.org/micro/v3/logger"
// SpanOptions contains span option // SpanOptions contains span option
type SpanOptions struct{} type SpanOptions struct {
Labels []interface{}
}
// SpanOption func signature // SpanOption func signature
type SpanOption func(o *SpanOptions) type SpanOption func(o *SpanOptions)
@ -14,6 +16,12 @@ type EventOptions struct{}
// EventOption func signature // EventOption func signature
type EventOption func(o *EventOptions) type EventOption func(o *EventOptions)
func SpanLabels(labels ...interface{}) SpanOption {
return func(o *SpanOptions) {
o.Labels = labels
}
}
// Options struct // Options struct
type Options struct { type Options struct {
// Logger used for logging // Logger used for logging

View File

@ -30,34 +30,5 @@ type Span interface {
// SetName set the span name // SetName set the span name
SetName(name string) SetName(name string)
// SetLabels set the span labels // SetLabels set the span labels
SetLabels(labels ...Label) SetLabels(labels ...interface{})
}
type Label struct {
val interface{}
key string
}
func LabelAny(k string, v interface{}) Label {
return Label{key: k, val: v}
}
func LabelString(k string, v string) Label {
return Label{key: k, val: v}
}
func LabelInt(k string, v int) Label {
return Label{key: k, val: v}
}
func LabelInt64(k string, v int64) Label {
return Label{key: k, val: v}
}
func LabelFloat64(k string, v float64) Label {
return Label{key: k, val: v}
}
func LabelBool(k string, v bool) Label {
return Label{key: k, val: v}
} }