Skip to content

feat(monitoring): add a switch to turn off the per-request metric - #114

Closed
geckofu wants to merge 1 commit into
masterfrom
feat/disable-request-metric
Closed

geckofu wants to merge 1 commit into
masterfrom
feat/disable-request-metric

Conversation

@geckofu

@geckofu geckofu commented Aug 26, 2026

Copy link
Copy Markdown
Member

Problem

monitoring.WithMonitor records a request measurement for every HTTP request. When the Monitor is the log monitor (the fallback when no InfluxDB is configured), that measurement is one log line per request.

On theplant/kakuyasu-services prod-mp that is 10.3M lines a week across 15 services. On the busiest one (web) it is 42% of the whole log volume. The lines carry path, method, response code and duration, which request tracing already has.

There was no way to turn it off short of not using appkit/service.

Change

  • monitoring.WithMonitorContextOnly(m): installs the Monitor in the request context but skips the request measurement. Handlers that record their own metrics through monitoring.ForceContext keep working.
  • appkit/service picks between WithMonitor and WithMonitorContextOnly based on MONITORING_DISABLE_REQUEST_METRIC, loaded with configor like the other middlewares in that package, and logs the decision at startup.

Default behaviour is unchanged: without the env var set, WithMonitor runs exactly as before.

Notes

  • WithMonitorContextOnly also skips the "cannot determine response code" warning, since that comes from building the measurement's tags.
  • Tests cover both paths: the metric is recorded by WithMonitor, not recorded by WithMonitorContextOnly, and the Monitor lands in the request context either way.

Test runs

  • go build ./...
  • go test ./monitoring/... ./service/... — both pass.

🤖 Generated with Claude Code

`monitoring.WithMonitor` records a "request" measurement for every HTTP
request. When the Monitor is the log monitor (no InfluxDB configured), that
is one log line per request. On theplant/kakuyasu-services prod-mp it is
10.3M lines a week across 15 services, 42% of the log volume of the busiest
one, carrying path, method, status code and duration that request tracing
already has.

Add `monitoring.WithMonitorContextOnly`, which installs the Monitor in the
request context but skips the measurement, so handlers recording their own
metrics keep working. `appkit/service` picks between the two on
`MONITORING_DISABLE_REQUEST_METRIC`, the same env-config pattern the other
middlewares in that package use.

Default behaviour is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@geckofu

geckofu commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

Closing: not the route we are taking. kakuyasu drops these lines at the log collector instead, matching how mcd already handles them in its firelens config. Leaving appkit's default behaviour alone.

@geckofu geckofu closed this Aug 26, 2026
@geckofu
geckofu deleted the feat/disable-request-metric branch August 26, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant