Edwin Kempin | 0ade5aa | 2018-08-10 08:49:32 +0200 | [diff] [blame] | 1 | = Request Tracing |
| 2 | |
| 3 | Gerrit supports on-demand tracing of single requests that results in |
| 4 | additional logs with debug information that are written to the |
| 5 | `error_log`. The logs that correspond to a traced request are |
| 6 | associated with a unique trace ID. This trace ID is returned with the |
| 7 | response and can be used by an administrator to find the matching log |
| 8 | entries. |
| 9 | |
| 10 | How tracing is enabled and how the trace ID is returned depends on the |
| 11 | request type: |
| 12 | |
| 13 | * REST API: For REST calls tracing can be enabled by setting the |
Edwin Kempin | 99ccd92 | 2018-09-10 10:06:53 +0200 | [diff] [blame] | 14 | `trace` request parameter or the `X-Gerrit-Trace` header, the trace |
| 15 | ID is returned as `X-Gerrit-Trace` header. More information about |
| 16 | this can be found in the link:rest-api.html#tracing[Request Tracing] |
| 17 | section of the link:rest-api.html[REST API documentation]. |
Edwin Kempin | 0ade5aa | 2018-08-10 08:49:32 +0200 | [diff] [blame] | 18 | * SSH API: For SSH calls tracing can be enabled by setting the |
| 19 | `--trace` option. More information about this can be found in |
| 20 | the link:cmd-index.html#trace[Trace] section of the |
| 21 | link:cmd-index.html[SSH command documentation]. |
| 22 | * Git: For Git pushes tracing can be enabled by setting the |
| 23 | `trace` push option, the trace ID is returned in the command output. |
| 24 | More information about this can be found in |
| 25 | the link:user-upload.html#trace[Trace] section of the |
| 26 | link:user-upload.html[upload documentation]. Tracing for Git requests |
| 27 | other than Git push is not supported. |
| 28 | |
Edwin Kempin | da82378 | 2018-08-29 22:52:54 +0200 | [diff] [blame] | 29 | When request tracing is enabled it is possible to provide an ID that |
| 30 | should be used as trace ID. If a trace ID is not provided a trace ID is |
| 31 | automatically generated. The trace ID must be provided to the support |
| 32 | team so that they can find the trace. |
| 33 | |
| 34 | When doing traces it is recommended to specify the ID of the issue |
| 35 | that is being investigated as trace ID so that the traces of the issue |
| 36 | can be found more easily. When the issue ID is used as trace ID there |
| 37 | is no need to find the generated trace ID and report it in the issue. |
| 38 | |
Edwin Kempin | c9ec778 | 2018-08-29 08:45:51 +0200 | [diff] [blame] | 39 | Since tracing consumes additional server resources tracing should only |
| 40 | be enabled for single requests if there is a concrete need for |
| 41 | debugging. In particular bots should never enable tracing for all their |
| 42 | requests by default. |
| 43 | |
Edwin Kempin | 0ade5aa | 2018-08-10 08:49:32 +0200 | [diff] [blame] | 44 | == Find log entries for a trace ID |
| 45 | |
| 46 | If tracing is enabled all log messages that correspond to the traced |
| 47 | request have a `TRACE_ID` tag set, e.g.: |
| 48 | |
| 49 | ---- |
| 50 | [2018-08-13 15:28:08,913] [HTTP-76] TRACE com.google.gerrit.httpd.restapi.RestApiServlet : Received REST request: GET /a/accounts/self (parameters: [trace]) [CONTEXT forced=true TRACE_ID="1534166888910-3985dfba" ] |
| 51 | [2018-08-13 15:28:08,914] [HTTP-76] TRACE com.google.gerrit.httpd.restapi.RestApiServlet : Calling user: admin [CONTEXT forced=true TRACE_ID="1534166888910-3985dfba" ] |
| 52 | [2018-08-13 15:28:08,942] [HTTP-76] TRACE com.google.gerrit.httpd.restapi.RestApiServlet : REST call succeeded: 200 [CONTEXT forced=true TRACE_ID="1534166888910-3985dfba" ] |
| 53 | ---- |
| 54 | |
| 55 | By doing a grep with the trace ID over the error log the log entries |
| 56 | that correspond to the request can be found. |
Edwin Kempin | ce92339b | 2018-08-29 09:56:16 +0200 | [diff] [blame] | 57 | |
| 58 | == Which information is captured in a trace? |
| 59 | |
| 60 | * request details |
| 61 | ** REST API: request URL, request parameter names, calling user, |
| 62 | response code, response body on errors |
| 63 | ** SSH API: parameter names |
| 64 | ** Git API: push options, magic branch parameter names |
| 65 | * cache misses, cache evictions |
| 66 | * reads from NoteDb, writes to NoteDb |
| 67 | * reads of meta data files, writes of meta data files |
| 68 | * index queries (with parameters and matches) |
| 69 | * reindex events |
| 70 | * permission checks (e.g. which rule is responsible for a deny) |
Edwin Kempin | eb17f3b | 2018-08-29 10:31:33 +0200 | [diff] [blame] | 71 | * timer metrics |
Edwin Kempin | ce92339b | 2018-08-29 09:56:16 +0200 | [diff] [blame] | 72 | * all other logs |