Uh oh!
There was an error while loading. Please reload this page.
feat(config): add OPENCODE_DISABLE_METRICS to suppress individual metrics - #11
Conversation
…rics Adds a comma-separated env var to disable any subset of metrics by name suffix (without prefix), e.g. 'cache.count,retry.count'. - Parse OPENCODE_DISABLE_METRICS into a Set<string> in loadConfig() - Thread disabledMetrics through HandlerContext - Add isMetricEnabled() helper in util.ts - Guard all 13 instrument call sites across session, message, activity handlers - Disabling a metric skips the counter/histogram only — log events still emit - Add 23 tests covering parse, per-metric disable, and all-disabled scenario - Update README with env var docs and opencode-only metrics table
- Move retry debug log inside isMetricEnabled guard (was firing even when retry.count was disabled, giving a misleading message) - Hoist lines_of_code.count guard outside the diff loop in activity.ts (was evaluated twice per file; now evaluated once per event) - Pass disabled metrics as array in startup log (more queryable in log backends than a comma-joined string) - Restore user_prompt to README log events table (was accidentally dropped in the docs rewrite) - Add OPENCODE_DISABLE_METRICS to config.test.ts env var cleanup list (prevents stale env state leaking across test files) - Move loadConfig parsing tests for disabledMetrics into config.test.ts where env isolation is managed via beforeEach/afterEach - Add direct unit tests for isMetricEnabled in util.test.ts including unknown metric name case
Adds .pre-commit-config.yaml with: - pre-commit-hooks: trailing whitespace, end-of-file, merge conflicts, case conflicts, JSON validation, JSON formatting, YAML validation, LF line endings - markdownlint: MD013 (line length) and MD041 (first-line-heading) disabled via .markdownlint.yaml; MD024 set to siblings_only for CHANGELOG compatibility - local TypeScript typecheck hook via bun run typecheck Also fixes all MD040 (missing fenced code language) violations in AGENTS.md and CONTRIBUTING.md by adding 'text' language to plaintext code blocks.
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdd environment-based metric disabling feature via Changes
Sequence Diagram(s)sequenceDiagram
participant ENV as Environment
participant Config as config.ts
participant Plugin as OtelPlugin (index.ts)
participant Context as HandlerContext
participant Handler as Handlers<br/>(session/message/activity)
participant Meter as OTel Meter
ENV->>Config: OPENCODE_DISABLE_METRICS="metric1,metric2"
activate Config
Config->>Config: Parse comma-separated list
Config->>Config: Populate Set<string>
Config-->>Plugin: Return config.disabledMetrics
deactivate Config
Plugin->>Context: Attach disabledMetrics: Set<string>
activate Context
Handler->>Context: Access ctx.disabledMetrics
deactivate Context
Handler->>Handler: isMetricEnabled("session.count", ctx)
alt Metric enabled
Handler->>Meter: counter.add()
else Metric disabled
Handler->>Handler: Skip metric emission
end
Handler->>Handler: Continue with logging<br/>(always emitted)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
OPENCODE_DISABLE_METRICSenv var — a comma-separated list of metric name suffixes to suppress (e.g.cache.count,retry.count)infolevel.pre-commit-config.yamlwith standard checks (JSON, YAML, Markdown, TypeScript)New env var
Metric name suffixes (without
OPENCODE_METRIC_PREFIX) — so the setting works regardless of prefix.opencode-only metrics table (added to README)
cache.countsession.durationsession.token.totalsession.cost.totalmodel.usageretry.countmessage.countImplementation
loadConfig()parsesOPENCODE_DISABLE_METRICSinto aSet<string>(trims whitespace, ignores empty segments)disabledMetricsthreaded throughHandlerContext— no globalsisMetricEnabled(name, ctx)helper inutil.ts— O(1)Set.has()checksession.ts,message.ts,activity.tslines_of_code.countguard hoisted outside the diff loopTests
130 tests passing. New coverage:
config.test.ts— 5 tests forloadConfigparsing (whitespace, trailing commas, etc.)util.test.ts— 5 direct unit tests forisMetricEnabledincluding unknown metric namedisabled-metrics.test.ts— per-metric disable tests + all-disabled integration testPre-commit hooks
pre-commit-hooks: trailing whitespace, EOF newline, merge conflicts, case conflicts, JSON validation + formatting, YAML, LF line endingsmarkdownlint: with.markdownlint.yaml(MD013/MD041 off, MD024 siblings-only for CHANGELOG)typecheck: runsbun run typecheckon any TypeScript changeSummary by CodeRabbit
New Features
OPENCODE_DISABLE_METRICSenvironment variable configuration option.Documentation
Chores