apilog

package
v0.271.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apilog captures OpenFGA HTTP traffic. It is transport-level and independent of the TUI: the playground buffers entries in a Recorder for its API Logs view, and `ofga --debug` streams them to stderr via a TraceWriter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transport

func Transport(base http.RoundTripper, rec Sink, apiURL string, configuredHeaders []string) http.RoundTripper

Transport returns an http.RoundTripper that records each attempt into rec. It sits beneath the SDK's auth/retry chain (installed via WithBaseTransport), so it sees the fully-decorated request and the raw response, and re-wraps both body streams so the SDK's own reads are never disturbed.

apiURL is the resolved OpenFGA API endpoint. The SDK also routes out-of-band OAuth token fetches (client_credentials / private_key_jwt) through this same base transport, and those requests carry secrets (client_secret in the request body, access_token in the response body) that must never be captured. Only requests whose host matches apiURL's host are recorded; everything else passes straight through unrecorded. As defense-in-depth for deployments where the token endpoint shares a host with the API (e.g. behind a gateway), captured bodies also go through redactBody, which masks known secret field names regardless of host.

configuredHeaders names the extra headers the caller sends on API requests (--header / a profile's headers list). Those carry gateway credentials, so their values are masked in captures too.

Types

type Entry

type Entry struct {
	Time                time.Time
	Method              string
	URL                 string
	ReqHeaders          http.Header
	ReqBody             []byte
	Status              int
	StatusText          string
	RespHeaders         http.Header
	RespBody            []byte
	Elapsed             time.Duration
	RequestID           string
	ServerQueryDuration string
	Err                 string
	Attempt             int
}

Entry is one captured HTTP attempt. Bodies are stored capped (see Transport); Err is set only on a transport-level failure, not on an HTTP error status.

type Recorder

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

Recorder is a concurrency-safe ring buffer of the most recent entries. Add is called from HTTP goroutines; Snapshot is read from the UI goroutine.

func NewRecorder

func NewRecorder(capacity int) *Recorder

NewRecorder returns a Recorder holding at most capacity entries.

func (*Recorder) Add

func (r *Recorder) Add(e Entry)

Add appends e, evicting the oldest entry past capacity, then fires notify.

func (*Recorder) Clear

func (r *Recorder) Clear()

Clear empties the buffer.

func (*Recorder) Len

func (r *Recorder) Len() int

Len returns how many entries the buffer currently holds (0..capacity), without copying them — cheap enough to call on every render.

func (*Recorder) SetNotify

func (r *Recorder) SetNotify(fn func())

SetNotify registers a callback fired after each Add (e.g. program.Send).

func (*Recorder) Snapshot

func (r *Recorder) Snapshot() []Entry

Snapshot returns an independent copy of the buffer, oldest first.

type Sink added in v0.267.0

type Sink interface {
	Add(Entry)
}

Sink receives each captured entry as it completes. The playground buffers them in a Recorder to render its API Logs view; the CLI's --debug streams them straight to stderr through a TraceWriter. Transport talks to this interface so neither consumer has to care what the other does.

Add is called from HTTP goroutines and may run concurrently, so implementations must be safe for concurrent use.

type TraceWriter added in v0.267.0

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

TraceWriter is a Sink that formats each entry to a writer as it completes, for `ofga --debug`. Unlike Recorder it keeps nothing: the point is to show the exchange while the command is still running, so a hung or slow request is visible before the process exits.

Everything it prints has already been through Transport's redaction (Authorization and cookie headers, secret-named JSON/form fields, URL query values), and Transport only ever hands it OpenFGA API traffic — OAuth token-fetch requests, which carry the client secret and the access token, are never captured in the first place.

func NewTraceWriter added in v0.267.0

func NewTraceWriter(w io.Writer) *TraceWriter

NewTraceWriter returns a Sink that writes a human-readable trace to w.

func (*TraceWriter) Add added in v0.267.0

func (t *TraceWriter) Add(e Entry)

Add renders one exchange. Concurrent callers (a parallel batch-check, a bulk tuple write) are serialized so two traces never interleave mid-line.

Jump to

Keyboard shortcuts

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