Exemple #1
0
// QOSEventSend sends an internal CLI event to segment for quality-of-service purposes.
// If the event is an error it also sends the error to rollbar, then displays the
// error to the user and exits non-zero.
func QOSEventSend(system, id string, ep QOSEventProperties) error {
	rollbar.Token = "8481f1ec73f549ce8b81711ca4fdf98a"
	rollbar.Environment = id

	segment := analytics.New("JcNCirASuqEvuWhL8K87JTsUkhY68jvX")

	props := map[string]interface{}{}

	if ep.Error != nil {
		props["error"] = ep.Error.Error()
		rollbar.Error(rollbar.ERR, ep.Error, &rollbar.Field{"id", id})
	}

	if ep.ValidationError != nil {
		props["validation_error"] = ep.ValidationError.Error()
	}

	if ep.AppType != "" {
		props["app_type"] = ep.AppType
	}

	if !ep.Start.IsZero() {
		props["elapsed"] = float64(time.Since(ep.Start).Nanoseconds()) / 1000000
	}

	err := segment.Track(&analytics.Track{
		Event:      system,
		UserId:     id,
		Properties: props,
	})
	if err != nil {
		rollbar.Error(rollbar.ERR, err, &rollbar.Field{"id", id})
	}

	err = segment.Close()
	if err != nil {
		rollbar.Error(rollbar.ERR, err, &rollbar.Field{"id", id})
	}

	if os.Getenv("ROLLBAR_TOKEN") != "" {
		rollbar.Wait()
	}

	if ep.ValidationError != nil {
		return ExitError(ep.ValidationError)
	}

	if ep.Error != nil {
		return ExitError(ep.Error)
	}

	return nil
}
Exemple #2
0
func handlePanic() {
	if rec := recover(); rec != nil {
		err, ok := rec.(error)
		if !ok {
			err = errors.New(rec.(string))
		}
		Errln("ERROR:", err)
		if Channel == "?" {
			debug.PrintStack()
		} else {
			rollbar.Error(rollbar.ERR, err, rollbarFields()...)
			rollbar.Wait()
		}
		Exit(1)
	}
}
Exemple #3
0
func wait() {
	rollbar.Wait()
}