observability

package
v0.1.0 Latest Latest
Warning

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

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

README

Observability helpers

observability provides optional Sentry request and panic instrumentation for Go services. Empty configuration is a no-op, which keeps self-hosted installations independent of a hosted telemetry service.

shutdown := observability.MustInit(observability.Config{Service: "example"})
defer shutdown()

The package scrubs request data before forwarding any event and owns no deployment or credential policy.

Documentation

Overview

Package observability wires kombify Go services into Sentry for error reporting and performance tracing.

This is the SINGLE SOURCE OF TRUTH for how internal kombify Go services initialize Sentry — defaults (sample rates, PII scrubbing, release tagging, user-context extraction from edgeauth headers) are enforced here so every service gets identical, DSGVO-safe behavior.

Scope: SaaS services only (Ebene 2 per PRODUCT-SEGMENTATION.md). OSS tools (Ebene 1 — Sim, SpeechKit, StackKits, TechStack-OSS) MUST NOT import this package. See ../kombify Core/standards/OBSERVABILITY-STANDARD.md.

Usage:

func main() {
    shutdown := observability.MustInit(observability.Config{
        Service:     "kombify-cloud-backend",
        Environment: os.Getenv("SENTRY_ENVIRONMENT"),
        Release:     os.Getenv("SENTRY_RELEASE"),
    })
    defer shutdown()

    mux := http.NewServeMux()
    // ... register handlers ...
    http.ListenAndServe(":8080", observability.Middleware(mux))
}

Index

Constants

This section is empty.

Variables

View Source
var ErrObservabilityDisabled = errors.New("observability: disabled (no SENTRY_DSN)")

ErrObservabilityDisabled is returned by utilities that require Sentry but the SDK is in no-op mode. Rarely needed — most code should check with IsEnabled() before branching.

Functions

func CaptureErr

func CaptureErr(ctx context.Context, err error) error

CaptureErr reports err to Sentry attached to the request hub when present, otherwise to the global hub. Returns the original error unchanged so it can be used in `return observability.CaptureErr(ctx, err)` chains.

func IsEnabled

func IsEnabled() bool

IsEnabled reports whether Sentry was initialized successfully.

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware wraps an http.Handler with:

  • Panic recovery (reported to Sentry, then re-raised as 500)
  • Request-scoped Sentry hub
  • User context from edgeauth identity headers (via identity.FromContext)

Use AFTER edgeauth.Middleware so identity is already in context.

func MustInit

func MustInit(cfg Config) func()

MustInit initializes Sentry with kombify defaults. Safe to call even when SENTRY_DSN is unset — it becomes a no-op and returns a no-op shutdown.

Returns a shutdown function that should be deferred in main().

Types

type Config

type Config struct {
	// Service is the Sentry project slug (e.g. "kombify-cloud-backend").
	// Required when Enabled=true.
	Service string

	// DSN is the Sentry DSN. Defaults to os.Getenv("SENTRY_DSN").
	// When empty, observability is disabled (safe for local dev).
	DSN string

	// Environment is the Sentry environment tag ("prod", "dev", "preview").
	// Defaults to os.Getenv("SENTRY_ENVIRONMENT") or "prod".
	Environment string

	// Release is the release identifier, typically the Git SHA.
	// Defaults to os.Getenv("SENTRY_RELEASE").
	Release string

	// TracesSampleRate overrides the default (0.1 in prod, 1.0 in dev).
	TracesSampleRate *float64

	// Debug enables Sentry SDK debug logging.
	Debug bool
}

Config configures Sentry initialization for a kombify SaaS Go service.

Jump to

Keyboard shortcuts

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