feat: add spanRequestHeaderAttributes and ENV mapping for CLI#1269
Merged
mathetake merged 3 commits intoenvoyproxy:mainfrom Oct 3, 2025
Merged
feat: add spanRequestHeaderAttributes and ENV mapping for CLI#1269mathetake merged 3 commits intoenvoyproxy:mainfrom
mathetake merged 3 commits intoenvoyproxy:mainfrom
Conversation
**Description** This adds header-to-attribute mapping for both OpenTelemetry spans and metrics, enabling session tracking and custom attribute propagation without requiring code instrumentation. Specifically, this deprecates `metricsRequestHeaderLabels` which was artificially Prometheus specific in favor of: **Kubernetes/extproc** - `spanRequestHeaderAttributes`: "x-session-id:session.id,x-user-id:user.id" - `metricsRequestHeaderAttributes`: "x-team-id:team.id,x-user-id:user.id" **CLI (aigw run)** To match convention of existing otel config, use ENV vars - OTEL_AIGW_SPAN_REQUEST_HEADER_ATTRIBUTES="x-session-id:session.id,x-user-id:user.id" - OTEL_AIGW_METRICS_REQUEST_HEADER_ATTRIBUTES="x-team-id:team.id,x-user-id:user.id" **Backward Compatibility** Full backward compatibility for the previous metricsRequestHeaderLabels flag: - Old flag: --metricsRequestHeaderLabels / controller.metricsRequestHeaderLabels - New flag: --metricsRequestHeaderAttributes / controller.metricsRequestHeaderAttributes - Fallback logic: If new flag is unset, old flag value is used - Deprecation warnings: Logged when old flag is detected - Removal timeline: Deprecated flag will be removed after v0.4 **Documentation** - site/docs/capabilities/observability/tracing.md#session-tracking - site/docs/cli/run.md#header-mapping - cmd/aigw/docker-compose-otel.yaml Signed-off-by: Adrian Cole <adrian@tetrate.io>
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (77.64%) is below the target coverage (86.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1269 +/- ##
==========================================
+ Coverage 77.60% 77.64% +0.03%
==========================================
Files 116 116
Lines 15192 15205 +13
==========================================
+ Hits 11790 11806 +16
+ Misses 2812 2808 -4
- Partials 590 591 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mathetake
approved these changes
Oct 3, 2025
Member
mathetake
left a comment
There was a problem hiding this comment.
Thanks for the cleanup & improvement as well on the existing header mapping!
missBerg
pushed a commit
to missBerg/ai-gateway
that referenced
this pull request
Dec 20, 2025
…roxy#1269) **Description** This uses the same header-to-attribute mapping approach for both OpenTelemetry spans and metrics, enabling session tracking and custom attribute propagation without requiring code instrumentation. Specifically, this deprecates `metricsRequestHeaderLabels` which was artificially Prometheus specific in favor of: **Kubernetes/extproc** - `spanRequestHeaderAttributes`: "x-session-id:session.id,x-user-id:user.id" - `metricsRequestHeaderAttributes`: "x-team-id:team.id,x-user-id:user.id" Note: Before we told people to lower_snake_case label values, but you don't need to do that because the prometheus exporter already does that. We shouldn't make mapping decisions like this in aigw as it interferes with non-prometheus metrics systems. This is particularly highlighted in "session.id" which is handled where if you made it "session_id" it wouldn't because the latter isn't an otel convention. **Related Issues/PRs** Fixes envoyproxy#1221 --------- Signed-off-by: Adrian Cole <adrian@tetrate.io> Signed-off-by: Erica Hughberg <erica.sundberg.90@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This uses the same header-to-attribute mapping approach for both OpenTelemetry spans and metrics, enabling session tracking and custom attribute propagation without requiring code instrumentation.
Specifically, this deprecates
metricsRequestHeaderLabelswhich was artificially Prometheus specific in favor of:Kubernetes/extproc
spanRequestHeaderAttributes: "x-session-id:session.id,x-user-id:user.id"metricsRequestHeaderAttributes: "x-team-id:team.id,x-user-id:user.id"Note: Before we told people to lower_snake_case label values, but you don't need to do that because the prometheus exporter already does that. We shouldn't make mapping decisions like this in aigw as it interferes with non-prometheus metrics systems. This is particularly highlighted in "session.id" which is handled where if you made it "session_id" it wouldn't because the latter isn't an otel convention.
CLI (aigw run)
To match convention of existing otel config, use ENV vars
Example App
I built from scratch like this
make build.aigw GOOS_LIST=linux cd cmd/aigw COMPOSE_PROFILES=phoenix docker compose -f docker-compose-otel.yaml up --build --wait -dThen I ran this
Then, my phoenix session had the expected session ID, mapped to the openai agent trace ID:
This includes all 3 LLM spans. This shows you can group the whole conversation even when normal tracing isn't setup on the client.
Related Issues/PRs
Fixes #1221
Special notes for reviewers
Backward compatibility for the previous
metricsRequestHeaderLabelsflag: