trace

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package trace is an opt-in, content-level debug tracer. When enabled (the server runs at the `trace` log level) it dumps the raw bytes flowing through the system (LLM prompt/response chains, raw HTTP feed-fetch bodies, and solimen-scraped HTML) to discrete files on disk so issues like non-UTF-8 feed responses or a misbehaving prompt chain can be inspected directly.

It is stdlib-only on purpose: keeping it free of project imports lets every layer (llmgateway, scrapers, manager) call into it without import cycles.

Every exported writer is a no-op when tracing is disabled and never returns an error to its caller; a failed trace write is logged and ignored so the debug facility can never break the main flow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Content

func Content(articleID, rawURL, reason, content string)

Content records article content that was rejected/notable for a given reason (e.g. "invalid-utf8") as its own byte-exact file plus a metadata sidecar, so the offending bytes, which would otherwise be dropped, stay inspectable.

func Enabled

func Enabled() bool

Enabled reports whether tracing is active. Call sites that must build a payload (e.g. read an HTTP body) should guard that work with this.

func HTTP

func HTTP(method, rawURL string, status int, contentType string, body []byte, dur time.Duration)

HTTP records a raw HTTP response body as its own file (exact bytes, so non-UTF-8 payloads stay inspectable) alongside a small metadata sidecar.

func Init

func Init(dir string, on bool) error

Init resolves the trace root and, when enabled, creates it and records its location. dir overrides the location; when empty a dedicated per-run folder under the OS temp dir is used (e.g. /tmp/downlink-trace-<timestamp>). When enabled is false this is a no-op and Enabled() stays false.

func LLM

func LLM(label, prompt, response string, dur time.Duration, callErr error, meta map[string]string)

LLM records a single prompt/response chain as one self-contained JSON file.

func SaveDiagnostic added in v0.2.0

func SaveDiagnostic(host string, status int, contentType string, body []byte) string

SaveDiagnostic writes a raw feed body to disk regardless of whether tracing is enabled, and returns the absolute path it wrote (empty on failure). It backs the on-demand `feeds diagnose` command and the parse-failure breadcrumb: those need the offending bytes even when the server is not running at trace log level.

When tracing is on the file lands under the active trace dir's fetch/ folder so it sits alongside the rest of the run; otherwise it goes to a stable, lazily created os.TempDir()/downlink-diagnose folder. Like every other writer here it never returns an error to its caller.

func Scrape

func Scrape(articleID, rawURL, state, html string)

Scrape records the raw HTML returned by a browser scrape (solimen) plus a metadata sidecar.

func SolimenRequest

func SolimenRequest(articleID, rawURL string, payload []byte)

SolimenRequest records the JSON query body POSTed to the solimen scrape service, so the exact request can be compared against its result.

Types

This section is empty.

Jump to

Keyboard shortcuts

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