sentry

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package sentry reports workflow failures to Sentry through github.com/getsentry/sentry-go: a workflow.Reporter that sends one Sentry event per failure it is handed.

r := sentry.New(nil, sentry.WithLabels("tenant"))
client, err := workflow.Use(client, middleware.Report(r, middleware.ReportConfig{}))

middleware.Report (or ReportFailures alone) hands it one Failure per run that ended failed, and with ReportConfig.Attempts one per failed attempt that will be retried; ReportConfig.Discarded adds discarded runs. The Reporter itself sends whatever it is given.

What is sent

Each event carries the error (its message and type chain, as sentry-go's CaptureException builds them), level LevelError for a final failure and LevelWarning for an attempt (WithLevels), the tags workflow.name, workflow.step, workflow.status and workflow.final, and a "workflow" context with the run ID, scheduled ID, attempt and time. The payload is never sent: workflow.Failure does not carry it. Job labels are not sent by default, because they can carry tenant or user ids into a third-party service; WithLabels (chosen keys) or WithAllLabels opts in, as tags named workflow.label.<key>. The default fingerprint groups events by workflow, step and error type (WithFingerprint replaces it), so one recurring failure is one Sentry issue rather than one per run.

Hub

New takes the hub to send through. With a nil hub each Report uses the hub in its ctx (sentry.GetHubFromContext) or else sentry.CurrentHub. Every Report works on a clone of that hub, so concurrent reports never share a scope and the app's own scope is never changed. WithEvent is the escape hatch: it sees each event and the Failure just before sending, and may change or drop the event.

Sending is sentry-go's: its transport batches in the background, so call sentry.Flush (or the hub client's Flush) before the process exits.

Index

Constants

View Source
const (
	TagWorkflow    = "workflow.name"
	TagStep        = "workflow.step"
	TagStatus      = "workflow.status"
	TagFinal       = "workflow.final"
	TagLabelPrefix = "workflow.label."
	ContextName    = "workflow"
)

Tag and context names set on every event. They are fixed so a Sentry search or alert rule written against them keeps working.

Variables

This section is empty.

Functions

func DefaultFingerprint

func DefaultFingerprint(f workflow.Failure) []string

DefaultFingerprint groups events by workflow, step and the type of the innermost error, so a recurring failure is one issue whatever the run or the error text (which often holds ids).

Types

type Option

type Option func(*Reporter)

Option configures a Reporter.

func WithAllLabels

func WithAllLabels() Option

WithAllLabels forwards every job label as a tag. Prefer WithLabels: a label added later is then sent without anyone deciding it.

func WithEvent

func WithEvent(fn func(*sentrygo.Event, workflow.Failure) *sentrygo.Event) Option

WithEvent runs fn on every event just before it is sent, with the Failure it came from; fn returns the event to send, or nil to drop it. It is the one escape hatch for anything the options do not cover.

func WithFingerprint

func WithFingerprint(fn func(workflow.Failure) []string) Option

WithFingerprint replaces the grouping of events into Sentry issues. The default is DefaultFingerprint.

func WithLabels

func WithLabels(keys ...string) Option

WithLabels forwards the job labels with these keys as tags (workflow.label.<key>). Labels are not sent unless chosen, because they can carry tenant or user ids.

func WithLevels

func WithLevels(final, attempt sentrygo.Level) Option

WithLevels sets the event level of a final failure and of an attempt failure (LevelError and LevelWarning by default).

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter is a workflow.Reporter that sends each Failure to Sentry as one event. Build it with New; it is safe for concurrent use.

func New

func New(hub *sentrygo.Hub, opts ...Option) *Reporter

New returns a Reporter that sends through hub; a nil hub means the hub in each Report's ctx, or sentry.CurrentHub when the ctx has none.

func (*Reporter) Report

func (r *Reporter) Report(ctx context.Context, f workflow.Failure)

Report sends f to Sentry as one event.

Jump to

Keyboard shortcuts

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