guardrail metrics: cover the /v1/messages (anthropic) path
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 157
- Forks
- 32
- Avg merge
- 1h 25m
- Merged PRs (30d)
- 145
Description
The guardrail outcome counters added in the test-connection observability work (aisix_guardrail_blocks_total / aisix_guardrail_bypasses_total) are recorded in chat.rs's centralized emit_usage_event, which covers /v1/chat/completions only.
The anthropic /v1/messages handler (messages.rs) ALSO runs the guardrail chain (resolve + check_input/check_output, returns ContentFiltered on block) but has a pre-existing telemetry gap: its UsageEvent / AnthropicStreamCompletion does not carry guardrail_blocked / bypass_reason, so the metric can't be recorded at its emit point. As a result the counters undercount anthropic guardrail blocks/bypasses.
Fix: thread guardrail_blocked + bypass_reason through the messages.rs telemetry (closing the AnthropicStreamCompletion gap) and record_guardrail_outcome at its emit, OR record at the messages verdict sites. This naturally folds into the applied-guardrails telemetry-threading work (#379 observability "A" slice), which reworks guardrail telemetry uniformly across both paths.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with chat.rs's centralized emit_usage_event and compare it with the /v1/messages handler in messages.rs, including UsageEvent and AnthropicStreamCompletion. Trace where guardrail resolve, check_input/check_output, and ContentFiltered verdicts are produced, then follow the telemetry-threading work in #379. Done means anthropic guardrail blocks and bypasses reach record_guardrail_outcome and the counters no longer undercount that path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100