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/adrs/006-logging-strategy.md
+46-16Lines changed: 46 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,34 +21,42 @@ Key drivers for this decision include:
21
21
22
22
We will implement and enforce comprehensive logging guidelines that prioritize **debugging capability** and **user visibility**.
23
23
This approach mandates descriptive, human-readable logs with structured request tracking through Mapped Diagnostic Context (MDC).
24
+
The SDK uses SLF4J API for all logging statements.
24
25
25
26
## Guidelines
26
27
27
28
### 1. Log Content and Security
28
29
29
-
-**Do not log sensitive information.**
30
+
***Do not log sensitive information.**
30
31
Never log full request or response bodies.
31
32
Ensure that personally identifiable or confidential data — such as names, IDs, tokens, or payload content — is always excluded from logs.
32
33
33
-
-**Write concise and relevant logs.**
34
+
***Write concise and relevant logs.**
34
35
Every log must convey meaningful information.
35
36
Avoid verbose, repetitive, or purely cosmetic details.
36
37
37
-
-**Use descriptive, human-readable formats.**
38
-
Logs must be clear enough for a developer to understand what happened without checking the code.
39
-
Use the `metric=value` pattern to include structured details with extensibility in mind.
38
+
***Use descriptive, human-readable and standard formats.**
39
+
- Logs must be clear enough for a developer to understand what happened without checking the code.
40
+
- Start log messages with a capital letter (exceptions include case-sensitive identifiers) and end with a period (`.`).
41
+
- Avoid newlines (`\n`) and emojis within log messages to prevent parsing and encoding concerns.
42
+
- Use the `metric=value` pattern to include structured details with extensibility in mind.
40
43
41
-
```[reqId=e3eaa45c] OpenAI request completed successfully with duration=1628ms, responseSize=1.2KB.```
44
+
```
45
+
[callId=e3eaa45c] OpenAI request completed successfully with duration=1628ms, responseSize=1.2KB.
46
+
```
42
47
43
48
* **Correlate logs.**
44
-
Include a request identifier (e.g., `reqId`) in per-request logs to assist with correlation and debugging.
45
-
In this SDK, a "request" represents a single AI service operation (e.g., one chat completion call, one embedding generation).
46
-
The `reqId` is generated for each AI service call and is distinct from any HTTP request tracking in user's application framework.
49
+
Include a call identifier (e.g., `callId`) in outgoing per-request logs to assist with correlation and debugging.
50
+
Throughout this document, the term 'request' refers to a single SDK operation that calls an AI service (e.g., `OrchestrationClient.chatCompletion()`, `OpenAiClient.embed()`), distinct from HTTP requests to the user's application.
47
51
48
52
* **Exception logging.**
49
53
When logging exceptions, use standard logging methods (e.g., `log.error("Operation failed", exception)`) rather than serializing exception objects.
50
54
Exception objects may contain custom fields with sensitive data that could be exposed through JSON serialization or custom `toString()` implementations.
51
55
56
+
* **Logging framework**
57
+
Write all logging statements against the SLF4J API.
58
+
The AI SDK relies on `logback-classic` as the provided runtime implementation.
59
+
52
60
---
53
61
54
62
### 2. Log Levels and Scope
@@ -69,10 +77,12 @@ This approach mandates descriptive, human-readable logs with structured request
69
77
Do not rely solely on response-time logging — requests may fail, hang, or take long durations.
70
78
This approach also avoids the need for stack-trace investigation when surface error responses are ambiguous.
71
79
72
-
```[reqId=e3eaa45c] Starting OpenAI synchronous request to /v1/chat/completions, destination=<some-uri>.```
80
+
```
81
+
[callId=e3eaa45c] Starting OpenAI synchronous request to /v1/chat/completions, destination=<some-uri>.
82
+
```
73
83
74
84
* **Performance-aware logging.**
75
-
If a log statement requires any object creation, guard it with a log-level check to prevent performance degradation.
85
+
If a log statement requires computation (such as object creation or method invocation), guard it with a log-level check to prevent performance degradation.
76
86
77
87
``` java
78
88
Optional<Destination> maybeDestination;
@@ -84,7 +94,7 @@ This approach mandates descriptive, human-readable logs with structured request
0 commit comments