errortracking

package
v0.0.0-...-23fd86d Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package errortracking abstracts all error reporting features away from services like workhorse or pages

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capture

func Capture(err error, opts ...CaptureOption)

Capture will report an error to the error reporting service

Example
package main

import (
	"net/http"

	"gitlab.com/gitlab-org/labkit/errortracking"
)

func main() {
	req, err := http.NewRequest("GET", "http://example.com", nil)
	ctx := req.Context()

	if err != nil {
		// Send the error to the error tracking system
		errortracking.Capture(err,
			errortracking.WithContext(ctx),                          // Extract details such as correlation-id from context
			errortracking.WithRequest(req),                          // Extract additional details from request
			errortracking.WithField("domain", "http://example.com")) // Add additional custom details
	}
}
Output:

func Initialize

func Initialize(opts ...InitializationOption) error

Initialize will initialize error reporting

func NewHandler

func NewHandler(next http.Handler) http.Handler

NewHandler will recover from panics inside handlers and reports the stacktrace to the errorreporting provider

Example
package main

import (
	"net/http"

	"gitlab.com/gitlab-org/labkit/errortracking"
)

func main() {
	handler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
		panic("oh dear")
	})

	http.ListenAndServe(":1234", errortracking.NewHandler(handler))
}
Output:

Types

type CaptureOption

type CaptureOption func(*sentry.Event)

CaptureOption will configure how an error is captured

func WithContext

func WithContext(ctx context.Context) CaptureOption

WithContext will extract information from the context to add to the error

func WithField

func WithField(key string, value string) CaptureOption

WithField allows to add a custom field to the error

func WithRequest

func WithRequest(r *http.Request) CaptureOption

WithRequest will capture details of the request along with the error

type InitializationOption

type InitializationOption func(*initializationConfig)

InitializationOption will configure a correlation handler

func WithLoggerName

func WithLoggerName(loggerName string) InitializationOption

WithLoggerName sets the logger name

func WithSentryDSN

func WithSentryDSN(sentryDSN string) InitializationOption

WithSentryDSN sets the sentry data source name

func WithSentryEnvironment

func WithSentryEnvironment(sentryEnvironment string) InitializationOption

WithSentryEnvironment sets the sentry environment

func WithVersion

func WithVersion(version string) InitializationOption

WithVersion is used to configure the version of the service that is currently running

Jump to

Keyboard shortcuts

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