Skip to content

jinsunyang/zapsentry

 
 

Repository files navigation

Sentry client for zap logger

Zap Core for Sentry

CI Status Go Report Card

Features

  • with stacktrace (this is handy for analysis into Sentry UI)
  • with tests (can always be tests)
  • easy setup

Quick start

Installation

Using go mod:

go get github.com/gebv/zapsentry/v2
# update
# go get -u github.com/gebv/zapsentry/v2

Example code

// you already have a logger
//
// config := zap.NewDevelopmentConfig()
// config.Level.SetLevel(zap.InfoLevel)
// l, _ := config.Build(zap.AddStacktrace(zap.ErrorLevel))

zaplog, _ := zapsentry.Set(l,
    // required sets level enabler
    zapsentry.LevelEnabler(zap.ErrorLevel),
    // required sets DSN to Sentry and sets tags if need
    zapsentry.WithSentry("https://...", map[string]string{
        "tag1": "tag1-value",
        "tag2": "tag2-value",
    }),

    // (optional) set the number of layers to skip (first layers are always the same)
    zapsentry.TraceSkipFrames(3), // skip 3 first layers in stacktraces
    // (optional) set your enviroment
    zapsentry.Enviroment("dev"),
    // (optional) set your application version
    zapsentry.Release("v1-demo"),
    // we recommend enable stektrace
    zapsentry.EnableStacktrace(),
    // (optional) set your server name
    zapsentry.ServerName("my-server-name"),
)

// zap.ReplaceGlobals(zaplog)

Example of error and visualization in the Sentry UI

err1 := io.EOF
err5 := errors.Wrap(err1, "fifth error")

zap.L().Error("case 5", zap.Error(err5))

The most interesting:

  • stacktrace
  • error details (section ADDITIONAL DATA)

Case 5

See a complete example

Version Policy

zapsentry follows semantic versioning for the documented public API on stable releases. v2 is the latest stable version and follows SemVer strictly. Follows changelog.

The library v1 after improved and finalized went into v2. v2 has a module name github.com/gebv/zapsentry/v2 v1 follows TheZeroSlave/zapsentry.

License

MIT, see LICENSE.

About

zap logger sentry core

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.4%
  • Makefile 0.6%