Logging is the record of what your system did and when.
It is the first thing you reach for when something goes wrong.
For a language model system, log the prompt, the response, the token counts, latency and cost.
Log the model version and any prompt version too.
Without those you cannot tell whether a change caused a complaint.
Structured logs as JSON are queryable, and plain text is not.
Searching a text log for all slow requests from one customer is painful.
A trace identifier lets you follow a single request across services.
In an agent, log every step: the tool chosen, the arguments, the result.
Agents fail in the middle, and without a trace debugging is guesswork.
Never log secrets, keys or personal data without redaction.
Prompts frequently contain personal data by their nature, which makes this a real obligation.
Redact at the point of logging, not later, since logs get copied.
Set retention deliberately, because keeping everything forever is a liability.
Sample high-volume logs rather than dropping the field you will want.