report

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: ISC Imports: 4 Imported by: 0

README

report

This package provides an error reporter for your go applications. An error reporter can report your errors to an error monitoring service (Rollbar, Airbrake, etc.) An error reporting service simplifies creating dashboards, alerting, and debugging.

Quick Start

You can use the global/singelton reporter as follows:

package main

import (
  "errors"

  "github.com/moorara/observe/report"
)

func main() {
  report.SetOptions(report.RollbarOptions{
    Token:       "rollbar-token",
    Environment: "production",
    CodeVersion: "commit-hash",
  })

  // Catch panics and report them
  defer report.OnPanic()

  // Report an error
  report.Error(errors.New("error"))
  
  // Trigger a panic
  panic("crash")
}

Or you can create a new instance reporter as follows:

package main

import (
  "errors"

  "github.com/moorara/observe/report"
)

func main() {
  reporter := report.NewRollbarReporter(report.RollbarOptions{
    Token:       "rollbar-token",
    Environment: "production",
    CodeVersion: "commit-hash",
  })

  // Catch panics and report them
  defer reporter.OnPanic()

  // Report an error
  err := errors.New("error")
  reporter.ErrorWithMetadata(err, map[string]interface{}{
    "userId":   "1234",
		"tenantId": "abcd",
  })
}

The project access token should be a post_server_item token.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(err error)

Error reports an error

func ErrorWithMetadata

func ErrorWithMetadata(err error, metadata map[string]interface{})

ErrorWithMetadata reports an error with extra metadata

func HTTPError

func HTTPError(req *http.Request, err error)

HTTPError reports an error for an http request

func HTTPErrorWithMetadata

func HTTPErrorWithMetadata(req *http.Request, err error, metadata map[string]interface{})

HTTPErrorWithMetadata reports an error for an http request with extra metdata

func OnPanic

func OnPanic()

OnPanic reports a panic and should be used with defer

func SetOptions

func SetOptions(opts RollbarOptions)

SetOptions sets options for singleton reporter

func Wait

func Wait()

Wait blocks until all errors are reported

Types

type RollbarOptions

type RollbarOptions struct {
	Token       string
	Environment string
	CodeVersion string
	ProjectURL  string
	// contains filtered or unexported fields
}

RollbarOptions contains optional options for RollbarReporter

type RollbarReporter

type RollbarReporter struct {
	// contains filtered or unexported fields
}

RollbarReporter simplifies rollbar client

func NewRollbarReporter

func NewRollbarReporter(opts RollbarOptions) *RollbarReporter

NewRollbarReporter creates a new instance of reporter

func (*RollbarReporter) Error

func (r *RollbarReporter) Error(err error)

Error reports an error

func (*RollbarReporter) ErrorWithMetadata

func (r *RollbarReporter) ErrorWithMetadata(err error, metadata map[string]interface{})

ErrorWithMetadata reports an error with extra metadata

func (*RollbarReporter) HTTPError

func (r *RollbarReporter) HTTPError(req *http.Request, err error)

HTTPError reports an error for an http request

func (*RollbarReporter) HTTPErrorWithMetadata

func (r *RollbarReporter) HTTPErrorWithMetadata(req *http.Request, err error, metadata map[string]interface{})

HTTPErrorWithMetadata reports an error for an http request with extra metdata

func (*RollbarReporter) OnPanic

func (r *RollbarReporter) OnPanic()

OnPanic reports a panic and should be used with defer

func (*RollbarReporter) Wait

func (r *RollbarReporter) Wait()

Wait blocks until all errors are reported

Jump to

Keyboard shortcuts

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