sentry

package module
v2.0.0-...-e19cc42 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 12 Imported by: 0

README

Sentry middleware for Kratos

This middleware helps you to catch panics and report them to sentry

Quick Start

You could check the full demo in example folder.

// Step 1: 
// init sentry in the entry of your application
import "github.com/getsentry/sentry-go"

sentry.Init(sentry.ClientOptions{
		Dsn: "<your dsn>",
		AttachStacktrace: true, // recommended
})


// Step 2: 
// set middleware
import 	ksentry "github.com/plum330/kratos/contrib/errortracker/sentry/v2"

// for HTTP server, new HTTP server with sentry middleware options
var opts = []http.ServerOption{
	http.Middleware(
		recovery.Recovery(),
		tracing.Server(),
		ksentry.Server(ksentry.WithTags(map[string]interface{}{
			"tag": "some-custom-constant-tag",
			"trace_id": tracing.TraceID(), // If you want to use the TraceID valuer, you need to place it after the A middleware.
		})), // must after Recovery middleware, because of the exiting order will be reversed
		
		logging.Server(logger), 
	),
}

// for gRPC server, new gRPC server with sentry middleware options
var opts = []grpc.ServerOption{
     grpc.Middleware(
		recovery.Recovery(),
		tracing.Server(),
		ksentry.Server(ksentry.WithTags(map[string]interface{}{
			"tag": "some-custom-constant-tag",
			"trace_id": tracing.TraceID(), // If you want to use the TraceID valuer, you need to place it after the A middleware.
		})), // must after Recovery middleware, because of the exiting order will be reversed
		logging.Server(logger),
     ),
 }


// Then, the framework will report events to Sentry when your trigger panics.
// Or your can push events to Sentry manually

Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHubFromContext

func GetHubFromContext(ctx context.Context) *sentry.Hub

GetHubFromContext retrieves attached *sentry.Hub instance from context or sentry. You can use this hub for extra information reporting

func Server

func Server(opts ...Option) middleware.Middleware

Server returns a new server middleware for Sentry.

Types

type Option

type Option func(*options)

func WithRepanic

func WithRepanic(repanic bool) Option

WithRepanic repanic configures whether Sentry should repanic after recovery, in most cases it should be set to true.

func WithTags

func WithTags(kvs map[string]interface{}) Option

WithTags global tags injection, the value type must be string or log.Valuer

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout timeout for the event delivery requests.

func WithWaitForDelivery

func WithWaitForDelivery(waitForDelivery bool) Option

WithWaitForDelivery waitForDelivery configures whether you want to block the request before moving forward with the response.

Jump to

Keyboard shortcuts

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