Skip to content

Commit

Permalink
Add EventTracerDisabled (#127)
Browse files Browse the repository at this point in the history
* No more printing to the screen
  • Loading branch information
tedsuo committed Oct 30, 2017
1 parent b99ffd2 commit 2e9e05f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
21 changes: 21 additions & 0 deletions events.go
Expand Up @@ -306,3 +306,24 @@ func (e *eventUnsupportedValue) Error() string {
func (e *eventUnsupportedValue) Err() error {
return e.err
}

const tracerDisabled = "the tracer has been disabled"

// EventTracerDisabled occurs when a tracer is disabled by either the user or
// the collector.
type EventTracerDisabled interface {
Event
EventTracerDisabled()
}

type eventTracerDisabled struct{}

func newEventTracerDisabled() EventTracerDisabled {
return eventTracerDisabled{}
}

func (eventTracerDisabled) Event() {}
func (eventTracerDisabled) EventTracerDisabled() {}
func (eventTracerDisabled) String() string {
return tracerDisabled
}
11 changes: 5 additions & 6 deletions tracer.go
Expand Up @@ -302,16 +302,15 @@ func (tracer *tracerImpl) postFlush(flushEventError *eventFlushError) *eventStat

func (tracer *tracerImpl) Disable() {
tracer.lock.Lock()
defer tracer.lock.Unlock()

if tracer.disabled {
tracer.lock.Unlock()
return
}

fmt.Printf("Disabling Runtime instance: %p", tracer)

tracer.buffer.clear()
tracer.disabled = true
tracer.buffer.clear()
tracer.lock.Unlock()

emitEvent(newEventTracerDisabled())
}

// Every MinReportingPeriod the reporting loop wakes up and checks to see if
Expand Down
1 change: 1 addition & 0 deletions tracer_test.go
Expand Up @@ -106,6 +106,7 @@ var _ = Describe("Tracer", func() {
Context("when the tracer is disabled", func() {
JustBeforeEach(func() {
tracer.Disable()
Eventually(eventChan).Should(Receive())
})

It("should not flush spans", func() {
Expand Down

0 comments on commit 2e9e05f

Please sign in to comment.