hb

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2015 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

package hb is a Go package from sending errors to Honeybadger.

Example
package main

import (
	"errors"
	"net/http"

	"github.com/remind101/pkg/reporter"
	"github.com/remind101/pkg/reporter/hb"
	"golang.org/x/net/context"
)

var errBoom = errors.New("boom")

func main() {
	ctx := reporter.WithReporter(context.Background(), hb.NewReporter("dcb8affa"))
	req, _ := http.NewRequest("GET", "/api/foo", nil)
	req.Header.Set("Content-Type", "application/json")

	reporter.AddContext(ctx, "request_id", "1234")
	reporter.AddRequest(ctx, req)
	reporter.Report(ctx, errBoom)
}
Output:

Index

Examples

Constants

View Source
const (
	DefaultURL     = "https://api.honeybadger.io"
	DefaultVersion = "v1"
)

Variables

View Source
var IgnoredHeaders = map[string]struct{}{
	"Authorization": struct{}{},
}

Headers that won't be sent to honeybadger.

Functions

This section is empty.

Types

type BacktraceLine

type BacktraceLine struct {
	Method string `json:"method"`
	File   string `json:"file"`
	Number string `json:"number"`
}

type Client

type Client struct {
	// URL is the location for the honeybadger api. The zero value is DefaultURL.
	URL string

	// Version is the API version to use. The zero value is DefaultVersion.
	Version string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *http.Client) *Client

NewClient returns a new Client instance.

func NewClientFromKey

func NewClientFromKey(key string) *Client

NewClientFromKey returns a new Client with an http.Client configured to add the key as the api token.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, v interface{}) (*http.Request, error)

func (*Client) Send

func (c *Client) Send(r *Report) error

type Error

type Error struct {
	Class     string                 `json:"class"`
	Message   string                 `json:"message"`
	Backtrace []*BacktraceLine       `json:"backtrace"`
	Source    map[string]interface{} `json:"source"`
	Tags      []string               `json:"tags"`
}

type Notifier

type Notifier struct {
	Name     string `json:"name"`
	Url      string `json:"url"`
	Version  string `json:"version"`
	Language string `json:"language"`
}

type Report

type Report struct {
	Notifier *Notifier `json:"notifier"`
	Error    *Error    `json:"error"`
	Request  *Request  `json:"request"`
	Server   *Server   `json:"server"`
}

func NewReport

func NewReport(err error) *Report

NewReport generates a new honeybadger report from an error.

type Reporter

type Reporter struct {
	Environment string
	// contains filtered or unexported fields
}

Reporter is used to report errors to honeybadger.

func NewReporter

func NewReporter(key string) *Reporter

NewReporter returns a new Reporter instance.

func (*Reporter) NewReport

func (r *Reporter) NewReport(err error) *Report

func (*Reporter) Report

func (r *Reporter) Report(ctx context.Context, err error) error

Report reports the error to honeybadger.

type Request

type Request struct {
	Url       string                 `json:"url"`
	Component string                 `json:"component"`
	Action    string                 `json:"action"`
	Params    map[string]interface{} `json:"params"`
	Session   map[string]interface{} `json:"session"`
	CgiData   map[string]interface{} `json:"cgi_data"`
	Context   map[string]interface{} `json:"context"`
}

type Server

type Server struct {
	ProjectRoot     map[string]interface{} `json:"project_root"`
	EnvironmentName string                 `json:"environment_name"`
	Hostname        string                 `json:"hostname"`
}

type Transport

type Transport struct {
	Key string

	Transport http.RoundTripper
}

Transport is an http.RoundTripper that adds the api key to the request headers.

func (*Transport) Client

func (t *Transport) Client() *http.Client

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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