-
Notifications
You must be signed in to change notification settings - Fork 6
feat(runner): accept caller trace headers for OpenRouter API requests #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jamespsterling
merged 7 commits into
main
from
devin/1787209755-openrouter-trace-headers
Aug 27, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e82aee
feat(runner): accept caller trace headers for OpenRouter API requests
jamespsterling 862f404
Merge remote-tracking branch 'origin/main' into devin/1787209755-open…
jamespsterling f4d8473
Merge remote-tracking branch 'origin/main' into devin/1787209755-open…
jamespsterling 5957182
fix(runner): match trace-header gate on exact URL or path-segment bou…
jamespsterling 4079d14
fix(runner): thread trace headers through the SDK request path and re…
jamespsterling ddf045b
test(runtime): assert generation lookup sends filtered trace headers
jamespsterling cd07550
Merge branch 'main' into devin/1787209755-openrouter-trace-headers
jamespsterling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
|
|
||
| import { filterTraceHeaders } from "./trace-headers"; | ||
|
|
||
| const TRACEPARENT = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"; | ||
|
|
||
| describe("filterTraceHeaders", () => { | ||
| it("keeps the allowed trace header names", () => { | ||
| expect( | ||
| filterTraceHeaders({ | ||
| traceparent: TRACEPARENT, | ||
| tracestate: "or=bench", | ||
| "x-or-traceparent": TRACEPARENT, | ||
| "x-benchmark-trace": "test-key", | ||
| }) | ||
| ).toEqual({ | ||
| traceparent: TRACEPARENT, | ||
| tracestate: "or=bench", | ||
| "x-or-traceparent": TRACEPARENT, | ||
| "x-benchmark-trace": "test-key", | ||
| }); | ||
| }); | ||
|
|
||
| it("normalizes header names to lowercase", () => { | ||
| expect(filterTraceHeaders({ Traceparent: TRACEPARENT })).toEqual({ | ||
| traceparent: TRACEPARENT, | ||
| }); | ||
| }); | ||
|
|
||
| it("drops disallowed header names such as authorization", () => { | ||
| expect( | ||
| filterTraceHeaders({ | ||
| traceparent: TRACEPARENT, | ||
| authorization: "Bearer attacker-key", | ||
| "x-session-id": "spoofed", | ||
| }) | ||
| ).toEqual({ traceparent: TRACEPARENT }); | ||
| }); | ||
|
|
||
| it("returns undefined when nothing survives the filter", () => { | ||
| expect(filterTraceHeaders({ authorization: "Bearer x" })).toBeUndefined(); | ||
| expect(filterTraceHeaders(undefined)).toBeUndefined(); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| export const ALLOWED_TRACE_HEADER_NAMES = [ | ||
| "traceparent", | ||
| "tracestate", | ||
| "x-or-traceparent", | ||
| "x-benchmark-trace", | ||
| ] as const; | ||
|
|
||
| export type AllowedTraceHeaderName = | ||
| (typeof ALLOWED_TRACE_HEADER_NAMES)[number]; | ||
|
|
||
| const ALLOWED_TRACE_HEADER_SET: ReadonlySet<string> = new Set( | ||
| ALLOWED_TRACE_HEADER_NAMES | ||
| ); | ||
|
|
||
| export function filterTraceHeaders( | ||
| headers: Readonly<Record<string, string>> | undefined | ||
| ): Record<string, string> | undefined { | ||
| if (headers === undefined) { | ||
| return undefined; | ||
| } | ||
| const filtered = Object.fromEntries( | ||
| Object.entries(headers) | ||
| .map(([name, value]): readonly [string, string] => [ | ||
| name.toLowerCase(), | ||
| value, | ||
| ]) | ||
| .filter(([name]) => ALLOWED_TRACE_HEADER_SET.has(name)) | ||
| ); | ||
| return Object.keys(filtered).length > 0 ? filtered : undefined; | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.