webhook

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package webhook delivers best-effort HTTP notifications on Trace session lifecycle events. Delivery is non-blocking and fail-open: a webhook that is slow, unreachable, or returns an error never propagates back to the caller and never fails a session. Failures are logged at WARN and dropped.

Index

Constants

View Source
const (
	EventSessionStart      = "session_start"
	EventCheckpointCreated = "checkpoint_created"
	EventSessionEnd        = "session_end"
	EventError             = "error"
)

Lifecycle event names. These are the canonical strings used both in the delivered payload's "event" field and in WebhookConfig.Events filtering.

Variables

This section is empty.

Functions

This section is empty.

Types

type Notifier

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

Notifier delivers events to a set of configured webhook endpoints.

func LoadNotifier

func LoadNotifier(ctx context.Context) *Notifier

LoadNotifier loads webhook config from Trace settings and returns a Notifier. Returns nil (a valid no-op) when settings cannot be loaded or no webhooks are configured — webhook delivery must never block on configuration errors.

func NewNotifier

func NewNotifier(cfg *settings.WebhookConfig) *Notifier

NewNotifier builds a Notifier from the given config. It returns nil when no endpoints are configured, so callers can treat a nil *Notifier as a no-op (every method is nil-safe).

func (*Notifier) Notify

func (n *Notifier) Notify(ctx context.Context, event, sessionID string, extra map[string]any)

Notify delivers an event to every configured endpoint. It is best-effort and never returns an error: failures are logged and dropped. The payload is the JSON object {event, session_id, timestamp, ...extra}. Calling on a nil Notifier is a no-op.

Delivery runs synchronously against the per-POST timeout so the caller can reason about the upper bound. Callers on a hot path that cannot tolerate even the bounded wait should use NotifyAsync.

func (*Notifier) NotifyAsync

func (n *Notifier) NotifyAsync(event, sessionID string, extra map[string]any)

NotifyAsync delivers an event on a detached goroutine and returns immediately, so even the bounded per-POST wait stays off the caller's path. It uses context.Background so a cancelled caller context does not abort in-flight delivery. Best-effort; failures are logged.

Jump to

Keyboard shortcuts

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