1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00
woodpecker/vendor/github.com/Sirupsen/logrus/hooks/sentry
2015-09-29 17:34:44 -07:00
..
README.md moving from Godeps to Go 1.5 vendoring 2015-09-29 17:34:44 -07:00
sentry_test.go moving from Godeps to Go 1.5 vendoring 2015-09-29 17:34:44 -07:00
sentry.go moving from Godeps to Go 1.5 vendoring 2015-09-29 17:34:44 -07:00

Sentry Hook for Logrus :walrus:

Sentry provides both self-hosted and hosted solutions for exception tracking. Both client and server are open source.

Usage

Every sentry application defined on the server gets a different DSN. In the example below replace YOUR_DSN with the one created for your application.

import (
  "github.com/Sirupsen/logrus"
  "github.com/Sirupsen/logrus/hooks/sentry"
)

func main() {
  log       := logrus.New()
  hook, err := logrus_sentry.NewSentryHook(YOUR_DSN, []logrus.Level{
    logrus.PanicLevel,
    logrus.FatalLevel,
    logrus.ErrorLevel,
  })

  if err == nil {
    log.Hooks.Add(hook)
  }
}

Special fields

Some logrus fields have a special meaning in this hook, these are server_name and logger. When logs are sent to sentry these fields are treated differently.

  • server_name (also known as hostname) is the name of the server which is logging the event (hostname.example.com)
  • logger is the part of the application which is logging the event. In go this usually means setting it to the name of the package.

Timeout

Timeout is the time the sentry hook will wait for a response from the sentry server.

If this time elapses with no response from the server an error will be returned.

If Timeout is set to 0 the SentryHook will not wait for a reply and will assume a correct delivery.

The SentryHook has a default timeout of 100 milliseconds when created with a call to NewSentryHook. This can be changed by assigning a value to the Timeout field:

hook, _ := logrus_sentry.NewSentryHook(...)
hook.Timeout = 20*time.Second