Close shutdowns all tracing sessions orderly. Firstly, the buffers are flushed. Then, the trace is closed to signal the event callback to stop consuming more events. Finally, the trace is stopped along with all event consumers.
()
| 299 | // signal the event callback to stop consuming more events. |
| 300 | // Finally, the trace is stopped along with all event consumers. |
| 301 | func (e *EventSource) Close() error { |
| 302 | if e.isClosed { |
| 303 | return nil |
| 304 | } |
| 305 | |
| 306 | for _, consumer := range e.consumers { |
| 307 | if err := consumer.Close(); err != nil { |
| 308 | log.Warnf("couldn't close consumer: %v", err) |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | for _, trace := range e.traces { |
| 313 | if !trace.IsStarted() { |
| 314 | continue |
| 315 | } |
| 316 | if err := trace.Flush(); err != nil { |
| 317 | log.Warnf("couldn't flush trace session for [%s]: %v", trace.Name, err) |
| 318 | } |
| 319 | time.Sleep(time.Millisecond * 150) |
| 320 | if err := trace.Close(); err != nil { |
| 321 | log.Warnf("couldn't close trace session for [%s]: %v", trace.Name, err) |
| 322 | } |
| 323 | time.Sleep(time.Millisecond * 250) |
| 324 | if err := trace.Stop(); err != nil { |
| 325 | log.Warnf("couldn't stop trace session for [%s]: %v", trace.Name, err) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | close(e.stop) |
| 330 | |
| 331 | e.isClosed = true |
| 332 | |
| 333 | return e.sequencer.Shutdown() |
| 334 | } |
| 335 | |
| 336 | // Errors returns the channel where errors are published. |
| 337 | func (e *EventSource) Errors() <-chan error { |