-
Notifications
You must be signed in to change notification settings - Fork 3
feat: req/resp logging middleware #105
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
base: main
Are you sure you want to change the base?
Conversation
beb1aca to
d021c47
Compare
|
|
||
| return func(req *http.Request, next MiddlewareNext) (*http.Response, error) { | ||
| if err := d.dumpRequest(req); err != nil { | ||
| fmt.Fprintf(os.Stderr, "apidump: failed to dump request: %v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe logger?
|
|
||
| resp, err := next(req) | ||
| if err != nil { | ||
| return resp, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about it but maybe it be useful to have "err" file with error?
intercept/apidump/apidump.go
Outdated
| var bodyBytes []byte | ||
| if resp.Body != nil { | ||
| var err error | ||
| bodyBytes, err = io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make streaming non responsive. I assume this is fine since logging should generally not be enabled other then when debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
| reqDumpData, err := os.ReadFile(reqDumpFile) | ||
| require.NoError(t, err, "request dump file should exist") | ||
| require.Contains(t, string(reqDumpData), "POST ") | ||
| require.Contains(t, string(reqDumpData), "Host:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add check like require.Contains(t, string(reqDumpData), string(reqBody))
and similar for response
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
ec13727 to
db0f11e
Compare

Logs the raw HTTP requests to and responses from AI providers' APIs.
$ tree /tmp/anthropic/ /tmp/anthropic/ ├── claude-haiku-4-5-20251001 │ ├── bb8e4048-8ea2-4aee-a58d-25027b962bf8.req.txt │ ├── bb8e4048-8ea2-4aee-a58d-25027b962bf8.resp.txt │ ├── e1f338a1-7ae9-4ccf-b898-fc3fbc25124e.req.txt │ └── e1f338a1-7ae9-4ccf-b898-fc3fbc25124e.resp.txt └── claude-opus-4-5-20251101 ├── 024f344e-c75a-46ea-abfb-e45e117e121a.req.txt ├── 024f344e-c75a-46ea-abfb-e45e117e121a.resp.txt ├── 0f02d1f5-882d-474f-b83d-85f09fd63ded.req.txt ├── 0f02d1f5-882d-474f-b83d-85f09fd63ded.resp.txt ├── 7f80f624-bf0b-4c12-a521-8c7654febe5d.req.txt ├── 7f80f624-bf0b-4c12-a521-8c7654febe5d.resp.txt ├── b9a37e54-1cd2-4a4f-92aa-c9adff088f4e.req.txt └── b9a37e54-1cd2-4a4f-92aa-c9adff088f4e.resp.txt