mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* update vendor directory, add go.opencensus.io * update imports * oops * s/opentracing/opencensus/ & remove prometheus / zipkin stuff & remove old stats * the dep train rides again * fix gin build * deps from last guy * start in on the agent metrics * she builds * remove tags for now, cardinality error is fussing. subscribe instead of register * update to patched version of opencensus to proceed for now TODO switch to a release * meh fix imports * println debug the bad boys * lace it with the tags * update deps again * fix all inconsistent cardinality errors * add our own logger * fix init * fix oom measure * remove bugged removal code * fix s3 measures * fix prom handler nil
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package zipkin
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/openzipkin/zipkin-go/model"
|
|
)
|
|
|
|
type spanImpl struct {
|
|
mtx sync.RWMutex
|
|
model.SpanModel
|
|
tracer *Tracer
|
|
mustCollect int32 // used as atomic bool (1 = true, 0 = false)
|
|
flushOnFinish bool
|
|
}
|
|
|
|
func (s *spanImpl) Context() model.SpanContext {
|
|
return s.SpanContext
|
|
}
|
|
|
|
func (s *spanImpl) SetName(name string) {
|
|
s.mtx.Lock()
|
|
s.Name = name
|
|
s.mtx.Unlock()
|
|
}
|
|
|
|
func (s *spanImpl) SetRemoteEndpoint(e *model.Endpoint) {
|
|
s.mtx.Lock()
|
|
if e == nil {
|
|
s.RemoteEndpoint = nil
|
|
} else {
|
|
s.RemoteEndpoint = &model.Endpoint{}
|
|
*s.RemoteEndpoint = *e
|
|
}
|
|
s.mtx.Unlock()
|
|
}
|
|
|
|
func (s *spanImpl) Annotate(t time.Time, value string) {
|
|
a := model.Annotation{
|
|
Timestamp: t,
|
|
Value: value,
|
|
}
|
|
|
|
s.mtx.Lock()
|
|
s.Annotations = append(s.Annotations, a)
|
|
s.mtx.Unlock()
|
|
}
|
|
|
|
func (s *spanImpl) Tag(key, value string) {
|
|
s.mtx.Lock()
|
|
|
|
if key == string(TagError) {
|
|
if _, found := s.Tags[key]; found {
|
|
s.mtx.Unlock()
|
|
return
|
|
}
|
|
}
|
|
|
|
s.Tags[key] = value
|
|
s.mtx.Unlock()
|
|
}
|
|
|
|
func (s *spanImpl) Finish() {
|
|
if atomic.CompareAndSwapInt32(&s.mustCollect, 1, 0) {
|
|
s.Duration = time.Since(s.Timestamp)
|
|
if s.flushOnFinish {
|
|
s.tracer.reporter.Send(s.SpanModel)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *spanImpl) Flush() {
|
|
if s.SpanModel.Debug || (s.SpanModel.Sampled != nil && *s.SpanModel.Sampled) {
|
|
s.tracer.reporter.Send(s.SpanModel)
|
|
}
|
|
}
|