Commit Graph

64 Commits

Author SHA1 Message Date
Patrick Cloke
1619802228
Various clean-ups to the logging context code () 2020-12-14 14:19:47 -05:00
Patrick Cloke
8b42a4eefd
Gracefully handle a pending logging connection during shutdown. () 2020-10-29 12:53:57 -04:00
Patrick Cloke
00b24aa545
Support generating structured logs in addition to standard logs. ()
This modifies the configuration of structured logging to be usable from
the standard Python logging configuration.

This also separates the formatting of logs from the transport allowing
JSON logs to files or standard logs to sockets.
2020-10-29 07:27:37 -04:00
Erik Johnston
2b7c180879
Start fewer opentracing spans ()
 started a span for every background process. This is good as it means all Synapse code that gets run should be in a span (unless in the sentinel logging context), but it means we generate about 15x the number of spans as we did previously.

This PR attempts to reduce that number by a) not starting one for send commands to Redis, and b) deferring starting background processes until after we're sure they're necessary.

I don't really know how much this will help.
2020-10-26 09:30:19 +00:00
Patrick Cloke
20a67aa70d
Separate the TCP and terse JSON formatting code. ()
This should (theoretically) allow for using the TCP code with a different output type
and make it easier to use the JSON code with files / console.
2020-10-21 06:59:54 -04:00
Patrick Cloke
4ff0201e62
Enable mypy checking for unreachable code and fix instances. () 2020-10-01 08:09:18 -04:00
Richard van der Hoff
5e3ca12b15
Create a mechanism for marking tests "logcontext clean" () 2020-09-28 17:58:33 +01:00
Patrick Cloke
8a4a4186de
Simplify super() calls to Python 3 syntax. ()
This converts calls like super(Foo, self) -> super().

Generated with:

    sed -i "" -Ee 's/super\([^\(]+\)/super()/g' **/*.py
2020-09-18 09:56:44 -04:00
Patrick Cloke
aec294ee0d
Use slots in attrs classes where possible ()
slots use less memory (and attribute access is faster) while slightly
limiting the flexibility of the class attributes. This focuses on objects
which are instantiated "often" and for short periods of time.
2020-09-14 12:50:06 -04:00
Patrick Cloke
d2a3eb04a4 Fix typos in comments. 2020-09-14 11:46:58 -04:00
Richard van der Hoff
703e2b8a96
Use the right constructor for log records ()
Update `log_function` to use the right factory to create log records, to make
sure that they have `request` attributes.

Fixes: .
2020-09-08 14:52:51 +01:00
Patrick Cloke
c619253db8
Stop sub-classing object () 2020-09-04 06:54:56 -04:00
Patrick Cloke
dbc630a628
Use the JSON encoder without whitespace in more places. () 2020-08-20 10:32:33 -04:00
Patrick Cloke
eebf52be06
Be stricter about JSON that is accepted by Synapse () 2020-08-19 07:26:03 -04:00
Erik Johnston
1ef9efc1e0
Fix error reporting when using opentracing.trace () 2020-07-27 16:20:24 +01:00
Richard van der Hoff
15997618e2
Clean up PreserveLoggingContext ()
This had some dead code and some just plain wrong docstrings.
2020-07-22 00:40:27 +01:00
Karthikeyan Singaravelan
5662e2b0f3
Remove unused code from synapse.logging.utils. () 2020-07-20 15:20:53 -04:00
Patrick Cloke
d1d5fa66e4
Fix the trace function for async functions. ()
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2020-07-17 13:32:01 -04:00
Will Hunt
62b1ce8539
isort 5 compatibility ()
The CI appears to use the latest version of isort, which is a problem when isort gets a major version bump. Rather than try to pin the version, I've done the necessary to make isort5 happy with synapse.
2020-07-05 16:32:02 +01:00
Erik Johnston
5cdca53aa0
Merge different Resource implementation classes () 2020-07-03 19:02:19 +01:00
Erik Johnston
e07a8caf58
Add support for using rust-python-jaeger-reporter () 2020-06-17 14:13:41 +01:00
Dagfinn Ilmari Mannsåker
a3f11567d9
Replace all remaining six usage with native Python 3 equivalents () 2020-06-16 08:51:47 -04:00
Richard van der Hoff
d4676910c9 remove miscellaneous PY2 code 2020-05-15 19:37:41 +01:00
Patrick Cloke
d7c2df2fa3
Improve per-block CPU and DB usage metrics () 2020-05-06 16:43:39 -04:00
Patrick Cloke
fe69fb6263
Add backwards compatibility codepath to LoggingContext. () 2020-05-05 09:21:34 -04:00
Erik Johnston
37f6823f5b
Add instance name to RDATA/POSITION commands ()
This is primarily for allowing us to send those commands from workers, but for now simply allows us to ignore echoed RDATA/POSITION commands that we sent (we get echoes of sent commands when using redis). Currently we log a WARNING on the master process every time we receive an echoed RDATA.
2020-04-29 16:23:08 +01:00
Richard van der Hoff
0f05fd1530
Reduce the number of calls to resource.getrusage ()
Let's just call `getrusage` once on each logcontext change, rather than twice.
2020-04-03 13:21:30 +01:00
Richard van der Hoff
60adcbed91
Fix "'NoneType' has no attribute start|stop" logcontext errors ()
Fixes .
2020-03-31 15:18:41 +01:00
Richard van der Hoff
39230d2171
Clean up some LoggingContext stuff ()
* Pull Sentinel out of LoggingContext

... and drop a few unnecessary references to it

* Factor out LoggingContext.current_context

move `current_context` and `set_context` out to top-level functions.

Mostly this means that I can more easily trace what's actually referring to
LoggingContext, but I think it's generally neater.

* move copy-to-parent into `stop`

this really just makes `start` and `stop` more symetric. It also means that it
behaves correctly if you manually `set_log_context` rather than using the
context manager.

* Replace `LoggingContext.alive` with `finished`

Turn `alive` into `finished` and make it a bit better defined.
2020-03-24 14:45:33 +00:00
Brendan Abolivier
dc6fb56c5f
Hopefully mypy is happy now 2020-03-10 14:40:28 +00:00
Brendan Abolivier
fe593ef990
Attempt at appeasing the gods of mypy 2020-03-10 14:19:06 +00:00
Neil Pilgrim
2bff4457d9
Add type hints to logging/context.py ()
* Add type hints to logging/context.py

Signed-off-by: neiljp (Neil Pilgrim) <github@kepier.clara.net>
2020-03-07 17:57:26 +00:00
Patrick Cloke
509e381afa
Clarify list/set/dict/tuple comprehensions and enforce via flake8 ()
Ensure good comprehension hygiene using flake8-comprehensions.
2020-02-21 07:15:07 -05:00
Richard van der Hoff
da4e52544e comment for run_in_background 2020-01-12 21:53:47 +00:00
Erik Johnston
495005360c Bump version of mypy 2019-12-12 15:21:12 +00:00
Erik Johnston
ffeafade48 Update comment 2019-12-10 13:17:39 +00:00
Erik Johnston
9a2223d4c8 Fix make_deferred_yieldable to work with coroutines 2019-12-10 11:22:12 +00:00
Amber Brown
fdec84aa42
Add benchmarks for structured logging performance () 2019-12-03 20:21:25 +11:00
Amber Brown
9eebd46048
Improve the performance of structured logging () 2019-11-26 03:45:50 +11:00
Andrew Morgan
73d091be48 A couple more instances 2019-11-12 13:12:25 +00:00
Amber Brown
020add5099
Update black to 19.10b0 ()
* update version of black and also fix the mypy config being overridden
2019-11-01 02:43:24 +11:00
Andrew Morgan
54fef094b3
Remove usage of deprecated logger.warn method from codebase ()
Replace every instance of `logger.warn` with `logger.warning` as the former is deprecated.
2019-10-31 10:23:24 +00:00
Erik Johnston
f3ceaf4323 Trace non-JSON APIs, /media, /key etc 2019-10-11 11:58:52 +01:00
Amber Brown
864f144543
Fix up some typechecking ()
* type checking fixes

* changelog
2019-10-02 05:29:01 -07:00
J. Ryan Stinnett
a86a290850 Fix logcontext spam on non-Linux platforms ()
This checks whether the current platform supports thread resource usage tracking
before logging a warning to avoid log spam.

Fixes https://github.com/matrix-org/synapse/issues/6055
2019-09-18 21:55:37 +01:00
Amber Brown
b617864cd9
Fix for structured logging tests stomping on logs () 2019-09-13 02:29:55 +10:00
Erik Johnston
d8517da85b Don't assume there is a 'self' arg in @trace decorator 2019-09-06 10:07:12 +01:00
Jorik Schellekens
bc604e7f94
Gracefully handle log context slips and missing opentracing import errors. () 2019-09-05 17:33:29 +01:00
Jorik Schellekens
909827b422
Add opentracing to all client servlets () 2019-09-05 14:46:04 +01:00
Jorik Schellekens
b9cfd3c375
Fix opentracing contexts missing from outbound replication requests () 2019-09-05 14:22:15 +01:00