Help us shape the future of Go! Take the 2026 Go Developer Survey

bugsnag

package module
v0.0.0-...-58e3c78 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: BSD-3-Clause Imports: 11 Imported by: 1

README

DEPRECATED

This project is deprecated, given that it wasn't being maintained for a few years and references to it were removed in 2021.


About

bugsnag client in Go

Please see https://bugsnag.com/docs/notifier-api for more info about the bugsnag API.

How to use

package main

import (
        "errors"
        "net/http"
        "github.com/toggl/bugsnag"
)

func main() {
        // First, configure bugsnag. Only APIKey is mandatory, other settings are optional.
        bugsnag.APIKey = "c9d60ae4c7e70c4b6c4ebd3e8056d2b8"

        bugsnag.AppVersion = "1.0.2"
        bugsnag.OSVersion = "Windows XP"
        bugsnag.ReleaseStage = "production"
        bugsnag.NotifyReleaseStages = []string{"production"}
        bugsnag.UseSSL = true
        bugsnag.Verbose = true

        // Then, out of the blue, an error happens:
        err := errors.New("Something bad just happened")
        bugsnag.Notify(err)

        // In case you need to supply the user ID:
        bugsnag.New(err).WithUserID("12345").Notify()

        // To report what your app was doing while error happened:
        bugsnag.New(err).WithContext("something").Notify()

        // Metadata can be set all at once:
        values := map[string]interface{}{
                "user_agent": "ie4",
                "account_id": 5555,
        }
        bugsnag.New(err).WithMetaDataValues("tab_name_in_bugsnag", values).Notify()

        // Or one key-value pair at a time:
        bugsnag.New(err).WithMetaData("tab_name_in_bugsnag", "user_agent", "ie4").WithMetaData("tab_name_in_bugsnag", "account_id", 5555).Notify()

        r, _ := http.NewRequest("GET", "http://google.com", nil)

        // To notify about a HTTP handler error:
        bugsnag.NotifyRequest(err, r)

        // To capture a HTTP handler panic, add this to your handler (assuming r is a *http.Request):
        defer bugsnag.CapturePanic(r)

        // If you need to add some error details when a panic is captured:
        defer bugsnag.OnCapturePanic(r, func(event bugsnag.EventDescriber) {
                event.WithMetaData("tab_name_in_bugsnag", "foo", "bar")
        })
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	APIKey              string
	AppVersion          string
	OSVersion           string
	Hostname            string
	WorkingDir          string
	ReleaseStage        = "production"
	NotifyReleaseStages = []string{ReleaseStage}
	AutoNotify          = true
	UseSSL              = true
	Verbose             = false
	Notifier            = &bugsnagNotifier{
		Name:    "Bugsnag Go client",
		Version: "0.0.2",
		URL:     "https://github.com/toggl/bugsnag_client",
	}
)

Functions

func CapturePanic

func CapturePanic(r *http.Request)

CapturePanic reports panics happening while processing a HTTP request

func Error

func Error(err error) error

func New

func New(err error) *bugsnagEvent

New returns returns a bugsnag event instance, that can be further configured before sending it.

func NewWithSkipFrames

func NewWithSkipFrames(err error, skipFrames int) *bugsnagEvent

New returns returns a bugsnag event instance, that can be further configured before sending it.

func Notify

func Notify(err error) error

Notify sends an error to bugsnag

func NotifyRequest

func NotifyRequest(err error, r *http.Request) error

NotifyRequest sends an error to bugsnag, and sets request URL as the event context.

func OnCapturePanic

func OnCapturePanic(r *http.Request, handler func(event EventDescriber))

OnCapturePanic allows to set bugsnag variables before the error is sent off after a HTTP request handler panicked.

Types

type EventDescriber

type EventDescriber interface {
	WithUserID(userID string) *bugsnagEvent
	WithContext(context string) *bugsnagEvent
	WithMetaDataValues(tab string, values map[string]interface{}) *bugsnagEvent
	WithMetaData(tab string, name string, value interface{}) *bugsnagEvent
}

EventDescriber is the public interface of a bugsnag event

Jump to

Keyboard shortcuts

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