2020-08-11 01:47:54 +02:00
|
|
|
# Logging and error reporting
|
2016-05-05 01:16:31 +02:00
|
|
|
|
2017-09-24 18:43:30 +02:00
|
|
|
Having a good system for logging error reporting is essential to
|
2021-08-20 21:53:28 +02:00
|
|
|
making a large project like Zulip successful. Without reliable error
|
2017-09-24 18:43:30 +02:00
|
|
|
reporting, one has to rely solely on bug reports from users in order
|
|
|
|
to produce a working product.
|
2016-05-05 01:16:31 +02:00
|
|
|
|
2017-09-24 18:43:30 +02:00
|
|
|
Our goal as a project is to have zero known 500 errors on the backend
|
2021-08-20 21:53:28 +02:00
|
|
|
and zero known JavaScript exceptions on the frontend. While there
|
2017-09-24 18:43:30 +02:00
|
|
|
will always be new bugs being introduced, that goal is impossible
|
|
|
|
without an efficient and effective error reporting framework.
|
|
|
|
|
2021-05-06 04:08:57 +02:00
|
|
|
We provide integration with [Sentry][sentry] to make it easier for
|
|
|
|
very large installations like zulip.com to manage their exceptions and
|
|
|
|
ensure they are all tracked down, but our default email-based system
|
|
|
|
is great for small installations.
|
2017-09-24 18:43:30 +02:00
|
|
|
|
|
|
|
## Backend error reporting
|
|
|
|
|
|
|
|
The [Django][django-errors] framework provides much of the
|
|
|
|
infrastructure needed by our error reporting system:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The ability to send emails to the server's administrators with any
|
2021-08-20 21:53:28 +02:00
|
|
|
500 errors, using the `mail_admins` function. We enhance these data
|
2017-09-24 18:43:30 +02:00
|
|
|
with extra details (like what user was involved in the error) in
|
|
|
|
`zerver/logging_handlers.py`, and then send them to the
|
|
|
|
administrator in `zerver/lib/error_notify.py` (which also supports
|
|
|
|
sending Zulips to a stream about production errors).
|
2021-08-20 21:45:39 +02:00
|
|
|
- The ability to rate-limit certain errors to avoid sending hundreds
|
2017-09-24 18:43:30 +02:00
|
|
|
of emails in an outage (see `_RateLimitFilter` in
|
|
|
|
`zerver/lib/logging_util.py`)
|
2021-08-20 21:45:39 +02:00
|
|
|
- A nice framework for filtering passwords and other important user
|
2017-09-24 18:43:30 +02:00
|
|
|
data from the exception details, which we use in
|
|
|
|
`zerver/filters.py`.
|
2021-08-20 21:45:39 +02:00
|
|
|
- Middleware for handling `JsonableError`, which is our standard
|
2021-06-30 18:46:10 +02:00
|
|
|
system for API code to return a JSON-format HTTP error response.
|
2017-09-24 18:43:30 +02:00
|
|
|
|
|
|
|
Since 500 errors in any Zulip server are usually a problem the server
|
|
|
|
administrator should investigate and/or report upstream, we have this
|
|
|
|
email reporting system configured to report errors by default.
|
|
|
|
|
2023-02-06 19:14:47 +01:00
|
|
|
### Sentry error logging
|
|
|
|
|
|
|
|
Zulip's optional backend [Sentry][sentry] integration will aggregate
|
|
|
|
errors to show which users and realms are affected, any logging which
|
|
|
|
happened prior to the exception, local variables in each frame of the
|
2021-05-06 04:08:57 +02:00
|
|
|
exception, and the full request headers which triggered it.
|
|
|
|
|
2023-02-06 19:14:47 +01:00
|
|
|
You can enable it by:
|
|
|
|
|
|
|
|
1. Create a [project][sentry-project] in your Sentry organization
|
|
|
|
with a platform of "Django."
|
|
|
|
2. Copy your [Sentry DSN][sentry-dsn] into `/etc/zulip/settings.py`
|
|
|
|
as `SENTRY_DSN`:
|
|
|
|
```python3
|
|
|
|
## Controls the DSN used to report errors to Sentry.io
|
|
|
|
SENTRY_DSN = "https://bbb@bbb.ingest.sentry.io/1234"
|
|
|
|
```
|
|
|
|
3. As the `zulip` user, restart Zulip by running:
|
|
|
|
```shell
|
|
|
|
/home/zulip/deployments/current/scripts/restart-server
|
|
|
|
```
|
|
|
|
|
2023-01-28 02:00:15 +01:00
|
|
|
You may also want to enable Zulip's [Sentry deploy
|
|
|
|
hook][sentry-deploy-hook].
|
|
|
|
|
2023-02-06 19:14:47 +01:00
|
|
|
[sentry-project]: https://docs.sentry.io/product/projects/
|
|
|
|
[sentry-dsn]: https://docs.sentry.io/product/sentry-basics/dsn-explainer/
|
2023-01-28 02:00:15 +01:00
|
|
|
[sentry-relase-hook]: ../production/deployment.md#sentry-deploy-hook
|
2023-02-06 19:14:47 +01:00
|
|
|
|
2017-09-24 18:43:30 +02:00
|
|
|
### Backend logging
|
|
|
|
|
|
|
|
[Django's logging system][django-logging] uses the standard
|
2021-08-20 21:53:28 +02:00
|
|
|
[Python logging infrastructure][python-logging]. We have configured
|
2017-09-24 18:43:30 +02:00
|
|
|
them so that `logging.exception` and `logging.error` get emailed to
|
|
|
|
the server maintainer, while `logging.warning` will just appear in
|
2021-08-20 21:53:28 +02:00
|
|
|
`/var/log/zulip/errors.log`. Lower log levels just appear in the main
|
2017-09-24 18:43:30 +02:00
|
|
|
server log (as well as in the log for corresponding process, be it
|
|
|
|
`django.log` for the main Django processes or the appropriate
|
|
|
|
`events_*` log file for a queue worker).
|
|
|
|
|
|
|
|
#### Backend logging format
|
|
|
|
|
|
|
|
The main Zulip server log contains a line for each backend request.
|
|
|
|
It also contains warnings, errors, and the full tracebacks for any
|
2021-08-20 21:53:28 +02:00
|
|
|
Python exceptions. In production, it goes to
|
2017-09-24 18:43:30 +02:00
|
|
|
`/var/log/zulip/server.log`; in development, it goes to the terminal
|
2023-03-04 02:17:54 +01:00
|
|
|
where you run `run-dev`.
|
2017-09-24 18:43:30 +02:00
|
|
|
|
2023-03-04 02:17:54 +01:00
|
|
|
In development, it's good to keep an eye on the `run-dev` console
|
2017-09-24 18:43:30 +02:00
|
|
|
as you work on backend changes, since it's a great way to notice bugs
|
|
|
|
you just introduced.
|
|
|
|
|
|
|
|
In production, one usually wants to look at `errors.log` for errors
|
|
|
|
since the main server log can be very verbose, but the main server log
|
|
|
|
can be extremely valuable for investigating performance problems.
|
2016-05-05 01:16:31 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```text
|
2020-03-24 12:45:29 +01:00
|
|
|
2016-05-20 14:50:22.056 INFO [zr] 127.0.0.1 GET 302 528ms (db: 1ms/1q) (+start: 123ms) / (unauth@zulip via ?)
|
2016-05-05 01:16:31 +02:00
|
|
|
[20/May/2016 14:50:22]"GET / HTTP/1.0" 302 0
|
2020-03-24 12:45:29 +01:00
|
|
|
2016-05-20 14:50:22.272 INFO [zr] 127.0.0.1 GET 200 124ms (db: 3ms/2q) /login/ (unauth@zulip via ?)
|
|
|
|
2016-05-20 14:50:26.333 INFO [zr] 127.0.0.1 POST 302 37ms (db: 6ms/7q) /accounts/login/local/ (unauth@zulip via ?)
|
2016-05-05 01:16:31 +02:00
|
|
|
[20/May/2016 14:50:26]"POST /accounts/login/local/ HTTP/1.0" 302 0
|
2020-03-24 12:45:29 +01:00
|
|
|
2016-05-20 14:50:26.538 INFO [zr] 127.0.0.1 POST 200 12ms (db: 1ms/2q) (+start: 53ms) /api/v1/events/internal [1463769771:0/0] (8@zulip via internal)
|
|
|
|
2016-05-20 14:50:26.657 INFO [zr] 127.0.0.1 POST 200 10ms (+start: 8ms) /api/v1/events/internal [1463769771:0/0] (8@zulip via internal)
|
|
|
|
2016-05-20 14:50:26.959 INFO [zr] 127.0.0.1 GET 200 588ms (db: 26ms/21q) / [1463769771:0] (8@zulip via website)
|
2016-05-05 01:16:31 +02:00
|
|
|
```
|
|
|
|
|
2017-09-24 18:43:30 +02:00
|
|
|
The format of this output is:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Timestamp
|
|
|
|
- Log level
|
|
|
|
- Logger name, abbreviated as "zr" for these Zulip request logs
|
|
|
|
- IP address
|
|
|
|
- HTTP method
|
|
|
|
- HTTP status code
|
|
|
|
- Time to process
|
|
|
|
- (Optional perf data details, e.g. database time/queries, memcached
|
2021-08-20 22:54:08 +02:00
|
|
|
time/queries, Django process startup time, Markdown processing time,
|
|
|
|
etc.)
|
2021-08-20 21:45:39 +02:00
|
|
|
- Endpoint/URL from zproject/urls.py
|
|
|
|
- "email via client" showing user account involved (if logged in) and
|
2021-08-20 22:54:08 +02:00
|
|
|
the type of client they used ("web", "Android", etc.).
|
2017-09-24 18:43:30 +02:00
|
|
|
|
|
|
|
The performance data details are particularly useful for investigating
|
|
|
|
performance problems, since one can see at a glance whether a slow
|
2020-08-11 01:47:49 +02:00
|
|
|
request was caused by delays in the database, in the Markdown
|
2017-09-24 18:43:30 +02:00
|
|
|
processor, in memcached, or in other Python code.
|
|
|
|
|
|
|
|
One useful thing to note, however, is that the database time is only
|
|
|
|
the time spent connecting to and receiving a response from the
|
2021-08-20 21:53:28 +02:00
|
|
|
database. Especially when response are large, there can often be a
|
2017-09-24 18:43:30 +02:00
|
|
|
great deal of Python processing overhead to marshall the data from the
|
|
|
|
database into Django objects that is not accounted for in these
|
|
|
|
numbers.
|
|
|
|
|
2022-05-10 01:34:06 +02:00
|
|
|
#### Searching backend log files
|
|
|
|
|
|
|
|
Zulip comes with a tool, `./scripts/log-search`, to quickly search
|
|
|
|
through the main `server.log` log file based on a number of different
|
|
|
|
axes -- including client IP address, client user-id, request path,
|
|
|
|
response code. It can also search the NGINX logs, which provide
|
|
|
|
similar information.
|
|
|
|
|
|
|
|
Because often the requests to static resources, or to things like user
|
|
|
|
avatars, are not as important, they are also filtered out of the
|
|
|
|
output by default.
|
|
|
|
|
|
|
|
The output shows timestamp, request duration, client IP address,
|
|
|
|
response code, and request method, hostname, and path; any property
|
|
|
|
which is limited by the tool is not displayed, for conciseness:
|
|
|
|
|
|
|
|
```
|
|
|
|
zulip@example-prod:~/deployments/current$ ./scripts/log-search realm-name
|
|
|
|
22:30:36.593 1ms 2606:2800:220:1:248:1893:25c8:1946 302 GET /
|
|
|
|
22:30:42.508 366ms 2606:2800:220:1:248:1893:25c8:1946 200 GET /login/
|
|
|
|
23:18:30.977 1ms 93.184.216.34 302 GET /
|
|
|
|
23:18:31.286 132ms 93.184.216.34 200 GET /login/
|
|
|
|
23:18:48.094 20ms 93.184.216.34 200 GET /accounts/password/reset/
|
|
|
|
23:18:51.520 149ms 93.184.216.34 200 GET /login/
|
|
|
|
23:18:59.420 20ms 93.184.216.34 200 GET /accounts/password/reset/
|
|
|
|
23:19:02.929 1300ms 93.184.216.34 302 POST /accounts/password/reset/
|
|
|
|
23:19:03.056 93ms 93.184.216.34 200 GET /accounts/password/reset/done/
|
|
|
|
23:19:08.911 26ms 93.184.216.34 302 GET /accounts/password/reset/OA/b56jfp-bd80ee99b98e703456b3bdcd91892be2/
|
|
|
|
23:19:09.189 116ms 93.184.216.34 200 GET /accounts/password/reset/OA/set-password/
|
|
|
|
23:19:18.743 215ms 93.184.216.34 302 POST /accounts/password/reset/OA/set-password/
|
|
|
|
23:19:18.779 12ms 93.184.216.34 200 GET /accounts/password/done/
|
|
|
|
23:19:20.796 12ms 93.184.216.34 200 GET /accounts/login/
|
|
|
|
23:19:29.323 295ms 8@ 93.184.216.34 302 POST /accounts/login/
|
|
|
|
23:19:29.704 362ms 8@ 93.184.216.34 200 GET /
|
|
|
|
23:20:04.980 110ms 8@ 93.184.216.34 200 DELETE /json/users/me/subscriptions
|
|
|
|
|
|
|
|
zulip@example-prod:~/deployments/current$ ./scripts/log-search 2606:2800:220:1:248:1893:25c8:1946
|
|
|
|
22:30:36.593 1ms 302 GET https://realm-one.example-prod.example.com/
|
|
|
|
22:30:42.508 366ms 200 GET https://realm-one.example-prod.example.com/login/
|
|
|
|
```
|
|
|
|
|
|
|
|
See `./scripts/log-search --help` for complete documentation.
|
|
|
|
|
2017-09-24 18:43:30 +02:00
|
|
|
## Blueslip frontend error reporting
|
|
|
|
|
|
|
|
We have a custom library, called `blueslip` (named after the form used
|
|
|
|
at MIT to report problems with the facilities), that takes care of
|
2021-08-20 21:53:28 +02:00
|
|
|
reporting JavaScript errors. In production, this means emailing the
|
2017-09-24 18:43:30 +02:00
|
|
|
server administrators (though the setting controlling this,
|
|
|
|
`BROWSER_ERROR_REPORTING`, is disabled by default, since most problems
|
|
|
|
are unlikely to be addressable by a system administrator, and it's
|
|
|
|
very hard to make JavaScript errors not at least somewhat spammy due
|
|
|
|
to the variety of browser versions and sets of extensions that someone
|
2021-08-20 21:53:28 +02:00
|
|
|
might use). In development, this means displaying a highly visible
|
2017-09-24 18:43:30 +02:00
|
|
|
overlay over the message view area, to make exceptions in testing a
|
|
|
|
new feature hard to miss.
|
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
- Blueslip is implemented in `web/src/blueslip.js`.
|
2021-08-20 21:45:39 +02:00
|
|
|
- In order to capture essentially any error occurring in the browser,
|
2020-04-19 07:37:22 +02:00
|
|
|
Blueslip listens for the `error` event on `window`, and has methods
|
|
|
|
for being manually triggered by Zulip JavaScript code for warnings
|
|
|
|
and assertion failures.
|
2021-08-20 21:45:39 +02:00
|
|
|
- Blueslip keeps a log of all the notices it has received during a
|
2017-09-24 18:43:30 +02:00
|
|
|
browser session, and includes them in reports to the server, so that
|
2021-08-20 21:53:28 +02:00
|
|
|
one can see cases where exceptions chained together. You can print
|
2021-09-08 00:23:24 +02:00
|
|
|
this log from the browser console using
|
2023-02-24 02:20:53 +01:00
|
|
|
`blueslip = require("./src/blueslip"); blueslip.get_log()`.
|
2017-09-24 18:43:30 +02:00
|
|
|
|
|
|
|
Blueslip supports several error levels:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `throw new Error(…)`: For fatal errors that cannot be easily
|
2021-08-20 21:53:28 +02:00
|
|
|
recovered from. We try to avoid using it, since it kills the
|
2020-09-24 07:56:29 +02:00
|
|
|
current JS thread, rather than returning execution to the caller.
|
2021-08-20 21:45:39 +02:00
|
|
|
- `blueslip.error`: For logging of events that are definitely caused
|
2017-09-24 18:43:30 +02:00
|
|
|
by a bug and thus sufficiently important to be reported, but where
|
|
|
|
we can handle the error without creating major user-facing problems
|
|
|
|
(e.g. an exception when handling a presence update).
|
2021-08-20 21:45:39 +02:00
|
|
|
- `blueslip.warn`: For logging of events that are a problem but not
|
2021-08-20 21:53:28 +02:00
|
|
|
important enough to send an email about in production. They are,
|
2017-09-24 18:43:30 +02:00
|
|
|
however, highlighted in the JS console in development.
|
2021-08-20 21:45:39 +02:00
|
|
|
- `blueslip.log` (and `blueslip.info`): Logged to the JS console in
|
2021-08-20 21:53:28 +02:00
|
|
|
development and also in the blueslip log in production. Useful for
|
2017-09-24 18:43:30 +02:00
|
|
|
data that might help discern what state the browser was in during an
|
|
|
|
error (e.g. whether the user was in a narrow).
|
2021-08-20 21:45:39 +02:00
|
|
|
- `blueslip.debug`: Similar to `blueslip.log`, but are not printed to
|
2017-09-24 18:43:30 +02:00
|
|
|
the JS console in development.
|
|
|
|
|
2017-09-24 18:58:51 +02:00
|
|
|
## Frontend performance reporting
|
|
|
|
|
|
|
|
In order to make it easier to debug potential performance problems in
|
|
|
|
the critically latency-sensitive message sending code pathway, we log
|
|
|
|
and report to the server the following whenever a message is sent:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The time the user triggered the message (aka the start time).
|
|
|
|
- The time the `send_message` response returned from the server.
|
|
|
|
- The time the message was received by the browser from the
|
2017-09-24 18:58:51 +02:00
|
|
|
`get_events` protocol (these last two race with each other).
|
2021-08-20 21:45:39 +02:00
|
|
|
- Whether the message was locally echoed.
|
|
|
|
- If so, whether there was a disparity between the echoed content and
|
2017-09-24 18:58:51 +02:00
|
|
|
the server-rendered content, which can be used for statistics on how
|
2022-02-24 00:17:21 +01:00
|
|
|
effective our [local echo system](markdown.md) is.
|
2017-09-24 18:58:51 +02:00
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
The code is all in `zerver/lib/report.py` and `web/src/sent_messages.js`.
|
2017-09-24 18:58:51 +02:00
|
|
|
|
|
|
|
We have similar reporting for the time it takes to narrow / switch to
|
|
|
|
a new view:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The time the action was initiated
|
|
|
|
- The time when the updated message feed was visible to the user
|
|
|
|
- The time when the browser was idle again after switching views
|
2017-09-24 18:58:51 +02:00
|
|
|
(intended to catch issues where we generate a lot of deferred work).
|
|
|
|
|
2021-11-05 20:09:57 +01:00
|
|
|
[django-errors]: https://docs.djangoproject.com/en/3.2/howto/error-reporting/
|
2017-09-24 18:43:30 +02:00
|
|
|
[python-logging]: https://docs.python.org/3/library/logging.html
|
2021-11-05 20:09:57 +01:00
|
|
|
[django-logging]: https://docs.djangoproject.com/en/3.2/topics/logging/
|
2017-09-24 18:43:30 +02:00
|
|
|
[sentry]: https://sentry.io
|