• Stars
    star
    192
  • Rank 202,019 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

sentry hook for logrus

Sentry Hook for Logrus :walrus:

GoDoc Release Build Status Coverage Status Go Report Card Code Climate BCH compliance

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/evalphobia/logrus_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)
  }
}

If you wish to initialize a SentryHook with tags, you can use the NewWithTagsSentryHook constructor to provide default tags:

tags := map[string]string{
  "site": "example.com",
}
levels := []logrus.Level{
  logrus.PanicLevel,
  logrus.FatalLevel,
  logrus.ErrorLevel,
}
hook, err := logrus_sentry.NewWithTagsSentryHook(YOUR_DSN, tags, levels)

If you wish to initialize a SentryHook with an already initialized raven client, you can use the NewWithClientSentryHook constructor:

import (
  "github.com/sirupsen/logrus"
  "github.com/evalphobia/logrus_sentry"
  "github.com/getsentry/raven-go"
)

func main() {
  log := logrus.New()

  client, err := raven.New(YOUR_DSN)
  if err != nil {
      log.Fatal(err)
  }

  hook, err := logrus_sentry.NewWithClientSentryHook(client, []logrus.Level{
    logrus.PanicLevel,
    logrus.FatalLevel,
    logrus.ErrorLevel,
  })

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

hook, err := NewWithClientSentryHook(client, []logrus.Level{
	logrus.ErrorLevel,
})

Special fields

Some logrus fields have a special meaning in this hook, and they will be especially processed by Sentry.

Field key Description
event_id Each logged event is identified by the event_id, which is hexadecimal string representing a UUID4 value. You can manually specify the identifier of a log event by supplying this field. The event_id string should be in one of the following UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx and urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
user_name Name of the user who is in the context of the event
user_email Email of the user who is in the context of the event
user_id ID of the user who is in the context of the event
user_ip IP of the user who is in the context of the event
server_name Also known as hostname, it is the name of the server which is logging the event (hostname.example.com)
tags tags are raven.Tags struct from github.com/getsentry/raven-go and override default tags data
fingerprint fingerprint is an string array, that allows you to affect sentry's grouping of events as detailed in the sentry documentation
logger 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.
http_request http_request is the in-coming request(*http.Request). The detailed request data are sent to Sentry.

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

Enabling Stacktraces

By default the hook will not send any stacktraces. However, this can be enabled with:

hook, _ := logrus_sentry.NewSentryHook(...)
hook.StacktraceConfiguration.Enable = true

Subsequent calls to logger.Error and above will create a stacktrace.

Other configuration options are:

  • StacktraceConfiguration.Level the logrus level at which to start capturing stacktraces.
  • StacktraceConfiguration.Skip how many stack frames to skip before stacktrace starts recording.
  • StacktraceConfiguration.Context the number of lines to include around a stack frame for context.
  • StacktraceConfiguration.InAppPrefixes the prefixes that will be matched against the stack frame to identify it as in_app
  • StacktraceConfiguration.IncludeErrorBreadcrumb whether to create a breadcrumb with the full text of error

More Repositories

1

logrus_fluent

fluentd hooks for logrus
Go
44
star
2

wizard

Wizard is database/sql management library for multi instance and sharding in golang
Go
43
star
3

google-home-client-go

Google Home client for golang
Go
30
star
4

aws-sdk-go-wrapper

Simple wrapper for aws-sdk-go
Go
29
star
5

google-tts-go

Google TTS (Text-To-Speech) for golang
Go
17
star
6

go-jp-text-ripper

tokenize text and separate it into words for Japanese
Go
11
star
7

logrus_stackdriver

logrus hooks for Google Stackdriver logging
Go
10
star
8

go-ip-fraud-check

To check ip address risk and proxy usage using ip address check services
Go
10
star
9

logrus_kinesis

AWS Kinesis hooks for logrus
Go
9
star
10

go-datarobot

datarobot supporting app and api client
Go
9
star
11

go-paypal-classic

PayPal Classic API library for golang
Go
8
star
12

google-api-go-wrapper

golang wrapper of Google APIs Client Library
Go
7
star
13

google-vision-ocr

Search image file and extract OCR text using Google Cloud Vision API
Go
5
star
14

instrumental_agent-go

Golang Agent for Instrumental Application Monitoring https://instrumentalapp.com
Go
4
star
15

go-config-loader

Simple config file loader for Golang
Go
4
star
16

go-sentry-logger

Go logger with sentry
Go
4
star
17

cloud-iam-policy-checker

Check IAM policy and permissions of AWS
Go
4
star
18

eurekache

fallback cache system with multiple cache source for go
Go
4
star
19

face-detect-annotator

Detect faces from Image by AWS Rekognition, Google Vision, Azure Computer Vision, Face++, OpenCV, Dlib, Pigo, Tensorflow
Go
4
star
20

go-logdna

LogDNA library for Golang
Go
3
star
21

go-simple-proxy

Go
3
star
22

apptracer

Golang multiple trace system wrapper for GCP Stackdriver Trace, AWS X-Ray, Datadog, LightStep and NewRelic
Go
3
star
23

go-yml2sql

Create SQL INSERT statement from YAML file
Go
3
star
24

go-timber

Timber.io library for Golang
Go
2
star
25

sls-ad-blocking-cloudflare-gateway

HCL
2
star
26

httpwrapper

HTTP client wrapper using h2non/gentleman
Go
2
star
27

serverless-twitter-image-slack

Search image from Tweet, Post it to Slack. Running on AWS Lambda.
Python
2
star
28

golint-sample

Go
2
star
29

go-log-wrapper

logrus wrapper
Go
2
star
30

godoc-auth

godoc http server with basic auth (from from go source https://code.google.com/p/go/source/browse/?repo=tools#hg%2Fcmd%2Fgodoc%253Fstate%253Dclosed)
Go
1
star
31

aws-sdk-go-v2-wrapper

Simple wrapper for aws-sdk-go-v2
Go
1
star
32

awscost

Fetch AWS Billing Cost (by Golang)
Go
1
star
33

go-gmo-pg

Unofficial golang library for GMO Payment Gateway
Go
1
star
34

dockerfiles

Dockerfile
1
star
35

jira2slack-lambda

Send JIRA event message to Slack channel
JavaScript
1
star
36

hydranger

Handy web frontend for Google Spread Sheet
JavaScript
1
star
37

cloud-label-uploader

Download file from CSV file via http; Create training CSV file for AutoML and Sagemaker Ground Truth; Upload file to GCS and S3
Go
1
star
38

go-face-plusplus

Face++ library for Golang
Go
1
star
39

serverless-datarobot

DataRobot Prime REST Server for Serverless
Python
1
star
40

ansible

My ansible playbooks & environments for Web Applications
Shell
1
star
41

datarobot-prime-server

HTTP server for DataRobot Prime.
Python
1
star
42

github-pr-checker

GitHub's Webhook to check changed files from Pull Request event then post comment and set assignee/reviewers. Powered by Serverless or HTTP server.
Go
1
star