request-metrics

Implement per-request domain metrics in Spring Boot using a Filter, Recorder, and Parser pattern.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill request-metrics-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: request-metrics
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/request-metrics
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill request-metrics-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Adding latency metrics for new REST endpoints in a Spring Boot service often means scattering timing logic across controllers and filters, producing inconsistent tags and duplicated code. This Skill provides a canonical Filter + Recorder + Parser architecture where every request is measured once by a single OncePerRequestFilter, routed by a registry to a use-case-specific MetricsRecorder, and tagged by pluggable parsers — so adding a new endpoint metric requires exactly one new class. ## Core Features & Use Cases - Single measurement point: One MetricsFilter measures elapsed time for every request in a try/finally block, so failed requests are still recorded, and actuator paths are excluded. - Open/closed metric extension: A MetricsRecorderRegistry auto-discovers all MetricsRecorder beans via Spring constructor injection; new metrics are purely additive with zero changes to the filter or registry. - Structured, safe tagging: Parsers extract HTTP method, response status, and authenticated client ID, always returning non-blank sentinel values so Prometheus never rejects a metric; SLO histogram buckets are defined once in MetricsTimerHelper. - Use Case: You need a latency timer for a new /api/v1/entities/{id}/convert endpoint tagged by target format. Add one constant, one URI pattern entry, one TargetFormatParser, and one ConvertEntityMetricsRecorder — nothing else changes. ## Quick Start Apply the request-metrics skill to add a Micrometer timer metric for a new REST endpoint in my Spring Boot service, following the Filter, Recorder, and Parser package structure.

Frequently Asked Questions about request-metrics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add custom per-endpoint metrics in Spring Boot?

Use a single OncePerRequestFilter to measure elapsed time, resolve the metric name from a URI pattern map, and delegate to a MetricsRecorder implementation. Adding a metric for a new endpoint requires only one new recorder class plus a constant and URI pattern entry.

How to add tags to Micrometer Timer metrics in Spring Boot?

Extract tags with dedicated parser components that read the request, response, or SecurityContext, then assemble them in a tags helper passed to Timer.builder. Parsers must never return null or empty strings because Prometheus rejects blank label values.

Does OncePerRequestFilter record metrics when the request throws an exception?

Yes, when the timing logic wraps filterChain.doFilter in a try/finally block, the finally clause records elapsed time even if the handler throws. This ensures failed requests still appear in latency metrics with their actual response status.

Why should actuator endpoints be excluded from custom request metrics?

Spring Boot Actuator endpoints already expose their own Micrometer metrics, so measuring them in a domain metrics filter would pollute custom counters. Override shouldNotFilter to skip any URI containing actuator.

When should I use SLO buckets instead of percentile histograms in Micrometer?

Use serviceLevelObjectives with fixed Duration buckets when you want predictable Prometheus cardinality and alerting against known latency thresholds. Percentile histograms generate many more time series, which increases storage and query cost.