Skip to content

Commit

Permalink
Merge pull request #616 from onflow/bugfix/remove-sentry-exception
Browse files Browse the repository at this point in the history
Remove sentry capture exception from mixpanel
  • Loading branch information
sukantoraymond authored Aug 12, 2022
2 parents aa3fd26 + 431fb08 commit 441bf42
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 59 deletions.
11 changes: 1 addition & 10 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,7 @@ func (c Command) handleUserTracking() {
if util.MIXPANEL_SERVICE_ACCOUNT_SECRET == "" || util.MIXPANEL_PROJECT_TOKEN == "" {
return
}
optedIn, err := util.IsUserOptedIn()
if err != nil {
sentry.CaptureException(err)
}
if optedIn {
err = util.TrackCommandUsage(c.Cmd)
if err != nil {
sentry.CaptureException(err)
}
}
_ = util.TrackCommandUsage(c.Cmd)
}

// AddToParent add new command to main parent cmd
Expand Down
49 changes: 0 additions & 49 deletions pkg/flowkit/util/mixpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"github.com/spf13/cobra"
"io/ioutil"
"net/http"
"net/url"
"strings"
)

const (
Expand Down Expand Up @@ -124,50 +122,3 @@ type MixPanelResponse struct {
} `json:"$properties"`
} `json:"results"`
}

//User is opted in by default
//If distinct id can't be found through query api, return true to reflect that user is opted in
func IsUserOptedIn() (bool, error) {
distinctId, err := generateNewDistinctId()
if err != nil {
return false, err
}

queryPayload := "distinct_id=" + url.QueryEscape(distinctId)
payload := strings.NewReader(queryPayload)
req, err := http.NewRequest("POST", MIXPANEL_QUERY_URL, payload)
if err != nil {
return false, err
}

mixpanelAuth := "Basic " + MIXPANEL_SERVICE_ACCOUNT_SECRET
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", mixpanelAuth)

res, err := http.DefaultClient.Do(req)
if err != nil {
return false, err
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)

var queryResponse MixPanelResponse
err = json.Unmarshal(body, &queryResponse)

if err != nil {
return false, err
}
if res.StatusCode >= 400 {
if res.StatusCode == 429 {
//tracking is enabled by default if there is rate limit error from mixpanel
return true, nil
}
return false, fmt.Errorf("invalid response status code %d for tracking command usage", res.StatusCode)
}
if len(queryResponse.Results) == 0 {
return true, nil
}
return queryResponse.Results[0].Properties.OptIn, nil
}

0 comments on commit 441bf42

Please sign in to comment.