-
Notifications
You must be signed in to change notification settings - Fork 276
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
Add id in logs in order to identify all the logs related to an error, to a request #1981
Comments
I like it. I wonder why have header control though? If it's good to have a request_id, why not just always return it as an I still think we want |
I don't know why not enabling it by default, it could just be a noise I think. But I don't have strong opinions. For error codes we will still be able to classify errors thanks to the For example: {
"data": {},
"errors": [
{
"message": "HTTP fetch failed from 'accounts': HTTP fetch failed from 'accounts': error trying to connect: tcp connect error: Connection refused (os error 111)",
"path": [],
"extensions": {
"type": "SubrequestHttpError",
"service": "accounts",
"reason": "HTTP fetch failed from 'accounts': error trying to connect: tcp connect error: Connection refused (os error 111)",
"request_id": "5e6a6bda8d0dca26e5aec14dafa6d96f"
}
}
]
} |
However it could be also way more easy to always enable the return of request_id because I won't have to manually add it on every errors in the errors array... |
Regarding error classification. I'm thinking about the use case where an admin is looking at server logs, not the use case where a client is looking at a response. |
@garypen To make sure there isn't any misunderstandings could you provide a real world example of what you would like to have as an admin. Maybe it's already done, but I want to be sure I understand correctly. BTW I made a changes in the way we will expose |
…1982) close #1981 It automatically adds a `trace_id` on logs to identify which log is related to a specific request. Also adds `trace_id` to an example error to have an example. This PR also refactor the way we handled formatters before, this refactor will let us be more flexible on which specific fields we want to display in logs. For now it keeps the current behavior which do not display any fields coming from current span and parent spans, only fields written directly in the log macro. Example of an error response: ```json { "data": {}, "errors": [ { "message": "HTTP fetch failed from 'accounts': HTTP fetch failed from 'accounts': error trying to connect: tcp connect error: Connection refused (os error 111)", "path": [], "extensions": { "type": "SubrequestHttpError", "service": "accounts", "reason": "HTTP fetch failed from 'accounts': error trying to connect: tcp connect error: Connection refused (os error 111)" } } ] } ``` with response header: ``` apollo_trace_id: 5e6a6bda8d0dca26e5aec14dafa6d96f ``` with related logs: ```logs 2022-10-21T15:17:45.562553Z ERROR [trace_id=5e6a6bda8d0dca26e5aec14dafa6d96f] apollo_router::services::subgraph_service: fetch_error="hyper::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" }))" 2022-10-21T15:17:45.565768Z ERROR [trace_id=5e6a6bda8d0dca26e5aec14dafa6d96f] apollo_router::query_planner::execution: Fetch error: HTTP fetch failed from 'accounts': HTTP fetch failed from 'accounts': error trying to connect: tcp connect error: Connection refused (os error 111) ``` Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Here is a sub task from #1840
The original idea was to provide a way to identify logs related to an error received in a GraphQL response with for example an
error_id
. I think we can do better by introduce arequest_id
in logs instead of just anerror_id
. In that way people who wants to debug a behavior without an error would be able to easily debug just by grepping therequest_id
in the logs.My proposal is to introduce
request_id
in fields for JSON formatter and directly in the text with of theTextFormatter
(including nice formatting).An addition to this experience we could introduce a way to directly ask to the router to return therequest_id
in the response thanks to GraphQL extensions to not limit it only for error cases. The way I imagine it is a configuration to indicate if we want to enable this debug mode and what kind of header should we pass to enable the ability to return therequest_id
.An addition to this experience we could introduce a way to directly ask to the router to return the
request_id
in the response headers.Something like
and have an answer like this:
headers:
And the formatted text log for example:
TODO:
The text was updated successfully, but these errors were encountered: