Skip to content

Commit c42bf29

Browse files
committed
chore: Add a dev-adr about logs and errors guidelines
1 parent 426107f commit c42bf29

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

DEV-ADR.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,49 @@ To complete
2323
To complete
2424
-->
2525

26+
### 5. Guidelines for writing useful log messages, error context, or error structure
27+
28+
**Date:** 2025-07-25
29+
**Status:** Accepted
30+
31+
### Context
32+
33+
Some errors and logs currently lack enough context to understand the cause of an issue.
34+
35+
This is especially true for failures that occur during requests to or from external sources.
36+
37+
At the same time, adding too much context can make logs noisy and hard to read, and can flood log storage with low-value
38+
or sensitive data.
39+
40+
### Decision
41+
42+
When writing log messages, adding error context, or designing error structures, follow these guidelines:
43+
44+
- **Prefer structured logging for internal context.**
45+
- Add identifiers as structured fields rather than embedding them in the message text (e.g., party id, signed entity
46+
type, beacon, request id, entity id).
47+
- Keep the human-readable message short, put “what happened” in the message and “what it relates to” in structured fields.
48+
49+
- **Avoid unnecessary or sensitive context in logs by default.**
50+
- Do not log secrets or high-risk material (e.g., cryptographic keys, seeds, tokens, credentials).
51+
- Do not log large payloads unless they are required for troubleshooting (see “External sources” below).
52+
53+
- **Handle large debug output explicitly.**
54+
- If a type’s `Debug` output is too large or contains sensitive fields, implement `Debug` manually to provide a safe,
55+
non-exhaustive representation by default.
56+
- Optionally support an “alternate” representation (e.g., `{:#?}`) that includes additional detail when it is safe and useful.
57+
58+
- **External sources: allow exceptions when needed to troubleshoot.**
59+
- For interactions with external sources, it can be acceptable to include additional context such as request/response
60+
payloads **only when necessary** to diagnose issues.
61+
- When logging external payloads, prefer safeguards such as truncation/size limits and logging only at error/debug
62+
level (and redaction when applicable).
63+
64+
### Consequences
65+
66+
- Logs are more readable and actionable.
67+
- Errors are easier to understand and troubleshoot without routinely leaking sensitive data or producing excessive log volume.
68+
2669
### 4. Guidelines for crate test utilities
2770

2871
**Date:** 2025-07-25

0 commit comments

Comments
 (0)