sentry

package module
v0.0.0-...-ebc04b8 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: MIT Imports: 5 Imported by: 0

README

Sentry handler

GitHub Workflow Status Codecov Go Report Card Go Version go.dev reference

Error handler integration for Sentry.

Installation

go get emperror.dev/handler/sentry

Usage

package main

import (
	"emperror.dev/handler/sentry"
)

func main() {
	dsn := "https://user:password@sentry.io/1234"

	handler, err := sentry.New(dsn)
	if err != nil {
		panic(err)
	}
	defer handler.Close() // Make sure to close the handler to flush all error reporting in progress
}

Development

When all coding and testing is done, please run the test suite:

$ make check
Running integration tests

In order to run integration tests, a local development environment must be configured. Unfortunately it's a little bit more complicated than a "fire and forget" command, but most of it can be done in the CLI.

The first part is as easy as executing a series of commands:

cp docker-compose.override.yml.dist docker-compose.override.yml
cp .env.test.dist .env.test
docker-compose up -d
docker-compose run --rm sentry upgrade --noinput
docker-compose run --rm sentry createuser --email admin@example.com --password admin --superuser --no-input

Go to the Sentry dashboard:

open http://localhost:32622

Login with admin@example.com and admin credentials.

Complete the setup wizard and add a new test Go project.

Run the test suite:

source .env.test
make test

Cleanup the environment:

docker-compose down

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler is responsible for sending errors to Sentry.

func New

func New(dsn string) (*Handler, error)

New creates a new handler.

Example
package main

import (
	sentryhandler "emperror.dev/handler/sentry"
)

func main() {
	dsn := "https://user:password@sentry.io/1234"

	handler, err := sentryhandler.New(dsn)
	if err != nil {
		panic(err)
	}
	defer handler.Close() // Make sure to close the handler to flush all error reporting in progress

}
Output:

func NewFromClient

func NewFromClient(client *raven.Client) *Handler

NewFromClient creates a new handler from a client instance.

Example
dsn := "https://user:password@sentry.io/1234"

client, err := raven.New(dsn)
if err != nil {
	panic(err)
}

handler := sentryhandler.NewFromClient(client)
defer handler.Close() // Make sure to close the handler to flush all error reporting in progress
Output:

func NewSync

func NewSync(dsn string) (*Handler, error)

NewSync creates a new handler that sends errors synchronously.

Example
package main

import (
	sentryhandler "emperror.dev/handler/sentry"
)

func main() {
	dsn := "https://user:password@sentry.io/1234"

	handler, err := sentryhandler.NewSync(dsn)
	if err != nil {
		panic(err)
	}
	defer handler.Close()

}
Output:

func NewSyncFromClient

func NewSyncFromClient(client *raven.Client) *Handler

NewSyncFromClient creates a new handler from a client instance that sends errors synchronously.

Example
dsn := "https://user:password@sentry.io/1234"

client, err := raven.New(dsn)
if err != nil {
	panic(err)
}

handler := sentryhandler.NewSyncFromClient(client)
defer handler.Close()
Output:

func (*Handler) Close

func (h *Handler) Close() error

Close closes the underlying notifier and waits for asynchronous reports to finish.

func (*Handler) Handle

func (h *Handler) Handle(err error)

Handle sends the error to Rollbar.

Jump to

Keyboard shortcuts

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