Merge pull request #811 from ankitnayan/fix/na-telemetry

fix: set userId as distinctId if failed to fetch IP
This commit is contained in:
Ankit Nayan 2022-03-03 18:14:58 +05:30 committed by GitHub
commit 46aaa8199d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ const (
) )
const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz" const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz"
const IP_NOT_FOUND_PLACEHOLDER = "NA"
var telemetry *Telemetry var telemetry *Telemetry
var once sync.Once var once sync.Once
@ -59,7 +60,7 @@ func createTelemetry() {
// Get preferred outbound ip of this machine // Get preferred outbound ip of this machine
func getOutboundIP() string { func getOutboundIP() string {
ip := []byte("NA") ip := []byte(IP_NOT_FOUND_PLACEHOLDER)
resp, err := http.Get("https://api.ipify.org?format=text") resp, err := http.Get("https://api.ipify.org?format=text")
if err != nil { if err != nil {
@ -116,7 +117,7 @@ func (a *Telemetry) SendEvent(event string, data map[string]interface{}) {
} }
userId := a.ipAddress userId := a.ipAddress
if a.isTelemetryAnonymous() { if a.isTelemetryAnonymous() || userId == IP_NOT_FOUND_PLACEHOLDER {
userId = a.GetDistinctId() userId = a.GetDistinctId()
} }