gobrake

package module
v3.3.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2017 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Airbrake Golang Notifier Build Status

Example

package main

import (
	"errors"

	"github.com/airbrake/gobrake"
)

var airbrake = gobrake.NewNotifier(1234567, "FIXME")

func init() {
	airbrake.AddFilter(func(notice *gobrake.Notice) *gobrake.Notice {
		notice.Context["environment"] = "production"
		return notice
	})
}

func main() {
	defer airbrake.Close()
	defer airbrake.NotifyOnPanic()

	airbrake.Notify(errors.New("operation failed"), nil)
}

Ignoring notices

airbrake.AddFilter(func(notice *gobrake.Notice) *gobrake.Notice {
	if notice.Context["environment"] == "development" {
		// Ignore notices in development environment.
		return nil
	}
	return notice
})

Setting severity

Severity allows categorizing how severe an error is. By default, it's set to error. To redefine severity, simply overwrite context/severity of a notice object. For example:

notice := airbrake.Notice("operation failed", nil, 3)
notice.Context["severity"] = "critical"
airbrake.Notify(notice, nil)

Logging

You can use glog fork to send your logs to Airbrake.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l *log.Logger)

Types

type Error

type Error struct {
	Type      string       `json:"type"`
	Message   string       `json:"message"`
	Backtrace []StackFrame `json:"backtrace"`
}

type Notice

type Notice struct {
	Id    string // id returned by SendNotice
	Error error  // error returned by SendNotice

	Errors  []Error                `json:"errors"`
	Context map[string]interface{} `json:"context"`
	Env     map[string]interface{} `json:"environment"`
	Session map[string]interface{} `json:"session"`
	Params  map[string]interface{} `json:"params"`
}

func NewNotice

func NewNotice(e interface{}, req *http.Request, depth int) *Notice

func (*Notice) String

func (n *Notice) String() string

type Notifier

type Notifier struct {
	// http.Client that is used to interact with Airbrake API.
	Client *http.Client
	// contains filtered or unexported fields
}

func NewNotifier

func NewNotifier(projectId int64, projectKey string) *Notifier

func (*Notifier) AddFilter

func (n *Notifier) AddFilter(fn filter)

AddFilter adds filter that can modify or ignore notice.

func (*Notifier) Close

func (n *Notifier) Close() error

func (*Notifier) CloseTimeout

func (n *Notifier) CloseTimeout(timeout time.Duration) error

CloseTimeout waits for pending requests to finish and then closes the notifier.

func (*Notifier) Flush

func (n *Notifier) Flush()

Flush waits for pending requests to finish.

func (*Notifier) Notice

func (n *Notifier) Notice(err interface{}, req *http.Request, depth int) *Notice

Notice returns Aibrake notice created from error and request. depth determines which call frame to use when constructing backtrace.

func (*Notifier) Notify

func (n *Notifier) Notify(e interface{}, req *http.Request)

Notify notifies Airbrake about the error.

func (*Notifier) NotifyOnPanic

func (n *Notifier) NotifyOnPanic()

NotifyOnPanic notifies Airbrake about the panic and should be used with defer statement.

func (*Notifier) SendNotice

func (n *Notifier) SendNotice(notice *Notice) (string, error)

SendNotice sends notice to Airbrake.

func (*Notifier) SendNoticeAsync

func (n *Notifier) SendNoticeAsync(notice *Notice)

SendNoticeAsync is like SendNotice, but sends notice asynchronously. Pending notices can be flushed with Flush.

func (*Notifier) SetHost

func (n *Notifier) SetHost(h string)

Sets Airbrake host name. Default is https://airbrake.io.

type StackFrame

type StackFrame struct {
	File string         `json:"file"`
	Line int            `json:"line"`
	Func string         `json:"function"`
	Code map[int]string `json:"code,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL