Add opt-in raw HTTP request/response logging - #93
Open
jcheng5 wants to merge 2 commits into
Open
Conversation
A fetch wrapper (raw-http-logging.ts) that captures byte-faithful .http request/response pairs for wire-level debugging of provider rejections, unlike the AI SDK-structured JsonRequestLogger view. Opt-in and dynamic: active while the configured raw-http/ directory exists (late binding, checked per chat call — mkdir mid-session to enable), or always-on via PA_RAW_HTTP_LOG_DIR. Credential-bearing header values are redacted; bodies are always byte-for-byte. All logging errors are swallowed so capture can never break a request. Wired into every AI SDK-backed model client (OpenAI, Anthropic, DeepSeek, Gemini, Vertex, Ollama, OpenRouter, Posit AI, Snowflake, Bedrock), composing with existing custom-fetch wrappers.
Look up node:fs lazily via process.getBuiltinModule instead of static node: imports so the module can be bundled into the Positron webview frontend (which shares chunks with the model clients). Outside Node, logging is simply disabled.
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.
Adds a fetch wrapper (
raw-http-logging.ts) that captures byte-faithful.httprequest/response pairs for wire-level debugging of provider rejections — the AI SDK-structuredJsonRequestLoggerview in the monorepo shows the SDK's interpretation of a call, not the actual bytes on the wire, which is exactly what you need when a provider returns a 400 you can't explain.Behavior
raw-http/directory exists — late binding, checked per chat call, so you canmkdirmid-session to enable capture without a restart.PA_RAW_HTTP_LOG_DIRturns it on unconditionally.node:fsis looked up lazily viaprocess.getBuiltinModulerather than a staticnode:import, so the module can be bundled into the Positron webview frontend (which shares chunks with the model clients). Outside Node, logging simply disables itself.Wired into every AI SDK-backed model client — OpenAI, Anthropic, DeepSeek, Gemini, Vertex, Ollama, OpenRouter, Posit AI, Snowflake, Bedrock — composing with each client's existing custom-fetch wrappers rather than replacing them.
Consumer
Needed by posit-dev/assistant#2015, which pins this branch and adds the per-deployment
raw-http/log directories plus therawHttpLogging.mdmemory-bank doc. That PR can't merge until this one does.🤖 Generated with Claude Code