You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/adr/0008-use-tracing.md
+19-14Lines changed: 19 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,10 @@
14
14
15
15
Currently all Rust code in [app-services](https://github.com/mozilla/application-services/)
16
16
uses the `log` crate for debugging and diagnostics.
17
-
Log output is often captured during tests where it's just printed to stdout/stderr if the test
18
-
fails. Further, both our mobile apps and Firefox Desktop have techniques for having this log
19
-
output be sent across the FFI so it can be captured in whatever "native" logging system is
20
-
in place (eg, logcat on Android, custom file logging on iOS, Log.sys.mjs/Console.sys.mjs logging on Desktop)
17
+
Log output is valuable for working on the code, and for helping users troubleshoot.
18
+
When working on the code, log output is often captured during tests, where it's just printed to stdout/stderr if the test fails.
19
+
For helping users troubleshoot, log output is sent across the FFI so it can be captured in whatever "native" logging system is in place.
20
+
Users or QA can then export and attach the logs to a bug.
21
21
22
22
application-services also has an [error support crate](https://github.com/mozilla/application-services/tree/main/components/support/error),
23
23
designed explicitly for error reporting for the applications.
@@ -31,14 +31,16 @@ and any changes proposed to this crate by this document are limited to just this
31
31
32
32
The main problem with the `log` module is a design choice made by that crate,
33
33
which is the concept of a [global "max level"](https://docs.rs/cli-log/latest/cli_log/fn.set_max_level.html)
34
+
that's set for all crates.
34
35
35
-
In Gecko, simply setting this max level to, say, `Trace` can cause performance regressions in other
36
-
crates - eg, [see this desktop bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1874215) for one example.
36
+
The Gecko code has embraced this design choice and sets the global max level to Info for production builds.
37
+
Changing this max level to, say, Trace can cause performance regressions in other crates - eg, see this desktop bug for one example.
38
+
Changing all the existing code is a difficult, and probably unwelcome, task, and is only possible for crates we control.
37
39
38
40
In practice, this means that we are unable to selectively get `Debug` or `Trace` logs for individual components,
39
41
because the max level for the logger is, effectively, fixed at `Info`.
40
42
41
-
### Problems with the error reporter
43
+
####Problems with the error reporter
42
44
43
45
The error reporter actually works OK for mobile, but is not implemented at all for Desktop.
44
46
However, the existing implementation is quite ad-hoc and not very "rich" in terms of data which
@@ -81,6 +83,11 @@ This document proposes that:
81
83
82
84
* This same mechanism, and the same raw data, should be used on all platforms (ie, Android, iOS and Desktop).
83
85
86
+
To be explicit, there would be no requirement for any other crates to move to tracing. However, we also
87
+
believe there is nothing in this document which would prevent any crates from using tracing.
88
+
Further, there's no reason that the use of `log` and `tracing` is mutually exclusive; crates are, and will remain, free
89
+
to use either of these crates as they see fit.
90
+
84
91
## Implementation: Move to tracing for all app-services crates.
85
92
86
93
This section describes the changes necessary to implement the above.
@@ -122,6 +129,7 @@ simply subscribe to the highest log level and perform additional filtering after
122
129
This means that the "performance critical path" for this process is determining if we have a subscriber;
123
130
once we have determined a subscriber matches an event, we can perform relatively expensive operations
124
131
on the event because we assume action will be taken on the event.
132
+
We believe this assumption is fine because we will own all such subscribers.
125
133
126
134
An example of these "relatively expensive" operations is fetching event "fields", such as the message or other meta-data.
127
135
@@ -134,7 +142,9 @@ There are 3 main places which would change in the first instance, broken down by
134
142
135
143
#### Mobile
136
144
137
-
The existing [rust_log_forwarder](https://github.com/mozilla/application-services/tree/main/components/support/rust-log-forwarder) and [error-support](https://github.com/mozilla/application-services/tree/main/components/support/error) crates would change how they collect "events" to using `tracing-subscriber`. Initially we'd not change the API exposed to the mobile apps, but very soon after declaring success on Desktop we'd look to consolidate the APIs as seen by the applications.
145
+
As described in the Application Services section, the existing crates used by mobile would keep the same public API
146
+
in the first instance, meaning our mobile apps would not require changes; however, eventually we'd look at moving
147
+
the mobile apps to the new mechanism, at which time we'd kill the 2 "legacy" app-services crates.
138
148
139
149
#### Desktop
140
150
@@ -149,7 +159,7 @@ The [app-services-logger](https://searchfox.org/mozilla-central/source/services/
149
159
150
160
#### Application Services
151
161
152
-
* All crates move to `tracing` instead of `logging`
162
+
* All crates move to `tracing` instead of `log`
153
163
154
164
* A new crate would be added which defines the application callback interfaces (via UniFFI) and
155
165
also the new tracing-subscriber implementation.
@@ -158,8 +168,3 @@ The [app-services-logger](https://searchfox.org/mozilla-central/source/services/
158
168
but would have their internal implementation replaced with the subscriber. This is for backwards
159
169
compatibility with mobile - eventually we'd expose the new callback interfaces to mobile and delete
160
170
these crates entirely.
161
-
162
-
#### Mobile
163
-
164
-
Mobile would not require changes in the first version, although we'd move to the new mechanism within
165
-
a month or 2, at which time we can kill the 2 "legacy" app-services crates.
0 commit comments