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
|
2023-06-10 01:01:05 +02:00
|
|
|
500 errors, using `django.utils.log.AdminEmailHandler`.
|
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-05-30 19:31:23 +02:00
|
|
|
[sentry-deploy-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
|
|
|
|
|
2023-03-29 19:07:36 +02:00
|
|
|
We have a custom library, called `blueslip` (named after the form used at MIT to
|
|
|
|
report problems with the facilities), that logs and reports JavaScript errors in
|
|
|
|
the browser. In production, this uses Sentry (if configured) to report and
|
|
|
|
aggregate errors. In development, this means displaying a highly visible overlay
|
|
|
|
over the message view area, to make exceptions in testing a new feature hard to
|
|
|
|
miss.
|
2017-09-24 18:43:30 +02:00
|
|
|
|
2023-03-11 08:13:37 +01:00
|
|
|
- Blueslip is implemented in `web/src/blueslip.ts`.
|
2023-03-29 19:07:36 +02:00
|
|
|
- In order to capture essentially any error occurring in the browser, in
|
|
|
|
development mode Blueslip listens for the `error` event on `window`.
|
|
|
|
- It also has methods for being manually triggered by Zulip JavaScript code for
|
|
|
|
warnings and assertion failures. Explicit `blueslip.error` calls are sent to
|
|
|
|
Sentry, if configured.
|
|
|
|
- Blueslip keeps a log of all the notices it has received during a browser
|
|
|
|
session, so that one can see cases where exceptions chained together. You can
|
|
|
|
print 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
|
|
|
|
2023-03-29 19:07:36 +02:00
|
|
|
- `throw new Error(…)`: For fatal errors that cannot be easily recovered
|
|
|
|
from. We try to avoid using it, since it kills the current JS thread, rather
|
|
|
|
than returning execution to the caller.
|
|
|
|
- `blueslip.error`: For logging of events that are definitely caused 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).
|
|
|
|
- `blueslip.warn`: For logging of events that are a problem but not important
|
|
|
|
enough to log an error to Sentry in production. They are, however, highlighted
|
|
|
|
in the JS console in development, and appear as breadcrumb logs in Sentry in
|
|
|
|
production.
|
|
|
|
- `blueslip.log` (and `blueslip.info`): Logged to the JS console in development
|
|
|
|
and also in the Sentry breadcrumb log in production. Useful for 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.
|
|
|
|
|
2023-04-11 22:44:36 +02:00
|
|
|
### Sentry JavaScript error logging
|
|
|
|
|
|
|
|
Zulip's optional JavaScript [Sentry][sentry] integration will aggregate errors
|
|
|
|
to show which users and realms are affected, any logging which happened prior to
|
|
|
|
the exception, and any DOM interactions which happened prior to the error.
|
|
|
|
|
|
|
|
You can enable it by:
|
|
|
|
|
|
|
|
1. Create a [project][sentry-project] in your Sentry organization
|
|
|
|
with a platform of "JavaScript."
|
|
|
|
2. Copy your [Sentry DSN][sentry-dsn] into `/etc/zulip/settings.py`
|
|
|
|
as `SENTRY_FRONTEND_DSN`:
|
|
|
|
```python3
|
|
|
|
## Controls the DSN used to report JavaScript errors to Sentry.io
|
|
|
|
SENTRY_FRONTEND_DSN = "https://bbb@bbb.ingest.sentry.io/1234"
|
|
|
|
```
|
|
|
|
3. If you wish to [sample][sentry-sample] some fraction of the errors, you
|
|
|
|
should adjust `SENTRY_FRONTEND_SAMPLE_RATE` down from `1.0`.
|
|
|
|
4. As the `zulip` user, restart Zulip by running:
|
|
|
|
```shell
|
|
|
|
/home/zulip/deployments/current/scripts/restart-server
|
|
|
|
```
|
|
|
|
|
|
|
|
You may also want to enable Zulip's [Sentry deploy
|
|
|
|
hook][sentry-deploy-hook].
|
|
|
|
|
|
|
|
[sentry-sample]: https://docs.sentry.io/platforms/javascript/configuration/sampling/
|
|
|
|
|
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-10-11 01:39:55 +02:00
|
|
|
The code is all in `zerver/lib/report.py` and `web/src/sent_messages.ts`.
|
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).
|
|
|
|
|
2017-09-24 18:43:30 +02:00
|
|
|
[python-logging]: https://docs.python.org/3/library/logging.html
|
2024-05-24 16:57:31 +02:00
|
|
|
[django-logging]: https://docs.djangoproject.com/en/5.0/topics/logging/
|
2017-09-24 18:43:30 +02:00
|
|
|
[sentry]: https://sentry.io
|