[APIP] Add error span to errors - #2989
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughAdds terminal HTTP outcome classification and OpenTelemetry tracing across policy-chain execution and ext_proc phases. It standardizes failure reporting, distinguishes policy and upstream outcomes, prevents stale terminal state, and adds comprehensive span-status tests. ChangesTerminal outcome tracing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ExternalProcessorServer
participant handleProcessingPhase
participant PolicyExecutionContext
participant RecordHTTPOutcome
ExternalProcessorServer->>handleProcessingPhase: process ext_proc phase
handleProcessingPhase->>PolicyExecutionContext: resolve terminal outcome
PolicyExecutionContext->>RecordHTTPOutcome: record status and terminal reason
RecordHTTPOutcome->>ExternalProcessorServer: update phase/root span
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
gateway/gateway-runtime/policy-engine/internal/kernel/extproc.go (1)
252-265: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFour near-identical outcome blocks; consider one helper.
The error-overwrite + success-stamp pair is copy-pasted across all four phase cases with only the comment differing. A small helper (e.g.
recordPhaseOutcome(span trace.Span, ec *PolicyExecutionContext, resp *extprocv3.ProcessingResponse, err error)) would keep the four phases from drifting apart later. Behaviour as written looks correct.Also applies to: 313-324, 367-378, 426-441
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@gateway/gateway-runtime/policy-engine/internal/kernel/extproc.go` around lines 252 - 265, Extract the repeated terminal-outcome overwrite and phase-span success recording into a shared helper, such as recordPhaseOutcome, using the existing span, execution context, response, and error values. Replace the duplicated blocks in all four phase cases with calls to this helper, preserving the current behavior for fatal errors, successful responses, and root-span stamping.gateway/gateway-runtime/policy-engine/internal/kernel/execution_context.go (1)
335-373: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valuePolicy
ImmediateResponsewith an unset status silently skips the memo update.If a policy returns an
ImmediateResponsewhoseStatusis nil/0,int(imm.GetStatus().GetCode())yields 0, so theout.StatusCode != 0guard at Line 369 leavesec.terminalholding whatever an earlier phase memoized while the phase span gets a bareterminal.reason=policy_deniedwith no status. Defaulting to the status the translator actually emits (or 500) would keep the two spans consistent.♻️ Possible hardening
} else { // Every other ImmediateResponse originates from a policy returning // policy.ImmediateResponse (auth denial, rate limit, guardrail, or a // python-bridge fault). + status := int(imm.GetStatus().GetCode()) + if status == 0 { + status = http.StatusInternalServerError + } out = tracing.HTTPOutcome{ - StatusCode: int(imm.GetStatus().GetCode()), + StatusCode: status, Reason: constants.TerminalReasonPolicyDenied, } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@gateway/gateway-runtime/policy-engine/internal/kernel/execution_context.go` around lines 335 - 373, Update resolveTerminalOutcome so policy ImmediateResponse results with a nil or zero status use the status emitted by the translator, falling back to 500 when no emitted status is available. Ensure the resulting nonzero StatusCode is assigned to ec.terminal, keeping the phase span and terminal memo consistent while preserving existing handling for explicit statuses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@gateway/gateway-runtime/policy-engine/internal/kernel/execution_context.go`:
- Around line 335-373: Update resolveTerminalOutcome so policy ImmediateResponse
results with a nil or zero status use the status emitted by the translator,
falling back to 500 when no emitted status is available. Ensure the resulting
nonzero StatusCode is assigned to ec.terminal, keeping the phase span and
terminal memo consistent while preserving existing handling for explicit
statuses.
In `@gateway/gateway-runtime/policy-engine/internal/kernel/extproc.go`:
- Around line 252-265: Extract the repeated terminal-outcome overwrite and
phase-span success recording into a shared helper, such as recordPhaseOutcome,
using the existing span, execution context, response, and error values. Replace
the duplicated blocks in all four phase cases with calls to this helper,
preserving the current behavior for fatal errors, successful responses, and
root-span stamping.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cba3b6e8-087e-4eb1-bf79-5c8f5986bdac
📒 Files selected for processing (8)
gateway/gateway-runtime/policy-engine/internal/constants/constants.gogateway/gateway-runtime/policy-engine/internal/executor/chain.gogateway/gateway-runtime/policy-engine/internal/executor/chain_span_status_test.gogateway/gateway-runtime/policy-engine/internal/kernel/execution_context.gogateway/gateway-runtime/policy-engine/internal/kernel/extproc.gogateway/gateway-runtime/policy-engine/internal/kernel/extproc_span_status_test.gogateway/gateway-runtime/policy-engine/internal/tracing/span_status.gogateway/gateway-runtime/policy-engine/internal/tracing/span_status_test.go
…ngine - Introduced new terminal reasons for better error tracking: `TerminalReasonPolicyStatusOverride` and `TerminalReasonProcessingFailed`. - Updated `PolicyExecutionContext` to track overridden response statuses. - Modified `RecordHTTPOutcome` to ensure correct span status classification based on terminal reasons.
No description provided.