gobrake

package module
v2.0.9 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: 21

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 added in v2.0.4

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 added in v2.0.4

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 added in v2.0.7

func (n *Notifier) Close() error

func (*Notifier) CloseTimeout added in v2.0.7

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 added in v2.0.4

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 added in v2.0.2

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 added in v2.0.4

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