Giter Club home page Giter Club logo

sentrytemporal's Introduction

Sentry Temporal Interceptor

The temporal interceptor captures panic and errors and report them to sentry server.

Installation

go get github.com/sdcxtech/sentrytemporal
	// The client and worker are heavyweight objects that should be created once per process.
	c, err := client.Dial(client.Options{})
	if err != nil {
		log.Fatalln("Unable to create client", err)
	}
	defer c.Close()

	w := worker.New(c, "taskQueue", worker.Options{
		// Create interceptor that will put started time on the logger
		Interceptors: []sdkinterceptor.WorkerInterceptor{
			sentrytemp.New(
				sentry.CurrentHub(),
				sentrytemp.Options{},
			),
		},
	})

Configuration

New accepts a struct of Options that allows you to configure how the inteceptor will behave.

type Options struct {
    // ActivityErrorSkipper configures a function to determine if an error (or panic) from activity should be skipped.
    // If it returns true, the error is ignored.
    ActivityErrorSkipper ActivityErrorSkipper
    // WorkflowErrorSkipper configures a function to determine if an error (or panic) from workflow should be skipped.
    // If it returns true, the error is ignored.
    WorkflowErrorSkipper WorkflowErrorSkipper
    
    // ActivityScopeCustomizer applies custom options to a sentry.Scope just before an error is reported from an activity
    ActivityScopeCustomizer ActivityScopeCustomizer
    // WorkflowScopeCustomizer applies custom options to a sentry.Scope just before an error is reported from a workflow
    WorkflowScopeCustomizer WorkflowScopeCustomizer
}

type (
    ActivityErrorSkipper func(context.Context, error) bool
    WorkflowErrorSkipper func(workflow.Context, error) bool

    ActivityScopeCustomizer func(context.Context, *sentry.Scope, error)
    WorkflowScopeCustomizer func(workflow.Context, *sentry.Scope, error)
)

Example:

Only report retryable error when attempt count is great then 1.

activityErrorSkipper := func(ctx context.Context, err error) bool {
	var errApp *temporal.ApplicationError
	if errors.As(err, &errApp) {
		if errApp.NonRetryable() {
			return false
		}

		info := activity.GetInfo(ctx)

		return !(info.Attempt > 1)
	}

	return false
}

sentrytemporal's People

Contributors

qiuyuzhou avatar fosmjo avatar igrayson avatar

Stargazers

Mike Johnson avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.