blob: d1fbb9783f7bcad970ff086484cc35a705b653f2 [file] [log] [blame]
Marian Harbachebeb1542019-12-13 10:42:46 +01001:linkattrs:
Edwin Kempin0ade5aa2018-08-10 08:49:32 +02002= Request Tracing
3
Edwin Kempin4a143162019-08-28 15:45:21 +02004[[on-demand]]
5== On-demand Request Tracing
6
Edwin Kempin0ade5aa2018-08-10 08:49:32 +02007Gerrit supports on-demand tracing of single requests that results in
8additional logs with debug information that are written to the
9`error_log`. The logs that correspond to a traced request are
10associated with a unique trace ID. This trace ID is returned with the
11response and can be used by an administrator to find the matching log
12entries.
13
14How tracing is enabled and how the trace ID is returned depends on the
15request type:
16
17* REST API: For REST calls tracing can be enabled by setting the
Edwin Kempin99ccd922018-09-10 10:06:53 +020018 `trace` request parameter or the `X-Gerrit-Trace` header, the trace
19 ID is returned as `X-Gerrit-Trace` header. More information about
20 this can be found in the link:rest-api.html#tracing[Request Tracing]
21 section of the link:rest-api.html[REST API documentation].
Edwin Kempin0ade5aa2018-08-10 08:49:32 +020022* SSH API: For SSH calls tracing can be enabled by setting the
23 `--trace` option. More information about this can be found in
24 the link:cmd-index.html#trace[Trace] section of the
25 link:cmd-index.html[SSH command documentation].
Edwin Kempinc9a076d2018-12-13 09:03:37 +010026* Git Push (requires usage of git protocol v2): For Git pushes tracing
27 can be enabled by setting the `trace` push option, the trace ID is
28 returned in the command output. More information about this can be
29 found in the link:user-upload.html#trace[Trace] section of the
30 link:user-upload.html[upload documentation].
31* Git Clone/Fetch/Ls-Remote (requires usage of git protocol v2): For
32 Git clone/fetch/ls-remote tracing can be enabled by setting the
33 `trace` server option. Use '-o trace=<TRACE-ID>' for `git fetch` and
34 `git ls-remote`, and '--server-option trace=<TRACE-ID>' for
35 `git clone`. If the `trace` server option is set without a value
36 (without trace ID) a trace ID is generated but the generated trace ID
37 is not returned to the client (hence a trace ID should always be
38 set).
Edwin Kempin0ade5aa2018-08-10 08:49:32 +020039
Edwin Kempinda823782018-08-29 22:52:54 +020040When request tracing is enabled it is possible to provide an ID that
41should be used as trace ID. If a trace ID is not provided a trace ID is
42automatically generated. The trace ID must be provided to the support
Edwin Kempinf6de7742019-08-28 15:39:56 +020043team (administrator of the server) so that they can find the trace.
Edwin Kempinda823782018-08-29 22:52:54 +020044
45When doing traces it is recommended to specify the ID of the issue
46that is being investigated as trace ID so that the traces of the issue
47can be found more easily. When the issue ID is used as trace ID there
48is no need to find the generated trace ID and report it in the issue.
49
Edwin Kempinc9ec7782018-08-29 08:45:51 +020050Since tracing consumes additional server resources tracing should only
51be enabled for single requests if there is a concrete need for
52debugging. In particular bots should never enable tracing for all their
53requests by default.
54
Edwin Kempinb4926332019-08-28 17:07:17 +020055[[auto-retry]]
56== Automatic Request Tracing
57
58Gerrit can be link:config-gerrit.html#retry.retryWithTraceOnFailure[
59configured] to automatically retry requests on non-recoverable failures
60with tracing enabled. This allows to automatically captures traces of
61these failures for further analysis by the Gerrit administrators.
62
63The auto-retry on failure behaves the same way as if the calling user
64would retry the failed operation with tracing enabled.
65
66It is expected that the auto-retry fails with the same exception that
67triggered the auto-retry, however this is not guaranteed:
68
69* Not all Gerrit operations are fully atomic and it can happen that
70 some parts of the operation have been successfully performed before
71 the failure happened. In this case the auto-retry may fail with a
72 different exception.
73* Some exceptions may mistakenly be considered as non-recoverable and
74 the auto-retry actually succeeds.
75
76[[auto-retry-succeeded]]
77If an auto-retry succeeds you may consider filing this as
Edwin Kempin135f0022023-06-20 12:30:21 +000078link:https://issues.gerritcodereview.com/issues/new?component=1371020[
Marian Harbach34253372019-12-10 18:01:31 +010079Gerrit issue,role=external,window=_blank] so that the Gerrit developers can fix this and treat this
Edwin Kempinb4926332019-08-28 17:07:17 +020080exception as recoverable.
81
82The trace IDs for auto-retries are generated and start with
Edwin Kempin8e8c9d12019-09-24 08:52:35 +020083`retry-on-failure-`. For REST requests they are returned to the client
84as `X-Gerrit-Trace` header.
Edwin Kempinb4926332019-08-28 17:07:17 +020085
86The best way to search for auto-retries in logs is to do a grep by
87`AutoRetry`. For each auto-retry that happened this should match 1 or 2
88log entries:
89
Edwin Kempin6a81e442019-12-18 08:41:21 +010090* one `FINE` log entry with the exception that triggered the auto-retry
Edwin Kempinb4926332019-08-28 17:07:17 +020091* one `FINE` log entry with the exception that happened on auto-retry
92 (if this log entry is not present the operation succeeded on
93 auto-retry)
94
95To inspect single auto-retry occurrences in detail you can do a
96link:#find-trace[grep by the trace ID]. The trace ID is part of the log
97entries which have been found by the previous grep (watch out for
98something like: `retry-on-failure-1534166888910-3985dfba`).
99
100[TIP]
101Auto-retrying on failures is only supported by some of the REST
102endpoints (change REST endpoints that perform updates).
103
104[[auto-retry-metrics]]
105=== Metrics
106
107If auto-retry is link:config-gerrit.html#retry.retryWithTraceOnFailure[
108enabled] the following metrics are reported:
109
110* `action/auto_retry_count`: Number of automatic retries with tracing
111* `action/failures_on_auto_retry_count`: Number of failures on auto retry
112
113By comparing the values of these counters one can see how often the
114auto-retry succeeds. As explained link:#auto-retry-succeeded[above] if
115auto-retries succeed that's an issue with Gerrit that you may want to
116report.
117
118[[find-trace]]
Edwin Kempin0ade5aa2018-08-10 08:49:32 +0200119== Find log entries for a trace ID
120
121If tracing is enabled all log messages that correspond to the traced
122request have a `TRACE_ID` tag set, e.g.:
123
124----
125[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" ]
126[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" ]
127[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" ]
128----
129
130By doing a grep with the trace ID over the error log the log entries
131that correspond to the request can be found.
Edwin Kempince92339b2018-08-29 09:56:16 +0200132
Edwin Kempinf6de7742019-08-28 15:39:56 +0200133[TIP]
134Usually only server administrators have access to the logs.
135
Edwin Kempince92339b2018-08-29 09:56:16 +0200136== Which information is captured in a trace?
137
138* request details
139** REST API: request URL, request parameter names, calling user,
140 response code, response body on errors
141** SSH API: parameter names
142** Git API: push options, magic branch parameter names
143* cache misses, cache evictions
144* reads from NoteDb, writes to NoteDb
145* reads of meta data files, writes of meta data files
146* index queries (with parameters and matches)
147* reindex events
148* permission checks (e.g. which rule is responsible for a deny)
Edwin Kempineb17f3b2018-08-29 10:31:33 +0200149* timer metrics
Edwin Kempince92339b2018-08-29 09:56:16 +0200150* all other logs
Edwin Kempin48a23162021-09-01 12:48:49 +0200151
152GERRIT
153------
154Part of link:index.html[Gerrit Code Review]
155
156SEARCHBOX
157---------