Skip to content

add trace_id in logs to identify all logs related to a request/error#1982

Merged
bnjjj merged 8 commits intodevfrom
bnjjj/feat_1981
Oct 26, 2022
Merged

add trace_id in logs to identify all logs related to a request/error#1982
bnjjj merged 8 commits intodevfrom
bnjjj/feat_1981

Conversation

@bnjjj
Copy link
Contributor

@bnjjj bnjjj commented Oct 21, 2022

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:

{
  "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:

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>
@bnjjj bnjjj self-assigned this Oct 21, 2022
@github-actions

This comment has been minimized.

bnjjj added 3 commits October 24, 2022 13:54
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj marked this pull request as ready for review October 26, 2022 09:44
@bnjjj bnjjj changed the title add request_id in logs to identify all logs related to a request/error add trace_id in logs to identify all logs related to a request/error Oct 26, 2022
bnjjj added 2 commits October 26, 2022 11:56
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Copy link
Contributor

@garypen garypen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. It makes me a bit sad that we are internalising so much of the tracing formatting code, but hey ho...

Couple of small questions.

@bnjjj
Copy link
Contributor Author

bnjjj commented Oct 26, 2022

@garypen I agree with you about internalising some tracing formatting code. I'm still pretty happy because I didn't had to copy paste the biggest part of json formatter, only small parts. Also that's why I started a draft PR in tracing to be able to implement filtering upstream and get rid of that part of the code.

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj merged commit 48780c4 into dev Oct 26, 2022
@bnjjj bnjjj deleted the bnjjj/feat_1981 branch October 26, 2022 15:59
@abernix abernix mentioned this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add id in logs in order to identify all the logs related to an error, to a request

3 participants