stats-observer

command
v0.12.0 Latest Latest
Warning

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

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

Documentation

Overview

Package stats-observer demonstrates how to use stats.ValidationObserver and stats.ReportErrors with codecs directly — without any HTTP or MQTT adapter.

This is the codec-only observability path: implement just stats.ValidationObserver (one method) and call stats.ReportErrors after each codex.Codec.Decode.

Scenario: an application validates its config file on startup. Invalid config fields emit stats.RecordValidationError events that a production observer would route to Prometheus counters, structured logs, or alerting.

The final section demonstrates stats.TraceObserver — an additive optional interface for distributed tracing. Implement StartSpan/EndSpan against your tracing backend (OpenTelemetry, Datadog, etc.) and wire it via stats.NewFanout alongside metrics and logging observers.

The last section demonstrates the observer pattern in PLAIN BUSINESS LOGIC — a function with no pipeline, no adapter, just a direct call — using the same stats.ObserverFromContext lookup adapters use internally, a manual stats.TraceObserver span, and a custom domain-specific observer interface (OrderObserver) defined outside the stats package. It also demonstrates the one real gotcha: stats.NewFanout never forwards custom interfaces.

Run with: go run ./examples/stats-observer

Jump to

Keyboard shortcuts

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