sentrytemporal

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 7 Imported by: 0

README

Sentry Temporal Interceptor

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

Installation

go get github.com/zax-29/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
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New creates a worker interceptor which will report error to sentry.

Types

type ActivityErrorSkipper

type ActivityErrorSkipper func(context.Context, error) bool

type ActivityScopeCustomizer

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

type Options

type Options struct {
	// ActivityErrorSkipper configures a function to determine if an error from activity should be skipped.
	// If it returns true, the error is ignored.
	ActivityErrorSkipper ActivityErrorSkipper
	// WorkflowErrorSkipper configures a function to determine if an error 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 WorkflowErrorSkipper

type WorkflowErrorSkipper func(workflow.Context, error) bool

type WorkflowScopeCustomizer

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

Jump to

Keyboard shortcuts

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