Skip to content

Commit

Permalink
Merge pull request #102 from rollbar/pawel/closing_default_client
Browse files Browse the repository at this point in the history
added the function to disable default client
  • Loading branch information
pawelsz-rb committed Sep 27, 2022
2 parents 54913f7 + f057587 commit ed38c7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rollbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func SetTelemetry(options ...OptionFunc) {
std.SetTelemetry(options...)
}

func DisableDefaultClient(destroy bool) {
if destroy {
std = nil
return
}
std.SetEnabled(false)
std.Close()
}

// CaptureTelemetryEvent sets the user-specified telemetry event
func CaptureTelemetryEvent(eventType, eventlevel string, eventData map[string]interface{}) {
std.CaptureTelemetryEvent(eventType, eventlevel, eventData)
Expand Down
23 changes: 23 additions & 0 deletions rollbar_closed_channel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package rollbar

import (
"testing"
)

func TestDisableDefaultClient(t *testing.T) {
defer func() {
std = NewAsync("", "development", "", hostname, "")

}()
DisableDefaultClient(false)
err := std.push(map[string]interface{}{
"data": map[string]interface{}{},
})
if err == nil {
t.Error("error should indicate that channel is closed")
}
DisableDefaultClient(true)
if std != nil {
t.Error("error should indicate that std is nil")
}
}

0 comments on commit ed38c7c

Please sign in to comment.