pathfilter

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package pathfilter implements the Phase A "path-filter" plugin: an ObserveOnFinalize plugin that drops traces whose Path matches any operator-configured pattern.

Pattern semantics match the display-side filter the viewer already uses (see ROADMAP § 4 "path noise filter" + commit 5cbdda1):

  • Exact match: pattern "/api/v1/auth/me" matches Path "/api/v1/auth/me" only.
  • Prefix match via trailing "*": pattern "/api/v1/*" matches "/api/v1", "/api/v1/auth/me", "/api/v1/anything".
  • The lone pattern "*" disables the plugin (matches everything; would drop every trace — operators almost certainly don't want this, so we treat it as a config bug and reject it at Init).

Why match the display-side semantics: the viewer's path input and the capture-side skip both want to express the same operator intent ("ignore admin UI polling on /api/v1/*"). Identical syntax means the operator copies the same string into both places. Glob libraries (path.Match, doublestar) would be over-engineered for the v0 surface — two cases is enough.

Index

Constants

View Source
const Name = "path-filter"

Name is the plugin identifier used in config and telemetry.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Patterns is the list of paths to drop from recording. Exact match
	// or trailing-"*" prefix match per the package doc.
	Patterns []string `yaml:"patterns"`
}

Config is the YAML subtree under plugins.config.path-filter.

Defaults: zero value (Patterns: nil) is a no-op plugin that records every trace. The operator opts in by listing patterns.

type Plugin

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

Plugin is the path-filter implementation. It satisfies plugin.Plugin and plugin.ObserveOnFinalize. Construction is trivial; the patterns are compiled in Init.

func New

func New() *Plugin

New returns an uninitialized Plugin. The caller (Registry) MUST call Init before invoking OnFinalize — calling OnFinalize on a fresh Plugin yields shouldRecord=true (no patterns means nothing matches).

func (*Plugin) Close

func (p *Plugin) Close() error

Close is a no-op for path-filter; there is no buffered state.

func (*Plugin) Init

func (p *Plugin) Init(cfg map[string]any) error

Init parses cfg into compiled patterns. cfg is the raw map form produced by YAML unmarshaling at the plugin.Registry layer.

Accepted shape:

{"patterns": ["/api/v1/*", "/api/v1/auth/me"]}

nil cfg = no patterns = the plugin is a no-op; an absent block is the same as an explicit empty block.

Returns an error on:

  • Wrong type for "patterns" (not a list or list elements not strings).
  • The lone pattern "*" (operator config bug — would drop every trace).

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the constant plugin identifier.

func (*Plugin) OnFinalize

func (p *Plugin) OnFinalize(_ context.Context, tr trace.Trace) (bool, error)

OnFinalize returns shouldRecord=false when tr.Path matches any of the configured patterns, shouldRecord=true otherwise. The error return is always nil for path-filter — pattern matching cannot fail at runtime once patterns compile cleanly in Init.

The context is accepted to honor the plugin interface contract but is not consulted; matching is non-blocking and cheap.

Renamed from BeforeRecord per plugin-b-c-spec §7.3 (Phase A migration).

Jump to

Keyboard shortcuts

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