| 1 |
Observability |
| 2 |
============= |
| 3 |
|
| 4 |
Librsvg supports basic, mostly ad-hoc logging with an ``RSVG_LOG=1`` |
| 5 |
environment variable. This has not been very effective in letting me, |
| 6 |
the maintainer, know what went wrong when someone reports a bug about |
| 7 |
librsvg doing the wrong thing in an application. Part of it is because |
| 8 |
the code could be more thorough about logging (e.g. log at all error |
| 9 |
points), but also part of it is that there is no logging about what API |
| 10 |
calls are made into the library. On each bug reported on behalf of a |
| 11 |
particular application, my thought process goes something like this: |
| 12 |
|
| 13 |
- What was the app doing? |
| 14 |
|
| 15 |
- Can I obtain the problematic SVG? |
| 16 |
|
| 17 |
- Does the bug reporter even know what the problematic SVG was? |
| 18 |
|
| 19 |
- Was the app rendering with direct calls to the librsvg API? |
| 20 |
|
| 21 |
- Or was it using the gdk-pixbuf loader, and thus has very little |
| 22 |
control of how librsvg is used? |
| 23 |
|
| 24 |
- If non-pixbuf, what was the Cairo state when librsvg was called? |
| 25 |
|
| 26 |
- What sort of interesting API calls are being used? Stylesheet |
| 27 |
injection? Re-rendering single elements with different styles? |
| 28 |
|
| 29 |
And every time, I must ask the bug reporter for information related to |
| 30 |
that, or to point me to the relevant source code where they were using |
| 31 |
librsvg… which is not terribly useful, since building their code and |
| 32 |
reproducing the bug with it is A Yak That Should Not Have To Be Shaved. |
| 33 |
|
| 34 |
Desiderata |
| 35 |
---------- |
| 36 |
|
| 37 |
Know exactly what an application did with librsvg: |
| 38 |
|
| 39 |
- All API calls and their parameters. |
| 40 |
|
| 41 |
- State of the Cairo context at entry. |
| 42 |
|
| 43 |
- “What SVG?” - be careful and explicit about exfiltrating SVG data to |
| 44 |
the logs. |
| 45 |
|
| 46 |
- Basic platform stuff? Is the platform triple enough? Distro ID? |
| 47 |
|
| 48 |
- Versions of dependencies. |
| 49 |
|
| 50 |
- Version of librsvg itself. |
| 51 |
|
| 52 |
Internals of the library: |
| 53 |
|
| 54 |
- Regular debug tracing. We may have options to enable/disable tracing |
| 55 |
domains: parsing, cascading, referencing elements, temporary surfaces |
| 56 |
during filtering, render tree, etc. |
| 57 |
|
| 58 |
- Log all points where an error is detected/generated, even if it will |
| 59 |
be discarded later (e.g. invalid CSS values are silently ignored, per |
| 60 |
the spec). |
| 61 |
|
| 62 |
Enabling logging |
| 63 |
---------------- |
| 64 |
|
| 65 |
It may be useful to be able to enable logging in various ways: |
| 66 |
|
| 67 |
- Programmatically, for when one has control of the source code of the |
| 68 |
problematic application. Enable logging at the problem spot, for the |
| 69 |
SVG you know that exhibits the problem, and be done with it. This can |
| 70 |
probably be at the individual ``RsvgHandle`` level, not globally. For |
| 71 |
global logging within a single process, see the next point. |
| 72 |
|
| 73 |
- For a single process which one can easily launch via the command |
| 74 |
line; e.g. with an environment variable. This works well for |
| 75 |
non-sandboxed applications. Something like |
| 76 |
``RSVG_LOG_CONFIG=my_log_config.toml``. |
| 77 |
|
| 78 |
- With a configuration file, a la ``~/.config/librsvg.toml``. Many |
| 79 |
programs use librsvg and you don’t want logs for all of them; allow |
| 80 |
the configuration file to specify a process name, or maybe other ways |
| 81 |
of determining when to log. For session programs like gnome-shell, |
| 82 |
you can’t easily set an environment variable to enable logging - |
| 83 |
hence, a configuration file that only turns on logging from the |
| 84 |
gnome-shell process. |
| 85 |
|
| 86 |
All of the above should be well documented, and then we can deprecate |
| 87 |
``RSVG_LOG``. |
| 88 |
|
| 89 |
Which SVG caused a crash? |
| 90 |
------------------------- |
| 91 |
|
| 92 |
Every once in a while, a bug report comes in like “$application crashed |
| 93 |
in librsvg”. The application renders many SVGs, often indirectly via |
| 94 |
gdk-pixbuf, and it is hard to know exactly which SVG caused the problem. |
| 95 |
Think of gnome-shell or gnome-software. |
| 96 |
|
| 97 |
For applications that call librsvg directly, if they pass the filename |
| 98 |
or a GFile then it is not hard to find out the source SVG. |
| 99 |
|
| 100 |
But for those that feed bytes into librsvg, including those that use it |
| 101 |
indirectly via gdk-pixbuf, librsvg has no knowledge of the filename. We |
| 102 |
need to use the base_uri then, or see if the pixbuf loader can be |
| 103 |
modified to propagate this information (is it even available from the |
| 104 |
GdkPixbufLoader machinery?). |
| 105 |
|
| 106 |
If all else fails, we can have an exfiltration mechanism. How can we |
| 107 |
avoid logging *all* the SVG data that gnome-shell renders, for example? |
| 108 |
Configure the logger to skip the first N SVGs, and hope that the order |
| 109 |
is deterministic? We can’t really “log only if there is a crash during |
| 110 |
rendering”. |
| 111 |
|
| 112 |
Log only the checksums of SVGs or data lengths, and use that to find |
| 113 |
which SVG caused the crash? I.e. have the user use a two-step process to |
| 114 |
find a crash: get a log (written synchronously) of all SVG |
| 115 |
checksums/lengths, and then reconfigure the logger to only exfiltrate |
| 116 |
the last one that got logged - presumably that one caused the crash. |
| 117 |
|
| 118 |
Which dynamically-created SVG caused a problem? |
| 119 |
----------------------------------------------- |
| 120 |
|
| 121 |
Consider a bug like :issue:`GNOME/gnome-shell#5415` where an |
| 122 |
application dynamically generates an SVG and feeds it to librsvg. That |
| 123 |
bug was not a crash; it was about incorrect values returned from an |
| 124 |
librsvg API function. For those cases it may be useful to be able to |
| 125 |
exfiltrate an SVG and its stylesheets only if it matches a user-provided |
| 126 |
substring. |
| 127 |
|
| 128 |
Global configuration |
| 129 |
-------------------- |
| 130 |
|
| 131 |
``$(XDG_CONFIG_HOME)/librsvg.toml`` - for startup-like processes like |
| 132 |
gnome-shell, for which it is hard to set an environment variable: |
| 133 |
|
| 134 |
Per-process configuration |
| 135 |
------------------------- |
| 136 |
|
| 137 |
``RSVG_LOG_CONFIG=my_log_config.toml my_process`` |
| 138 |
|
| 139 |
Programmatic API |
| 140 |
---------------- |
| 141 |
|
| 142 |
FIXME |
| 143 |
|
| 144 |
Configuration format |
| 145 |
-------------------- |
| 146 |
|
| 147 |
.. code:: toml |
| 148 |
|
| 149 |
[logging] |
| 150 |
enabled = true |
| 151 |
process = "gnome-shell" # mandatory for global config - don't want to log all processes - warn to g_log if key is not set |
| 152 |
output = "/home/username/rsvg.log" # if missing, log to g_log only - or use a output_to_g_log=true instead? |
| 153 |
|
| 154 |
API logging |
| 155 |
----------- |
| 156 |
|
| 157 |
Log cr state at entry, surface type, starting transform. |
| 158 |
|
| 159 |
Log name/base_uri of rendered document. |
| 160 |
|
| 161 |
Can we know if it is a gresource? Or a byte buffer? Did it come from |
| 162 |
gdk-pixbuf? |
| 163 |
|
| 164 |
Implementation |
| 165 |
-------------- |
| 166 |
|
| 167 |
There is currently the start of a :internals:struct:`rsvg::session::Session` |
| 168 |
type woven throughout the source code, with the idea of it being the |
| 169 |
thing that records logging events, it may be better to plug into the |
| 170 |
``tracing`` ecosystem: |
| 171 |
|
| 172 |
https://crates.io/crates/tracing |
| 173 |
|
| 174 |
Initial ideas: |
| 175 |
|
| 176 |
* See the "In libraries" section in ``tracing``'s README; it shows how |
| 177 |
to create spans for API calls. |
| 178 |
|
| 179 |
* How would we capture from gnome-shell? `tracing-journald |
| 180 |
<https://tracing-rs.netlify.app/tracing_journald/index.html>`_? |
| 181 |
Or would things be easier for casual users if we logged to a file? |
| 182 |
|
| 183 |
* Maybe later, have a ``tracing-sysprof`` crate to send the events to |
| 184 |
`sysprof <https://gitlab.gnome.org/GNOME/sysprof/-/tree/master/src>`_? |
| 185 |
|
| 186 |
Log contents |
| 187 |
------------ |
| 188 |
|
| 189 |
/home/username/rsvg.log - json doesn’t have comments; put one of these |
| 190 |
in a string somehow: |
| 191 |
|
| 192 |
:: |
| 193 |
|
| 194 |
****************************************************************************** |
| 195 |
* This log file exists because you enabled logging in ~/.config/librsvg.toml * |
| 196 |
* for the "gnome-shell" process. * |
| 197 |
* * |
| 198 |
* If you want to disable this kind of log, please turn it off in that file * |
| 199 |
* or delete that file entirely. * |
| 200 |
****************************************************************************** |
| 201 |
|
| 202 |
****************************************************************************** |
| 203 |
* This log file exists because you enabled logging with * |
| 204 |
* RSVG_LOG_CONFIG=config.toml for the "single-process-name" process. * |
| 205 |
* * |
| 206 |
* If you want to disable this kind of log, FIXME */ |
| 207 |
****************************************************************************** |
| 208 |
|
| 209 |
To-do list |
| 210 |
---------- |
| 211 |
|
| 212 |
- Audit code for GIO errors; log there. |
| 213 |
|
| 214 |
- Audit code for Cairo calls that yield errors; log there. |
| 215 |
|
| 216 |
- Log the entire ancestry of the element that caused the error? Is |
| 217 |
that an insta-reproducer? |