trace Read endpoint
This commit is contained in:
parent
eeb6944ce5
commit
8d2dc8a822
@ -16,7 +16,25 @@ type trace struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *trace) Read(opts ...ReadOption) ([]*Span, error) {
|
func (t *trace) Read(opts ...ReadOption) ([]*Span, error) {
|
||||||
return []*Span{}, nil
|
var options ReadOptions
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
|
||||||
|
sp := t.buffer.Get(t.buffer.Size())
|
||||||
|
|
||||||
|
var spans []*Span
|
||||||
|
|
||||||
|
for _, span := range sp {
|
||||||
|
val := span.Value.(*Span)
|
||||||
|
// skip if trace id is specified and doesn't match
|
||||||
|
if len(options.Trace) > 0 && val.Trace != options.Trace {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
spans = append(spans, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return spans, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *trace) Start(ctx context.Context, name string) *Span {
|
func (t *trace) Start(ctx context.Context, name string) *Span {
|
||||||
@ -49,7 +67,7 @@ func (t *trace) Start(ctx context.Context, name string) *Span {
|
|||||||
|
|
||||||
func (t *trace) Finish(s *Span) error {
|
func (t *trace) Finish(s *Span) error {
|
||||||
// set finished time
|
// set finished time
|
||||||
s.Finished = time.Now()
|
s.Duration = time.Since(s.Started)
|
||||||
|
|
||||||
// save the span
|
// save the span
|
||||||
t.buffer.Put(s)
|
t.buffer.Put(s)
|
||||||
|
@ -10,3 +10,10 @@ type ReadOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ReadOption func(o *ReadOptions)
|
type ReadOption func(o *ReadOptions)
|
||||||
|
|
||||||
|
// Read the given trace
|
||||||
|
func ReadTrace(t string) ReadOption {
|
||||||
|
return func(o *ReadOptions) {
|
||||||
|
o.Trace = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -28,8 +28,8 @@ type Span struct {
|
|||||||
Parent string
|
Parent string
|
||||||
// Start time
|
// Start time
|
||||||
Started time.Time
|
Started time.Time
|
||||||
// Finish time
|
// Duration in nano seconds
|
||||||
Finished time.Time
|
Duration time.Duration
|
||||||
// associated data
|
// associated data
|
||||||
Metadata map[string]string
|
Metadata map[string]string
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user