zlogsentry

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

zerolog-sentry

Build Status codecov

Example
import (
	"errors"
	stdlog "log"
	"os"

	"github.com/lexx13/zerolog-sentry"
	"github.com/rs/zerolog"
)

func main() {
	w, err := zlogsentry.New("http://e35657dcf4fb4d7c98a1c0b8a9125088@localhost:9000/2", zlogsentry.WithEnvironment("dev"), zlogsentry.WithRelease("1.0.0"))
	if err != nil {
		stdlog.Fatal(err)
	}

	defer w.Close()

	multi := zerolog.MultiLevelWriter(os.Stdout, w)
	logger := zerolog.New(multi).With().Timestamp().Logger()

	logger.Error().Err(errors.New("dial timeout")).Msg("test message")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventHintCallback

type EventHintCallback func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event

type Writer

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

Writer is a sentry events writer with std io.Writer iface.

func New

func New(dsn string, opts ...WriterOption) (*Writer, error)

New creates writer with provided DSN and options.

func (*Writer) Close

func (w *Writer) Close() error

Close forces client to flush all pending events. Can be useful before application exits.

func (*Writer) Write

func (w *Writer) Write(data []byte) (n int, err error)

Write handles zerolog's json and sends events to sentry.

func (*Writer) WriteLevel

func (w *Writer) WriteLevel(level zerolog.Level, p []byte) (n int, err error)

implements zerolog.LevelWriter

type WriterOption

type WriterOption interface {
	// contains filtered or unexported methods
}

WriterOption configures sentry events writer.

func WithBeforeSend

func WithBeforeSend(beforeSend sentry.EventProcessor) WriterOption

WithBeforeSend sets a callback which is called before event is sent.

func WithCaCerts

func WithCaCerts(caCerts *x509.CertPool) WriterOption

WithCaCerts enables sentry client tracing.

func WithDebug

func WithDebug() WriterOption

WithDebug enables sentry client debug logs.

func WithDebugWriter

func WithDebugWriter(w io.Writer) WriterOption

WithDebugWriter enables sentry client tracing.

func WithEnvironment

func WithEnvironment(environment string) WriterOption

WithEnvironment configures the environment to be sent with events.

func WithHttpProxy

func WithHttpProxy(proxy string) WriterOption

WithHttpProxy enables sentry client tracing.

func WithHttpsProxy

func WithHttpsProxy(proxy string) WriterOption

WithHttpsProxy enables sentry client tracing.

func WithIgnoreErrors

func WithIgnoreErrors(reList []string) WriterOption

WithIgnoreErrors configures the list of regexp strings that will be used to match against event's message and if applicable, caught errors type and value. If the match is found, then a whole event will be dropped.

func WithLevels

func WithLevels(levels ...zerolog.Level) WriterOption

WithLevels configures zerolog levels that have to be sent to Sentry. Default levels are: error, fatal, panic.

func WithRelease

func WithRelease(release string) WriterOption

WithRelease configures the release to be sent with events.

func WithSampleRate

func WithSampleRate(rate float64) WriterOption

WithSampleRate configures the sample rate as a percentage of events to be sent in the range of 0.0 to 1.0.

func WithServerName

func WithServerName(serverName string) WriterOption

WithServerName configures the server name field for events. Default value is OS hostname.

func WithTracing

func WithTracing() WriterOption

WithTracing enables sentry client tracing.

func WithTracingSampleRate

func WithTracingSampleRate(tsr float64) WriterOption

WithTracingSampleRate sets tracing sample rate.

Jump to

Keyboard shortcuts

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