Skip to content

Commit

Permalink
Prevent segment from writing to console (especially for pi-hole), fixes
Browse files Browse the repository at this point in the history
#1968, fixes #1767, fixes #1967 (#2497)

Also adds architecture into segment reporting.
  • Loading branch information
rfay committed Sep 11, 2020
1 parent 617c414 commit cad94dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/ddev/cmd/root.go
Expand Up @@ -191,7 +191,9 @@ func checkDdevVersionAndOptInInstrumentation() error {
allowStats := util.Confirm("It looks like you have a new ddev release.\nMay we send anonymous ddev usage statistics and errors?\nTo know what we will see please take a look at\nhttps://ddev.readthedocs.io/en/stable/users/cli-usage/#opt-in-usage-information\nPermission to beam up?")
if allowStats {
globalconfig.DdevGlobalConfig.InstrumentationOptIn = true
client := analytics.New(version.SegmentKey)
client, _ := analytics.NewWithConfig(version.SegmentKey, analytics.Config{
Logger: &ddevapp.SegmentNoopLogger{},
})
defer func() {
_ = client.Close()
}()
Expand Down
11 changes: 10 additions & 1 deletion pkg/ddevapp/instrumentation.go
Expand Up @@ -21,6 +21,12 @@ import (

var hashedHostID string

// Define a no-op logger to prevent Segment log messages from being emitted
type SegmentNoopLogger struct{}

func (n *SegmentNoopLogger) Logf(format string, args ...interface{}) {}
func (n *SegmentNoopLogger) Errorf(format string, args ...interface{}) {}

// ReportableEvents is the list of events that we choose to report specifically.
// Excludes non-ddev custom commands.
var ReportableEvents = map[string]bool{"auth": true, "composer": true, "config": true, "debug": true, "delete": true, "describe": true, "exec": true, "export-db": true, "import-db": true, "import-files": true, "launch": true, "list": true, "logs": true, "mysql": true, "pause": true, "poweroff": true, "pull": true, "restart": true, "restore-snapshot": true, "sequelace": true, "sequelpro": true, "share": true, "snapshot": true, "ssh": true, "start": true, "stop": true, "xdebug": true}
Expand All @@ -43,6 +49,7 @@ func SetInstrumentationBaseTags() {
lang := os.Getenv("LANG")

nodeps.InstrumentationTags["OS"] = runtime.GOOS
nodeps.InstrumentationTags["architecture"] = runtime.GOARCH
wslDistro := nodeps.GetWSLDistro()
if wslDistro != "" {
nodeps.InstrumentationTags["isWSL"] = "true"
Expand Down Expand Up @@ -131,7 +138,9 @@ func SendInstrumentationEvents(event string) {
defer runTime()

if globalconfig.DdevGlobalConfig.InstrumentationOptIn && globalconfig.IsInternetActive() {
client := analytics.New(version.SegmentKey)
client, _ := analytics.NewWithConfig(version.SegmentKey, analytics.Config{
Logger: &SegmentNoopLogger{},
})

err := SegmentEvent(client, GetInstrumentationUser(), event)
if err != nil {
Expand Down

0 comments on commit cad94dd

Please sign in to comment.