Skip to content

feat(cloudslog): store httpRequest, if available - #813

Draft
fredrikaverpil wants to merge 2 commits into
masterfrom
slog-error-reporting-v2
Draft

feat(cloudslog): store httpRequest, if available#813
fredrikaverpil wants to merge 2 commits into
masterfrom
slog-error-reporting-v2

Conversation

@fredrikaverpil

@fredrikaverpil fredrikaverpil commented Nov 6, 2025

Copy link
Copy Markdown
Member

Why?

There are additional fields we could put onto the error report. See
context.httpRequest part of the schema.

The request logging middleware currently only sets httpRequest on the record
after the handler returns (for access logging). This means errors logged
during request handling never have httpRequest available for error reports.

What?

  • Add a dedicated context key (cloudslog.WithHTTPRequest) to store a partial
    httpRequest on the context before request handling begins.
  • The error reporting handler reads from this context key to include
    httpRequest in the error report's context group.
  • The middleware (cloudrequestlog) sets the partial httpRequest on the
    context in all server-side entry points (gRPC unary, gRPC stream, HTTP).
  • The access log continues to build its own full httpRequest (with status,
    latency, response size) as a record attribute after the handler returns —
    no duplication or interference.

Notes

cc @ngalaiko — addressed your feedback
about the timing issue by using a context-based approach.

@fredrikaverpil
fredrikaverpil requested review from a team as code owners November 6, 2025 17:24
@fredrikaverpil fredrikaverpil self-assigned this Nov 6, 2025
@fredrikaverpil
fredrikaverpil force-pushed the slog-error-reporting-v2 branch 6 times, most recently from 9727839 to 3401e6a Compare November 6, 2025 17:36
@ngalaiko

ngalaiko commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

I think that would be nice to have, and I have tried it in my pr. One problem though: errors tend to happen during an http call. and cloudrequestlog will only set httpRequest when that is finished, for access logging

So to properly fix this, you should make sure that some of the httpRequest data (url, etc.) is set before request is handeled, and the rest (status code, duration) is added after.

http middleware: https://github.com/einride/cloudrunner-go/blob/master/cloudrequestlog/middleware.go#L189-L223

@fredrikaverpil
fredrikaverpil marked this pull request as draft December 1, 2025 16:42
Store a partial httpRequest on the context before request handling so
that error reports logged mid-request can include HTTP request context.
The previous approach extracted httpRequest from record attrs, but the
middleware only set that after the handler returned — too late for errors.
@fredrikaverpil
fredrikaverpil force-pushed the slog-error-reporting-v2 branch from 3401e6a to 31f94d0 Compare April 1, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants