Skip to content

Commit d9a344f

Browse files
authored
docs: document x-bf-dim-* unified dimensions and deprecate x-bf-prom-* headers (#3099)
## Summary Introduces `x-bf-dim-*` as the canonical unified header prefix for per-request observability dimensions in Bifrost. Previously, users had to use separate header families (`x-bf-prom-*`, `x-bf-maxim-*`) to propagate metadata to different backends. The new `x-bf-dim-*` prefix sends dimensions to all observability backends simultaneously — internal logs, OpenTelemetry spans, Prometheus custom labels, and Maxim tags — from a single set of headers. ## Changes - Documented `x-bf-dim-*` as the new canonical runtime dimension prefix, replacing `x-bf-prom-*` for cross-backend observability metadata - Added `BifrostContextKeyDimensions` (`map[string]string`) as the corresponding Go SDK context key - Deprecated `x-bf-prom-*` headers; they remain functional for Prometheus-only backward compatibility, but `x-bf-dim-*` takes precedence when both are present for the same label - Clarified the relationship between `x-bf-dim-*` and `x-bf-maxim-*`: shared dimensions flow to Maxim at lower priority, and explicit `x-bf-maxim-*` tags override same-named dimensions for Maxim only - Added a dedicated "Unified dimensions" section in `request-options.mdx` with cURL and Go SDK examples - Added a "Shared observability dimensions" section in the Maxim observability doc explaining forwarding behavior and priority rules ## Type of change - [ ] Bug fix - [ ] Feature - [ ] Refactor - [x] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [x] Docs ## How to test Verify the documented header behavior against a running Bifrost gateway: ```sh # Send a request with x-bf-dim-* headers and confirm dimensions appear in Prometheus metrics, # OpenTelemetry spans, and Maxim tags curl -X POST http://localhost:8080/v1/chat/completions \ -H "x-bf-dim-environment: production" \ -H "x-bf-dim-team: engineering" \ -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello!"}]}' # Confirm legacy x-bf-prom-* headers still work curl -X POST http://localhost:8080/v1/chat/completions \ -H "x-bf-prom-environment: production" \ -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello!"}]}' # Confirm x-bf-dim-* wins when both prefixes supply the same label curl -X POST http://localhost:8080/v1/chat/completions \ -H "x-bf-dim-environment: production" \ -H "x-bf-prom-environment: staging" \ -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello!"}]}' ``` ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No `x-bf-prom-*` headers continue to work. No existing behavior is removed. ## Related issues ## Security considerations Dimensions set via `x-bf-dim-*` are propagated to all observability backends including logs, spans, and external services such as Maxim. Callers should not include secrets or PII in dimension values. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] 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 applicable
1 parent eda9ab3 commit d9a344f

3 files changed

Lines changed: 87 additions & 11 deletions

File tree

docs/features/observability/maxim.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ Reserved keys are `session-id`, `trace-id`, `trace-name`, `generation-id`, `gene
188188
</Tab>
189189
</Tabs>
190190

191+
### Shared observability dimensions
192+
193+
For tags that should be visible beyond Maxim, use `x-bf-dim-*` instead of `x-bf-maxim-*`.
194+
195+
`x-bf-dim-*` is the canonical per-request dimension prefix in Bifrost. Those dimensions are forwarded to Maxim as tags at lower priority than explicit `x-bf-maxim-*` tags, and they are also propagated to internal logs, OpenTelemetry spans, and Prometheus custom labels.
196+
197+
```bash
198+
curl -X POST http://localhost:8080/v1/chat/completions \
199+
-H "x-bf-dim-environment: production" \
200+
-H "x-bf-dim-team: platform" \
201+
-d '{"model": "gpt-4", "messages": [...]}'
202+
```
203+
204+
If you send both `x-bf-dim-environment` and `x-bf-maxim-environment`, Maxim uses the explicit `x-bf-maxim-*` tag value while the shared dimension still flows to the other observability backends.
205+
191206
## Supported Request Types
192207

193208
The plugin supports the following Bifrost request types:

docs/features/telemetry.mdx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Bifrost provides built-in telemetry and monitoring capabilities through Promethe
1313
- **Prometheus Integration** - Native metrics collection at `/metrics` endpoint
1414
- **Comprehensive Tracking** - Success/error rates, token usage, costs, and cache performance
1515
- **Custom Labels** - Configurable dimensions for detailed analysis
16-
- **Dynamic Headers** - Runtime label injection via `x-bf-prom-*` headers
16+
- **Dynamic Headers** - Runtime label injection via `x-bf-dim-*` headers
1717
- **Cost Monitoring** - Real-time tracking of AI provider costs in USD
1818
- **Cache Analytics** - Direct and semantic cache hit tracking
1919
- **Async Collection** - Zero-latency impact on request processing
@@ -207,28 +207,33 @@ curl -X PATCH http://localhost:8080/config \
207207

208208
### Dynamic Label Injection
209209

210-
Add custom label values at runtime using `x-bf-prom-*` headers:
210+
Add custom label values at runtime using `x-bf-dim-*` headers:
211211

212212
```bash
213213
# Add custom labels to specific requests
214214
curl -X POST http://localhost:8080/v1/chat/completions \
215215
-H "Content-Type: application/json" \
216-
-H "x-bf-prom-team: engineering" \
217-
-H "x-bf-prom-environment: production" \
218-
-H "x-bf-prom-organization: my-org" \
219-
-H "x-bf-prom-project: my-project" \
216+
-H "x-bf-dim-team: engineering" \
217+
-H "x-bf-dim-environment: production" \
218+
-H "x-bf-dim-organization: my-org" \
219+
-H "x-bf-dim-project: my-project" \
220220
-d '{
221221
"model": "gpt-4o-mini",
222222
"messages": [{"role": "user", "content": "Hello!"}]
223223
}'
224224
```
225225

226226
**Header Format:**
227-
228-
- Prefix: `x-bf-prom-`
229-
- Label name: Any string after the prefix
227+
- Prefix: `x-bf-dim-`
228+
- Label name: Any string after the prefix, except reserved metric labels like `path` and `method`
230229
- Value: String value for the label
231230

231+
These runtime dimensions are also forwarded to the other observability backends. The same `x-bf-dim-*` values appear in internal logs, OpenTelemetry span attributes, and Maxim tags.
232+
233+
<Note>
234+
Legacy `x-bf-prom-*` headers still work for Prometheus-only behavior, but they are deprecated. When both prefixes provide the same label, `x-bf-dim-*` wins.
235+
</Note>
236+
232237
---
233238

234239
## Infrastructure Setup

docs/providers/request-options.mdx

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Bifrost provides request options that control behavior, enable features, and pas
3737
| `maxim.TraceIDKey` | `x-bf-maxim-trace-id` | `string` | Maxim trace ID |
3838
| `maxim.GenerationIDKey` | `x-bf-maxim-generation-id` | `string` | Maxim generation ID |
3939
| `maxim.TagsKey` | `x-bf-maxim-*` | `map[string]string` | Maxim tags (custom tag names) |
40-
| `BifrostContextKey(labelName)` | `x-bf-prom-*` | `string` | Prometheus metric labels |
40+
| `BifrostContextKeyDimensions` | `x-bf-dim-*` | `map[string]string` | Unified per-request dimensions forwarded to logs, spans, Prometheus custom labels, and Maxim tags |
41+
| `BifrostContextKey(labelName)` | `x-bf-prom-*` | `string` | Deprecated Prometheus-only label headers for backward compatibility |
4142

4243
## Request Configuration Options
4344

@@ -1065,14 +1066,67 @@ Input: messages,
10651066
</Tab>
10661067
</Tabs>
10671068
1069+
### Unified dimensions (x-bf-dim-*)
1070+
1071+
**Context Key:** `BifrostContextKeyDimensions`
1072+
**Header Pattern:** `x-bf-dim-{name}`
1073+
**Type:** `map[string]string`
1074+
**Required:** No
1075+
1076+
Add per-request dimensions once and have Bifrost forward them to all observability backends:
1077+
- internal logs as request metadata
1078+
- OpenTelemetry span attributes
1079+
- Prometheus custom labels when the dimension name matches a configured label
1080+
- Maxim generation and trace tags
1081+
1082+
`x-bf-dim-*` is now the canonical header prefix for runtime observability metadata.
1083+
1084+
<Tabs>
1085+
<Tab title="Gateway (cURL)">
1086+
```bash
1087+
curl --location 'http://localhost:8080/v1/chat/completions' \
1088+
--header 'x-bf-dim-environment: production' \
1089+
--header 'x-bf-dim-team: engineering' \
1090+
--header 'Content-Type: application/json' \
1091+
--data '{
1092+
"model": "openai/gpt-4o-mini",
1093+
"messages": [{"role": "user", "content": "Hello!"}]
1094+
}'
1095+
```
1096+
</Tab>
1097+
<Tab title="Go SDK">
1098+
```go
1099+
dims := map[string]string{
1100+
"environment": "production",
1101+
"team": "engineering",
1102+
}
1103+
ctx := context.Background()
1104+
ctx = context.WithValue(ctx, schemas.BifrostContextKeyDimensions, dims)
1105+
1106+
response, err := client.ChatCompletionRequest(schemas.NewBifrostContext(ctx, schemas.NoDeadline), &schemas.BifrostChatRequest{
1107+
Provider: schemas.OpenAI,
1108+
Model: "gpt-4o-mini",
1109+
Input: messages,
1110+
})
1111+
```
1112+
</Tab>
1113+
</Tabs>
1114+
1115+
<Note>
1116+
`x-bf-dim-*` values cannot override reserved Bifrost context keys such as request IDs or virtual keys. Also avoid sending secrets or PII in dimensions because they are propagated to observability backends.
1117+
For `x-bf-dim-*`, reserved metric labels `path` and `method` are ignored at runtime.
1118+
</Note>
1119+
10681120
### Maxim Tags (x-bf-maxim-*)
10691121

10701122
**Context Key:** `maxim.TagsKey`
10711123
**Header Pattern:** `x-bf-maxim-{tag-name}`
10721124
**Type:** `map[string]string`
10731125
**Required:** No
10741126

1075-
Add custom tags to Maxim traces. Any header starting with `x-bf-maxim-` that isn't a reserved header becomes a tag.
1127+
Add Maxim-specific tags to traces. Any header starting with `x-bf-maxim-` that isn't a reserved header becomes a tag.
1128+
1129+
Use `x-bf-dim-*` for tags that should also appear in logs, OpenTelemetry, and Prometheus. Use `x-bf-maxim-*` only for Maxim-specific tagging or when you need to override a same-named dimension for Maxim.
10761130

10771131
<Tabs>
10781132
<Tab title="Gateway (cURL)">
@@ -1116,6 +1170,8 @@ Input: messages,
11161170
11171171
Add custom labels to Prometheus metrics. The `x-bf-prom-` prefix is stripped and the remainder becomes the label name.
11181172
1173+
This header family is deprecated. Prefer `x-bf-dim-*`, which feeds Prometheus and the other observability backends together. If both `x-bf-dim-foo` and `x-bf-prom-foo` are present, the `x-bf-dim-*` value takes precedence for Prometheus.
1174+
11191175
<Tabs>
11201176
<Tab title="Gateway (cURL)">
11211177
```bash

0 commit comments

Comments
 (0)