errclass

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package errclass implements a pluggable classifier that maps errors to a closed set of OpenTelemetry-compatible error.type labels. The base module defines only vendor-neutral classes (timeouts, cancellation, network, auth, rate-limiting, invalid requests, permission denial, upstream 5xx). Each consuming SDK registers its own sentinels or matchers.

Index

Constants

This section is empty.

Variables

View Source
var AttrKey = attribute.Key("error.type")

AttrKey is the OTel-standard error.type attribute key. Recorded spans and metrics use it as the closed-set error classification label.

Functions

This section is empty.

Types

type Class

type Class string

Class is a closed-set label. Consuming libraries may define their own Class constants, but they SHOULD keep the total cardinality bounded and stable.

const (
	// Unknown is the default when no matcher fires. Use sparingly — an Unknown
	// rate climbing is a signal that your sentinel coverage is lagging.
	Unknown Class = "unknown"

	// Standard closed set.
	Timeout          Class = "timeout"
	Canceled         Class = "canceled"
	InvalidRequest   Class = "invalid_request"
	RateLimited      Class = "rate_limited"
	Auth             Class = "auth"
	PermissionDenied Class = "permission_denied"
	Upstream5xx      Class = "upstream_5xx"
	Network          Class = "network"
)

func (Class) Attr

func (c Class) Attr() attribute.KeyValue

Attr returns the error.type attribute for this class.

type Matcher

type Matcher func(error) (Class, bool)

Matcher returns (class, true) when it recognizes the error, (_, false) otherwise.

type Registry

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

Registry holds an ordered list of matchers. First match wins.

func New

func New() *Registry

New returns an empty registry. Consider calling RegisterDefaults() if you want the standard context.Canceled / context.DeadlineExceeded mappings.

func (*Registry) Classify

func (r *Registry) Classify(err error) Class

Classify returns the class for err. Returns "" for a nil error and Unknown if no matcher fires.

func (*Registry) RegisterDefaults

func (r *Registry) RegisterDefaults()

RegisterDefaults registers the baseline mappings that apply to every library: context.DeadlineExceeded → Timeout, context.Canceled → Canceled.

func (*Registry) RegisterMatcher

func (r *Registry) RegisterMatcher(m Matcher)

RegisterMatcher appends a custom matcher. Matchers are tried in registration order, so register more specific matchers before more general ones.

func (*Registry) RegisterSentinel

func (r *Registry) RegisterSentinel(target error, class Class)

RegisterSentinel wires a sentinel error to a class via errors.Is.

Jump to

Keyboard shortcuts

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