Skip to content

Commit

Permalink
Add optional real username for instrumentation (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jul 22, 2019
1 parent aabfe94 commit fdab57d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/ddevapp/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ import (

var hashedHostID string

// GetInstrumentationUser normally gets just the hashed hostID but if
// an explicit user is provided in global_config.yaml that will be prepended.
func GetInstrumentationUser() string {
userID := hashedHostID
if globalconfig.DdevGlobalConfig.InstrumentationUser != "" {
userID = globalconfig.DdevGlobalConfig.InstrumentationUser + "_" + hashedHostID
}
return userID
}

// SetInstrumentationBaseTags sets the basic always-used tags for Sentry/Raven/Segment
func SetInstrumentationBaseTags() {
if globalconfig.DdevGlobalConfig.InstrumentationOptIn {
Expand All @@ -29,7 +39,7 @@ func SetInstrumentationBaseTags() {
nodeps.InstrumentationTags["dockerComposeVersion"] = composeVersion
nodeps.InstrumentationTags["dockerToolbox"] = strconv.FormatBool(isToolbox)
nodeps.InstrumentationTags["version"] = version.VERSION
nodeps.InstrumentationTags["ServerHash"] = hashedHostID
nodeps.InstrumentationTags["ServerHash"] = GetInstrumentationUser()

// Add these tags to sentry/raven
raven.SetTagsContext(nodeps.InstrumentationTags)
Expand Down Expand Up @@ -95,12 +105,12 @@ func SendInstrumentationEvents(event string) {

client := analytics.New(version.SegmentKey)

err := SegmentUser(client, hashedHostID)
err := SegmentUser(client, GetInstrumentationUser())
if err != nil {
util.Warning("error sending hashedHostID to segment: %v", err)
}

err = SegmentEvent(client, hashedHostID, event)
err = SegmentEvent(client, GetInstrumentationUser(), event)
if err != nil {
util.Warning("error sending event to segment: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/globalconfig/global_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type GlobalConfig struct {
LastUsedVersion string `yaml:"last_used_version"`
ProjectList map[string]*ProjectInfo `yaml:"project_info"`
DeveloperMode bool `yaml:"developer_mode,omitempty"`
InstrumentationUser string `yaml:"instrumentation_user,omitempty"`
}

// GetGlobalConfigPath() gets the path to global config file
Expand Down

0 comments on commit fdab57d

Please sign in to comment.