github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/amplitude_project.go (about) 1 package ddevapp 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/ddev/ddev/pkg/amplitude" 8 "github.com/ddev/ddev/pkg/dockerutil" 9 "github.com/ddev/ddev/pkg/globalconfig" 10 "github.com/ddev/ddev/pkg/nodeps" 11 "github.com/ddev/ddev/third_party/ampli" 12 "github.com/denisbrodbeck/machineid" 13 ) 14 15 // ProtectedID returns the unique hash value for the project. 16 func (app *DdevApp) ProtectedID() string { 17 appID, _ := machineid.ProtectedID("ddev" + app.Name) 18 return appID 19 } 20 21 // TrackProject collects and tracks information about the project for instrumentation. 22 func (app *DdevApp) TrackProject() { 23 // defer util.TimeTrack()() 24 25 // Initialization is currently done before via init() func somewhere while 26 // creating the ddevapp. This should be cleaned up. 27 // TODO: Remove once clean up has done. 28 amplitude.InitAmplitude() 29 30 // Early exit if instrumentation is disabled. 31 if ampli.Instance.Disabled { 32 return 33 } 34 35 containersOmitted := app.GetOmittedContainers() 36 37 var services []string 38 containers, err := dockerutil.GetAppContainers(app.Name) 39 if err == nil { 40 for _, k := range containers { 41 serviceName := strings.TrimPrefix(k.Names[0], "/") 42 shortName := strings.Replace(serviceName, fmt.Sprintf("ddev-%s-", app.Name), "", 1) 43 services = append(services, shortName) 44 } 45 } 46 47 builder := ampli.Project.Builder(). 48 AddOns(GetInstalledAddonNames(app)). 49 Containers(services). 50 ContainersOmitted(containersOmitted). 51 FailOnHookFail(app.FailOnHookFail || app.FailOnHookFailGlobal). 52 Id(app.ProtectedID()). 53 NodejsVersion(app.NodeJSVersion). 54 PerformanceMode(app.GetPerformanceMode()). 55 PhpVersion(app.GetPhpVersion()). 56 ProjectType(app.GetType()). 57 RouterDisabled(IsRouterDisabled(app)). 58 WebserverType(app.GetWebserverType()) 59 60 if !nodeps.ArrayContainsString(containersOmitted, "db") { 61 builder. 62 DatabaseType(app.Database.Type). 63 DatabaseVersion(app.Database.Version) 64 } 65 66 if !IsRouterDisabled(app) { 67 builder.Router(globalconfig.DdevGlobalConfig.Router) 68 } 69 70 ampli.Instance.Project("", builder.Build(), amplitude.GetEventOptions()) 71 }