telemetry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaskIP

func MaskIP(ip string) string

MaskIP applies k-anonymity by truncating the last octet(s) of an IP address. IPv4: keeps /24 prefix, e.g. "203.0.113.45" → "203.0.113.0" IPv6: keeps /48 prefix, e.g. "2001:db8:1234::1" → "2001:db8:1234::" Returns the original string unchanged if it cannot be parsed as an IP.

Types

type Collector

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

Collector buffers and periodically ships telemetry events.

func New

func New(enabled bool, endpoint string, batchIntervalSec int, epsilon float64, salt string, logger *slog.Logger) *Collector

New creates a new Collector. batchIntervalSec is in seconds.

func (*Collector) Record

func (c *Collector) Record(event Event)

Record adds an event to the ring buffer. No-op if not enabled.

func (*Collector) Run

func (c *Collector) Run(ctx context.Context)

Run starts the periodic flush loop. It blocks until ctx is cancelled.

type Event

type Event struct {
	AgentIDHash      string    `json:"agentIdHash"`
	Timestamp        time.Time `json:"timestamp"`
	Method           string    `json:"method"`
	Direction        string    `json:"direction"` // "request" | "response"
	Success          bool      `json:"success"`
	LatencyMs        float64   `json:"latencyMs"`
	PayloadSizeBytes int       `json:"payloadSizeBytes"`
	AuthStatus       string    `json:"authStatus"` // "verified" | "failed" | "unsigned"
	ErrorCode        string    `json:"errorCode,omitempty"`
}

Event is a single telemetry event.

Jump to

Keyboard shortcuts

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