airbrake

package
v0.0.0-...-e2451da Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2015 License: MIT Imports: 12 Imported by: 0

README

The airbrake handler provides a handler for sawmill which sends events to the airbrake service.

Example usage:

package main

import (
	"os"
	"strings"

	"github.com/phemmer/sawmill"
	"github.com/phemmer/sawmill/handler/airbrake"
)

func main() {
	defer sawmill.Stop()
	sawmill.SetStackMinLevel(sawmill.ErrorLevel)

	a := airbrake.New(123456, "0123456789abcdef0123456789abcdef", "production")
	a.Context.URL = "http://myproject.example.com"
	// Add all environment variables.
	for _, envVar := range os.Environ() {
		envKP := strings.SplitN(envVar, "=", 2)
		a.Env[envKP[0]] = envKP[1]
	}
	filter := sawmill.FilterHandler(a).LevelMin(sawmill.ErrorLevel)
	sawmill.AddHandler("airbrake", filter)

	_, err := os.Create("/test")
	if err != nil {
		sawmill.Error("Failed to create /test", sawmill.Fields{"error": err, "path": "/test"})
	}
}

General

General


Backtrace

Backtrace


Params

Params


Env

Env


Context

Context

Documentation

Overview

The airbrake package provides a handler which sends events to the Airbrake error reporting service.

For a stack trace to be included, sawmill needs to be configured to gather them. E.G.:

logger.SetStackMinLevel(sawmill.ErrorLevel)

The handler sends all received events to the airbrake service. Thus it should most likely be used in combination with the filter handler (http://godoc.org/github.com/phemmer/sawmill/handler/filter).

Example
package main

import (
	"os"
	"strings"

	"github.com/phemmer/sawmill"
	"github.com/phemmer/sawmill/handler/airbrake"
)

func main() {
	sawmill.SetStackMinLevel(sawmill.ErrorLevel)

	a := airbrake.New(12345, "0123456789abcdef0123456789abcdef", "development")
	a.Context.URL = "http://myproject.example.com"
	// Add all environment variables.
	for _, envVar := range os.Environ() {
		envKP := strings.SplitN(envVar, "=", 2)
		a.Env[envKP[0]] = envKP[1]
	}
	filter := sawmill.FilterHandler(a).LevelMin(sawmill.ErrorLevel)
	sawmill.AddHandler("airbrake", filter)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AirbrakeContext

type AirbrakeContext struct {
	OS          string `json:"os"`
	Language    string `json:"language"`
	Environment string `json:"environment"`
	Version     string `json:"version"`
	URL         string `json:"url"`

	// RootDirectory should be the project directory. This is normally
	// automatically deteremined.
	// If airbrake is integrated with your version control system (github), it
	// will generate links for you by stripping the RootDirectory from the
	// backtrace path, and adding it to the VCS repo URL.
	RootDirectory string `json:"rootDirectory"`
	UserId        string `json:"userId"`
	UserName      string `json:"userName"`
	UserEmail     string `json:"userEmail"`
}

type AirbrakeHandler

type AirbrakeHandler struct {
	sync.Mutex

	// AirbrakeURL is the base URL for the airbrake service
	// (e.g. https://airbrake.io).
	AirbrakeURL *url.URL

	// Context contains the fields which show up under the "context" section of
	// airbrake.
	// Some fields are automatically populated:
	//  * OS - Obtained from GOOS & GOARCH.
	//  * Language - "go" & the go compiler version.
	//  * Environment - The 'environment' parameter passed to New().
	//  * RootDirectory - The VCS repo root of the caller of New().
	//  * Version - The tag or commit of the caller's repo (git only).
	Context *AirbrakeContext

	// Env is an arbitrary mapping of environmental variables.
	// For security reasons, the OS environment variables are not copied.
	// Instead a few common variables are provided instead.
	//  * _ - The name of the process
	//  * GOVERSION - The go compiler version
	//  * GOMAXPROCS - The value of GOMAXPROCS at the time of New()
	//  * GOROOT - The value of GOROOT
	//  * HOSTNAME - The system's host name
	// Values may be added or removed.
	Env map[string]string
	// contains filtered or unexported fields
}

AirbrakeHandler implements the sawmill.Handler interface.

Modifying attributes after adding to a logger should be performed only after calling AirbrakeHandler.Lock() (and Unlock() after complete). However before being added to a sawmill logger, attributes may be modified without locking.

func New

func New(projectId int64, key string, environment string) *AirbrakeHandler

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 (*AirbrakeHandler) Event

func (ah *AirbrakeHandler) Event(logEvent *event.Event) error

Event processes a sawmill event, and sends it to the airbrake service.

Jump to

Keyboard shortcuts

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