apilog

package
v0.263.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 8 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 for the playground's API Logs view. It is transport-level and independent of the TUI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transport

func Transport(base http.RoundTripper, rec *Recorder, apiURL 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.

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.

Jump to

Keyboard shortcuts

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