Commit 54afe9e
authored
feat: add opt-in per-request overrides for content logging and raw request/response visibility (#3066)
## Summary
Adds two opt-in configuration flags — `allow_per_request_content_storage_override` and `allow_per_request_raw_override` — that gate whether per-request context keys and HTTP headers can override the global content logging and raw request/response visibility settings. When enabled, callers can suppress sensitive content (e.g. PII, credentials) from log records on specific requests via `x-bf-disable-content-logging`, or override raw capture behavior via `x-bf-send-back-raw-request`/`x-bf-send-back-raw-response`, without changing global configuration. When disabled (the default), provider-level and global settings remain authoritative and per-request overrides are silently ignored.
## Changes
- Added `BifrostContextKeyDisableContentLogging`, `BifrostContextKeyAllowPerRequestStorageOverride`, and `BifrostContextKeyAllowPerRequestRawOverride` to the `BifrostContextKey` enum.
- Introduced a `contentLoggingEnabled(ctx)` helper on `LoggerPlugin` that checks the per-request context override (only when `BifrostContextKeyAllowPerRequestStorageOverride` is set) before falling back to the global `disableContentLogging` config. This replaces all inline `p.disableContentLogging == nil || !*p.disableContentLogging` checks throughout the logging plugin.
- Propagated the resolved `contentLoggingEnabled` bool as an explicit parameter to `updateLogEntry`, `applyStreamingOutputToEntry`, `applyNonStreamingOutputToEntry`, and `applyRealtimeOutputToEntry`, removing the redundant local re-evaluation inside `applyRealtimeOutputToEntry`.
- Gated the existing `BifrostContextKeySendBackRawRequest`, `BifrostContextKeySendBackRawResponse`, and `BifrostContextKeyStoreRawRequestResponse` per-request overrides in `requestWorker` behind the new `BifrostContextKeyAllowPerRequestRawOverride` flag.
- Added `AllowPerRequestContentStorageOverride` and `AllowPerRequestRawOverride` fields to `ClientConfig` with corresponding hash entries, `Config` accessor methods, and two new methods on the `HandlerStore` interface (`ShouldAllowPerRequestStorageOverride`, `ShouldAllowPerRequestRawOverride`).
- Refactored `ConvertToBifrostContext` to accept a `HandlerStore` instead of individual parameters, propagating the new override flags into the bifrost context at request ingress.
- Added UI toggles for both new flags in the Logs Settings view and updated the `CoreConfig` TypeScript type and defaults.
- Added tests covering all precedence combinations (no config, global on/off, ctx override on/off, nil ctx), as well as integration-style tests for `updateLogEntry` and the apply-output helpers verifying both suppression and force-enable behavior.
- Documented the new `x-bf-disable-content-logging` option in `docs/providers/request-options.mdx` with cURL and Go SDK examples, precedence rules, and a prerequisite callout for `allow_per_request_content_storage_override`.
## Type of change
- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI
## Affected areas
- [x] Core (Go)
- [x] Transports (HTTP)
- [ ] Providers/Integrations
- [x] Plugins
- [x] UI (React)
- [x] Docs
## How to test
```sh
go test ./plugins/logging/... ./transports/bifrost-http/lib/...
```
To validate end-to-end via the gateway, first enable `allow_per_request_content_storage_override` in your logging config, then send a chat completion request with the header and confirm the log record omits message content while still recording token counts and latency:
```sh
curl --location 'http://localhost:8080/v1/chat/completions' \
--header 'x-bf-disable-content-logging: true' \
--header 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Sensitive data here"}]
}'
```
The resulting log record should have empty `input_history`, `output_message`, and `raw_request`/`raw_response` fields, while `total_tokens`, `latency`, and routing metadata remain populated.
To verify the gate is enforced, send the same request without enabling `allow_per_request_content_storage_override` — the header should be ignored and content should appear in the log record as normal.
## Breaking changes
- [x] No
## Security considerations
Both override flags default to `false`, meaning existing deployments are unaffected on upgrade. The per-request override is applied only at log-write time and does not affect what is sent to the upstream provider. Operators should consider carefully before enabling `allow_per_request_raw_override`, as it permits callers to request that raw provider payloads be returned in API responses.
## Checklist
- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable1 parent 4be4b78 commit 54afe9e
25 files changed
Lines changed: 855 additions & 357 deletions
File tree
- core
- schemas
- docs
- openapi/schemas/management
- providers
- framework/configstore
- plugins/logging
- transports
- bifrost-http
- handlers
- integrations
- lib
- ui
- app/workspace/config/views
- lib/types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5526 | 5526 | | |
5527 | 5527 | | |
5528 | 5528 | | |
5529 | | - | |
5530 | | - | |
| 5529 | + | |
| 5530 | + | |
| 5531 | + | |
| 5532 | + | |
| 5533 | + | |
5531 | 5534 | | |
5532 | 5535 | | |
5533 | | - | |
5534 | | - | |
| 5536 | + | |
| 5537 | + | |
| 5538 | + | |
| 5539 | + | |
5535 | 5540 | | |
5536 | 5541 | | |
5537 | | - | |
5538 | | - | |
| 5542 | + | |
| 5543 | + | |
| 5544 | + | |
| 5545 | + | |
| 5546 | + | |
5539 | 5547 | | |
5540 | 5548 | | |
5541 | 5549 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
251 | 254 | | |
252 | 255 | | |
253 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
177 | 188 | | |
178 | 189 | | |
179 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments