Commit c7105d8
authored
Add support for JSON log format (cowprotocol#3336)
# Description
Structured logs offer several advantages for our services:
- Improved troubleshooting and root cause analysis, as the flow of a
request can be more easily traced.
- Simpler log correlation.
- Easier integration and automation.
This PR introduces a new parameter, `use_json_format`, for log output
(currently set to `false` by default). When enabled, the `tracing` crate
will emit logs in JSON format instead of the standard plain text.
Below is an example of a log entry from the `autopilot` service using
the new structured format:
```json
{"timestamp":"2025-03-25T12:12:42.492Z","level":"DEBUG","fields":{"message":"stored order events","label":"Executing","count":1,"elapsed":"7.604417ms"},"target":"autopilot::database::order_events","span":{"auction_id":1057,"name":"auction"},"spans":[{"auction_id":1057,"name":"auction"}]}
```
Related to cowprotocol#3282
# Changes
- Added the `json` feature to the `tracing-subscriber` crate, and
updated the version to the latest.
- Introduced a new `log_use_json_format` parameter to specify whether to
use structured logging. It is disabled by default.
- Used across all crates that perform logging: `orderbook`, `autopilot`,
`driver`, `solver`, `alerter`, and `refunder`.
- Since logging is encapsulated within the `observer` crate, the
creation of the new JSON logging layer only needed to be implemented
there.
- The new parameter is currently set to `false` in all unit and E2E
tests.
## How to test
Testing was done by running e2e tests in both scenarios (new parameter
enabled and disabled) and inspecting the resulting logs for the
services.1 parent 3c2c00b commit c7105d8
21 files changed
Lines changed: 99 additions & 49 deletions
File tree
- crates
- alerter/src
- autopilot/src
- driver/src
- infra
- observe
- tests/setup
- e2e/src/setup
- ethrpc/src/block_stream
- observe/src
- orderbook/src
- refunder/src
- solvers/src
- infra
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
381 | 385 | | |
382 | 386 | | |
383 | 387 | | |
384 | 388 | | |
385 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
386 | 394 | | |
387 | 395 | | |
388 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
| 35 | + | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
| 891 | + | |
891 | 892 | | |
892 | 893 | | |
893 | 894 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | | - | |
| 390 | + | |
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| |||
0 commit comments