rollbar

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: MIT, Apache-2.0, MIT Imports: 14 Imported by: 1

README

rollbar

rollbar is a Golang Rollbar client that makes it easy to report errors to Rollbar with full stacktraces. Errors are sent to Rollbar asynchronously in a background goroutine.

Because Go's error type doesn't include stack information from when it was set or allocated, we use the stack information from where the error was reported.

Documentation

API docs on godoc.org

Usage

package main

import (
  "github.com/stvp/rollbar"
)

func main() {
  rollbar.Token = "MY_TOKEN"
  rollbar.Environment = "production" // defaults to "development"

  result, err := DoSomething()
  if err != nil {
    rollbar.Error(rollbar.ERR, err)
  }

  rollbar.Message("info", "Message body goes here")

  rollbar.Wait()
}

Running Tests

Set up a dummy project in Rollbar and pass the access token as an environment variable to go test:

TOKEN=f0df01587b8f76b2c217af34c479f9ea go test

And verify the reported errors manually in the Rollbar dashboard.

Contributors

A big thank you to everyone who has contributed pull requests and bug reports:

  • @kjk
  • @Soulou
  • @paulmach

Documentation

Index

Constants

View Source
const (
	NAME    = "go-rollbar"
	VERSION = "0.3.1"

	// Severity levels
	CRIT  = "critical"
	ERR   = "error"
	WARN  = "warning"
	INFO  = "info"
	DEBUG = "debug"

	FILTERED = "[FILTERED]"
)

Variables

View Source
var (
	// Rollbar access token. If this is blank, no errors will be reported to
	// Rollbar.
	Token = ""

	// All errors and messages will be submitted under this environment.
	Environment = "development"

	// Platform, default to OS, but could be change ('client' for instance)
	Platform = runtime.GOOS

	// API endpoint for Rollbar.
	Endpoint = "https://api.rollbar.com/api/1/item/"

	// Maximum number of errors allowed in the sending queue before we start
	// dropping new errors on the floor.
	Buffer = 1000

	// Filter GET and POST parameters from being sent to Rollbar.
	FilterFields = regexp.MustCompile("password|secret|token")

	// Output of error, by default stderr
	ErrorWriter = os.Stderr
)

Functions

func Error

func Error(level string, err error, fields ...*Field)

Error asynchronously sends an error to Rollbar with the given severity level. You can pass, optionally, custom Fields to be passed on to Rollbar.

func ErrorWithStack

func ErrorWithStack(level string, err error, stack Stack, fields ...*Field)

ErrorWithStack asynchronously sends and error to Rollbar with the given stacktrace and (optionally) custom Fields to be passed on to Rollbar.

func ErrorWithStackSkip

func ErrorWithStackSkip(level string, err error, skip int, fields ...*Field)

ErrorWithStackSkip asynchronously sends an error to Rollbar with the given severity level and a given number of stack trace frames skipped. You can pass, optionally, custom Fields to be passed on to Rollbar.

func Message

func Message(level string, msg string)

Message asynchronously sends a message to Rollbar with the given severity level.

func RequestError

func RequestError(level string, r *http.Request, err error, fields ...*Field)

RequestError asynchronously sends an error to Rollbar with the given severity level and request-specific information. You can pass, optionally, custom Fields to be passed on to Rollbar.

func RequestErrorWithStack

func RequestErrorWithStack(level string, r *http.Request, err error, stack Stack, fields ...*Field)

RequestErrorWithStack asynchronously sends an error to Rollbar with the given severity level, request-specific information provided by the given http.Request, and a custom Stack. You You can pass, optionally, custom Fields to be passed on to Rollbar.

func RequestErrorWithStackSkip

func RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int, fields ...*Field)

RequestErrorWithStackSkip asynchronously sends an error to Rollbar with the given severity level and a given number of stack trace frames skipped, in addition to extra request-specific information. You can pass, optionally, custom Fields to be passed on to Rollbar.

func Wait

func Wait()

Wait will block until the queue of errors / messages is empty. This allows you to ensure that errors / messages are sent to Rollbar before exiting an application.

Types

type Field

type Field struct {
	Name string
	Data interface{}
}

Fields can be used to pass arbitrary data to the Rollbar API.

type Frame

type Frame struct {
	Filename string `json:"filename"`
	Method   string `json:"method"`
	Line     int    `json:"lineno"`
}

type Stack

type Stack []Frame

func BuildStack

func BuildStack(skip int) Stack

func (Stack) Fingerprint

func (s Stack) Fingerprint() string

Create a fingerprint that uniquely identify a given message. We use the full callstack, including file names. That ensure that there are no false duplicates but also means that after changing the code (adding/removing lines), the fingerprints will change. It's a trade-off.

Jump to

Keyboard shortcuts

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