use *pb.TraceEvent as argument for Trace in the EventTracer interface
This commit is contained in:
parent
f134d65848
commit
0aa629c79c
2
trace.go
2
trace.go
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
// Generic event tracer interface
|
// Generic event tracer interface
|
||||||
type EventTracer interface {
|
type EventTracer interface {
|
||||||
Trace(evt interface{})
|
Trace(evt *pb.TraceEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pubsub tracer details
|
// pubsub tracer details
|
||||||
|
|
10
tracer.go
10
tracer.go
|
@ -14,10 +14,10 @@ import (
|
||||||
type basicTracer struct {
|
type basicTracer struct {
|
||||||
ch chan struct{}
|
ch chan struct{}
|
||||||
mx sync.Mutex
|
mx sync.Mutex
|
||||||
buf []interface{}
|
buf []*pb.TraceEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *basicTracer) Trace(evt interface{}) {
|
func (t *basicTracer) Trace(evt *pb.TraceEvent) {
|
||||||
t.mx.Lock()
|
t.mx.Lock()
|
||||||
t.buf = append(t.buf, evt)
|
t.buf = append(t.buf, evt)
|
||||||
t.mx.Unlock()
|
t.mx.Unlock()
|
||||||
|
@ -57,7 +57,7 @@ func OpenJSONTracer(file string, flags int, perm os.FileMode) (*JSONTracer, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *JSONTracer) doWrite() {
|
func (t *JSONTracer) doWrite() {
|
||||||
var buf []interface{}
|
var buf []*pb.TraceEvent
|
||||||
enc := json.NewEncoder(t.w)
|
enc := json.NewEncoder(t.w)
|
||||||
for {
|
for {
|
||||||
_, ok := <-t.ch
|
_, ok := <-t.ch
|
||||||
|
@ -109,7 +109,7 @@ func OpenPBTracer(file string, flags int, perm os.FileMode) (*PBTracer, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *PBTracer) doWrite() {
|
func (t *PBTracer) doWrite() {
|
||||||
var buf []interface{}
|
var buf []*pb.TraceEvent
|
||||||
w := ggio.NewDelimitedWriter(t.w)
|
w := ggio.NewDelimitedWriter(t.w)
|
||||||
for {
|
for {
|
||||||
_, ok := <-t.ch
|
_, ok := <-t.ch
|
||||||
|
@ -121,7 +121,7 @@ func (t *PBTracer) doWrite() {
|
||||||
t.mx.Unlock()
|
t.mx.Unlock()
|
||||||
|
|
||||||
for i, evt := range buf {
|
for i, evt := range buf {
|
||||||
err := w.WriteMsg(evt.(*pb.TraceEvent))
|
err := w.WriteMsg(evt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error writing event trace: %s", err.Error())
|
log.Errorf("error writing event trace: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue