Ejemplo n.º 1
0
// New constructs a new AirbrakeHandler.
//
// The projectId & key parameters should be obtained from airbrake. The
// environment parameter is the name of the environment to report errors under.
func New(projectId int64, key string, environment string) *AirbrakeHandler {
	repoRoot, _, repoVersion := util.RepoInfo()
	context := &AirbrakeContext{
		OS:            runtime.GOOS + " " + runtime.GOARCH, //TODO syscall.Uname() when in linux
		Language:      "go " + runtime.Version(),
		Environment:   environment,
		RootDirectory: repoRoot,
		Version:       repoVersion,
	}

	env := map[string]string{}
	env["_"] = os.Args[0]
	env["GOVERSION"] = runtime.Version()
	env["GOMAXPROCS"] = fmt.Sprintf("%d", runtime.GOMAXPROCS(0))
	env["GOROOT"] = runtime.GOROOT()
	env["HOSTNAME"], _ = os.Hostname()

	aURL, _ := url.Parse(fmt.Sprintf("%s/api/v3/projects/%d/notices?key=%s", airbrakeURL, projectId, key))
	return &AirbrakeHandler{
		AirbrakeURL: aURL,
		projectId:   projectId,
		key:         key,
		Context:     context,
		Env:         env,
	}
}
Ejemplo n.º 2
0
// New constructs a new Sentry handler.
//
// The DSN is provided by the Sentry service.
func New(dsn string) (*Sentry, error) {
	client, err := raven.NewClient(dsn, map[string]string{})
	if err != nil {
		return nil, err
	}

	repoRoot, repoRevision, repoTag := util.RepoInfo()
	client.SetRelease(repoTag)
	if repoRevision != "" {
		client.Tags["revision"] = repoRevision
	}

	// generate a random value to use as the ID prefix.
	// We want to use a common prefix for all events from this handler.
	prefix := rand.New(rand.NewSource(time.Now().UnixNano())).Int63()

	return &Sentry{
		idPrefix:     strconv.FormatInt(prefix, 36) + ".",
		repoRoot:     repoRoot,
		repoRevision: repoRevision,
		repoTag:      repoTag,
		client:       client,
	}, nil
}