Skip to content

Commit

Permalink
Merge branch 'main' into julien/flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Dec 5, 2023
2 parents 846c340 + d6595bd commit d650258
Show file tree
Hide file tree
Showing 38 changed files with 1,295 additions and 404 deletions.
9 changes: 0 additions & 9 deletions ignite/cmd/ignite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ func main() {
func run() int {
const exitCodeOK, exitCodeError = 0, 1
var wg sync.WaitGroup

defer func() {
if r := recover(); r != nil {
analytics.SendMetric(&wg, os.Args, analytics.WithError(fmt.Errorf("%v", r)))
fmt.Println(r)
os.Exit(exitCodeError)
}
}()

if len(os.Args) > 1 {
analytics.SendMetric(&wg, os.Args)
}
Expand Down
48 changes: 8 additions & 40 deletions ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,25 @@ const (

var gaclient gacli.Client

type (
// metric represents an analytics metric.
options struct {
// err sets metrics type as an error metric.
err error
}

// anonIdentity represents an analytics identity file.
anonIdentity struct {
// name represents the username.
Name string `json:"name" yaml:"name"`
// doNotTrack represents the user track choice.
DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"`
}
)
// anonIdentity represents an analytics identity file.
type anonIdentity struct {
// name represents the username.
Name string `json:"name" yaml:"name"`
// doNotTrack represents the user track choice.
DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"`
}

func init() {
gaclient = gacli.New(telemetryEndpoint)
}

// Option configures ChainCmd.
type Option func(*options)

// WithError with application command error.
func WithError(error error) Option {
return func(m *options) {
m.err = error
}
}

// SendMetric send command metrics to analytics.
func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) {
func SendMetric(wg *sync.WaitGroup, args []string) {
// only the app name
if len(args) <= 1 {
return
}

// apply analytics options.
var opt options
for _, o := range opts {
o(&opt)
}

if args[1] == "version" {
return
}
Expand All @@ -83,14 +59,6 @@ func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) {
SessionID: dntInfo.Name,
Version: version.Version,
}

switch {
case opt.err == nil:
met.Status = "success"
case opt.err != nil:
met.Status = "error"
met.Error = opt.err.Error()
}
met.Cmd = args[1]

wg.Add(1)
Expand Down
Loading

0 comments on commit d650258

Please sign in to comment.