Commit b67ede9
authored
Fix missing OTel span error recording in proxy handler; consolidate to semconv/v1.41.0 (#7576)
Three error paths in `handleWithDIFC` silently ended spans without
marking them as errors, causing 502/503 failures to appear as successful
spans in tracing backends. Additionally, `genai_attrs.go` imported
`semconv/v1.34.0` solely for GenAI attribute keys while the rest of the
codebase uses `semconv/v1.41.0`.
## P0 — Span error recording gaps in `proxy/handler.go`
Three paths in `handleWithDIFC` now call `tracing.RecordSpanError` /
`RecordSpanErrorOnAll` before returning:
| Path | Status | Fix |
|---|---|---|
| Guard not initialized | 503 | `RecordSpanError(difcSpan, ...)` with
description `"proxy enforcement not configured"` |
| `RunPipelinePrePhases` non-access-denied failure | 502 |
`RecordSpanError(difcSpan, err, ...)` |
| `forwardAndReadBody` returns nil | 502 | `RecordSpanErrorOnAll(...,
fwdSpan, difcSpan)` |
```go
// Case 3: both child and parent spans now reflect the failure
if resp == nil {
tracing.RecordSpanErrorOnAll(errors.New("upstream request failed"), "upstream request failed", fwdSpan, difcSpan)
return
}
```
## P1 — Consolidate dual semconv imports
Switches `genai_attrs.go` from `semconv/v1.34.0` to `semconv/v1.41.0` —
all five needed GenAI keys (`GenAIToolNameKey`, `GenAIOperationNameKey`,
`GenAIConversationIDKey`, `GenAIAgentNameKey`, `GenAIAgentIDKey`) are
present in v1.41.0. `GenAISystem` is defined as a raw
`attribute.Key("gen_ai.system")` since that constant was dropped from
v1.41.0, preserving the same wire string. The block comment on these
constants is updated to make clear that `GenAISystem` is special-cased
and not a semconv alias.
## P2 — Regression tests for span error recording
Added `internal/proxy/handler_difc_test.go` with three tests that inject
an in-memory recording tracer via `CachedTracer` and assert span status
code and exception events on each failure path:
- `TestHandleWithDIFC_GuardNotInitialized_SetsSpanError` — verifies the
503 path sets `Error` status with description `"proxy enforcement not
configured"` and emits an `exception` event on the DIFC pipeline span.
- `TestHandleWithDIFC_LabelResourceError_SetsSpanError` — verifies the
502 pre-phases-failure path sets `Error` status with description
`"resource labeling failed"` and emits an `exception` event.
- `TestHandleWithDIFC_UpstreamFailure_SetsSpanError` — verifies the 502
upstream-nil path sets `Error` status on both the
`proxy.backend.forward` child span and the `proxy.difc_pipeline` parent
span.3 files changed
Lines changed: 134 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| 189 | + | |
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
| |||
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
| 216 | + | |
214 | 217 | | |
215 | 218 | | |
216 | 219 | | |
| |||
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
| 237 | + | |
234 | 238 | | |
235 | 239 | | |
236 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
536 | 539 | | |
537 | 540 | | |
538 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
0 commit comments