lightstep / lightstep-tracer-go

The Lightstep distributed tracing library for Go
https://lightstep.com
MIT License
98 stars 53 forks source link

expose a method to close and drain the reporting loop #56

Closed aybabtme closed 7 years ago

aybabtme commented 8 years ago

I'd like to have a method to tell the tracer "no more spans are coming, please try to send all the spans you have buffered". Something like Flush but that blocks until the reporting buffer is drained.

The FlushLightStepTracer call sorts of does that, but it does not block and may leave unreported spans in memory. For instance, if I call it when a report is already in flight, the function will return immediately. This means I can't block on the background flush to finish. The Close() function on the Recorder also does not drain the buffer queue.

Maybe something like:

func (tr *Tracer) DrainAndClose(ctx context.Context) error { 
    // try draining the queue until `<-ctx.Done()`
}

Here the context.Context is so that I can timeout waiting on the drain to finish.

Use case

The use case for this is for short-lived commands to be able to try and emit their spans before os.Exit'ing.

aybabtme commented 8 years ago

I'm happy to have a shot at this, btw. I'm opening this issue to see if there's interest.

yurishkuro commented 8 years ago

fwiw Jaeger's tracer.Close() method behaves exactly like that, it blocks until the memory buffer is flushed.

tedsuo commented 7 years ago

This is a duplicate of https://github.com/lightstep/lightstep-tracer-go/issues/82, plese comment there or on the associated PR if you'd like to review.