Commit 1dc774d
committed
fix(observability): stamp tenant org on gateway traffic docs (G-GATEWAY-INDEX-ORG)
Insights → Analytics/Accounting read ZEROS while offgrid-gateway holds 2,899 real
docs: those surfaces filter by term:{org} for tenant isolation, but the aggregator
shipped docs with no org field, so the filter matched 0 (proven live: match_all →
2899 hits, term org=default → 0).
Producer-side fix (the tenant filter is correct — dropping it would let one
tenant's cost model count another's traffic):
- aggregator reads x-offgrid-org off the request and stamps on the
observability record (absent ⇒ null: honestly unattributed, never guessed).
- new PURE gatewayAttribution({orgId,userId}) in lib/gateway.ts — one place that
builds the attribution headers, so call sites stop hand-writing them. Blank
values are DROPPED rather than sent empty (an empty header would attribute the
call to org "", worse than honestly unattributed).
- chat/stream (the interactive inference path, where orgId is already in scope)
now sends both headers.
4 unit tests on the pure helper. Suite 5079 pass / 0 fail; coverage green.
HONEST REMAINDER: agent/app-run inference still ships unattributed — gatewayAnswer
threads but not orgId, so that needs the param threaded through the
planner/compose signatures. Historical docs stay unattributed by design (guessing
an org for past traffic would fabricate attribution).1 parent 72a041b commit 1dc774d
4 files changed
Lines changed: 68 additions & 3 deletions
File tree
- scripts
- src
- app/api/v1/chat/stream
- lib
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
596 | 601 | | |
597 | 602 | | |
598 | 603 | | |
| |||
697 | 702 | | |
698 | 703 | | |
699 | 704 | | |
| 705 | + | |
700 | 706 | | |
701 | 707 | | |
702 | 708 | | |
703 | 709 | | |
704 | 710 | | |
705 | | - | |
| 711 | + | |
706 | 712 | | |
707 | 713 | | |
708 | 714 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
591 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
592 | 597 | | |
593 | 598 | | |
594 | 599 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
23 | 44 | | |
24 | 45 | | |
25 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments