Span-end reporting for EctoSparkles.NPlus1Detector: attaches telemetry handlers on Phoenix LiveView/router and Oban span endings that flush the per-process query counts at the end of each unit of work and log ONE consolidated warning per span for shapes repeated ≥ the threshold (config :ecto_sparkles, :n_plus_1_threshold, default 3).
Attach once at application start: EctoSparkles.NPlus1Reporter.setup(). The handlers run IN the LiveView/request/job process, so the flush clears exactly the state that unit of work accumulated. On :exception spans the state is cleared WITHOUT reporting, so a crashed span can't leak counts into the next one. Near-free when detection is off (the recommended prod default): the flush is a single pdict delete-miss.
Summary
Functions
Attach the flush/report handlers — a no-op unless NPlus1Detector.enabled?/0 (so callers can
invoke it unconditionally at boot or after flipping the config, and detection off means ZERO
attached handlers). Idempotent; pass events: to override the span list.