gobrake

package module
v2.0.9+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2016 License: BSD-3-Clause Imports: 14 Imported by: 2

README

Airbrake Golang Notifier Build Status

Example

package main

import (
	"errors"

	"gopkg.in/airbrake/gobrake.v2"
)

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
})

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 {
	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 acts as SendNotice, but sends notice asynchronously and 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.

func (*Notifier) WaitAndClose

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

Deprecated. Use CloseTimeout instead.

type StackFrame

type StackFrame struct {
	File string `json:"file"`
	Line int    `json:"line"`
	Func string `json:"function"`
}

Jump to

Keyboard shortcuts

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