M5-S2 — Logs, traces, errors and retention
Section titled “M5-S2 — Logs, traces, errors and retention”| Module | M5 — Observe |
| After this session you can | Reconstruct what happened to one request from its trace id, set up error reporting with its blind spots in mind, and plan for the logs and audit records the platform keeps. |
| Time | Facilitated: 31 min · On your own: 31 min |
| Before you start | M5-S1. From M3-S2: the gateway’s error envelope and its traceId. From ACSA: monitoring and the audit trail. |
| Go deeper | Observability: structured logging & correlation · Logs, audit & retention |
◆ Orientation (1 min) — One id, every service
Section titled “◆ Orientation (1 min) — One id, every service”A user reports that an approval email never arrived, and sends you the trace id from the error message. The request touched the gateway, the data pod, the bus, the workflow application and the notification worker: five places, five logs. This session shows how one id ties them together, what Sentry adds, and what the platform keeps for later questions.
▤ Concept (6 min) — Logs, the correlation id, Sentry and what is kept
Section titled “▤ Concept (6 min) — Logs, the correlation id, Sentry and what is kept”Structured logs
Section titled “Structured logs”Every service logs JSON, one object per line, because the chart runs them in production mode. Each
line carries service, env, timestamp, level and msg, and, inside a request or a message
handler, the correlationId, the userId and the spaceId. The level for the whole release is
global.log.level (error, warn, info or debug); changing it rolls every pod that reads the
shared configuration, so raise it to debug only for a short investigation. The logger removes
fields named like secrets (password, token, authorization, secret, key and similar) before
writing.
The correlation id: the only trace you get
Section titled “The correlation id: the only trace you get”There is no distributed-tracing system with spans and waterfalls. Instead, one id travels everywhere:
flowchart LR C["Caller<br/>(may send x-correlation-id)"] --> G["Gateway:<br/>keeps it or creates one"] G --> D["data:<br/>logs it"] D -->|"message carries it"| B["Bus"] B --> W["workflow:<br/>logs it"] B --> N["notification worker:<br/>logs it"]
What to notice: the id crosses the bus inside each message, so asynchronous work done minutes later in another service still carries the same id as the original request.
The gateway stamps x-correlation-id on every request, keeping one the caller sent. It is the
traceId in every gateway error (M3-S2). Work with no id, such as a request that bypassed the gateway,
logs NO-TRACE-ID and cannot be followed: ask integrators to send their own id so that you can find
their requests.
In production you search all logs at once in your log platform (Loki, Elasticsearch or similar). In
the lab, kubectl logs with the release’s label does the same job.
Error reporting with Sentry
Section titled “Error reporting with Sentry”When you give the release a Sentry project, unhandled errors are reported there with their correlation id:
| Value | Purpose |
|---|---|
sentry.backendDSN, sentry.webDSN | Where the services and the web portal report; unset means no reporting |
sentry.environment | The environment name Sentry groups by, for example northwind-prod |
sentry.traceSampleRate | Share of transactions traced; the chart’s default is "0.1" (10 %) |
Choose the sample rate deliberately: 10 % of every transaction is a lot of Sentry volume for a busy tenant. And know the blind spots: the audit application and the scheduler log some failures without raising them, on purpose, so those failures never reach Sentry. Watch their logs, the scheduler’s failed-job metric and the dead-letter queues instead.
What the platform keeps
Section titled “What the platform keeps”| Record | Who reads it | How long it is kept |
|---|---|---|
| The audit trail (who changed what) | The administrator, in Monitoring | A single-tenant release never purges it |
| Email, text-message and WhatsApp logs | The administrator, in Monitoring | A single-tenant release never purges them |
| Automation run history | The administrator | A single-tenant release never purges it |
| System logs and entry history | The administrator | Never purged |
| Sign-in and second-factor audit records | The identity server | Removed automatically after 180 and 90 days |
| Pod logs | You | As long as your log platform keeps them; a pod’s own log is lost when it is replaced |
Multi-tenant deployments purge the first three daily, per tenant, from each tenant’s plan limits. A single-tenant release grows these collections for ever: plan the MongoDB storage for it, and if Northwind’s policy requires a limit, agree it with the administrator and apply it at the database level. The audit trail is also evidence: never delete it without that agreement.
⛏ Lab (18 min) — Follow one change through the platform
Section titled “⛏ Lab (18 min) — Follow one change through the platform”Goal. One change you make in the portal, followed by its correlation id through the gateway, the data pod and at least one service that received it over the bus.
Before you start. The release healthy, you signed in as nwoperator in a browser with its
developer tools available (F12).
-
In the portal, open Administration › Organization › Users and open Drill Marker. Open the browser’s developer tools on the Network tab.
-
Change Drill Marker’s last name to Marker-Traced and save.
-
In the Network tab, select the request that saved the change (a
PATCHorPUTto the API), and copy thex-correlation-idheader from its response headers. -
Search every pod of the release for it:
Terminal window ID=<paste the id>kubectl -n northwind logs -l app.kubernetes.io/instance=nw --all-containers --prefix \--since=10m --max-log-requests=20 | grep "$ID" -
Sort what you found: which pods logged the id, and which of those lines came from handling a bus message rather than the HTTP request? (The prefix names the pod; the message text says which.)
-
Pick one JSON line and read its fields:
service,level,correlationId,userId,spaceId. -
Note in
inventory.mdthe release’s current Sentry settings:helm get values nw -n northwind -a | grep -A5 "^sentry:". -
Write two lines for Northwind’s operations handbook: what you need from a user to investigate a failure, and how long sign-in audit records are kept.
Check.
- You have the correlation id of your own change.
- It appears in the gateway’s log and in the
core-datapod’s log. - It also appears in at least one other pod, from a message handled over the bus.
- You can name the
serviceandspaceIdof one of the lines. - Your handbook lines ask for the trace id and give 180 days for sign-in audit records.
Pass condition. All five checks hold.
If something goes wrong
| What you see | What to do |
|---|---|
No x-correlation-id response header | Look for it on the request headers instead, or in an error response’s traceId. If neither, use curl with your own header, for example -H "x-correlation-id: nw-lab-trace-001". |
grep finds nothing | Widen --since, and check the label: kubectl -n northwind get pods --show-labels shows app.kubernetes.io/instance=nw. |
kubectl logs complains about too many log requests | Raise --max-log-requests, or search one Deployment at a time. |
| The lines are not JSON | The service is not running in production mode; report it, as the chart sets it for every service. |
Model answer
A typical result for saving a user:
| Pod | What it logged | How the id got there |
|---|---|---|
nw-osos-apigateway | The request, with the id it stamped | It created or kept it |
nw-osos-core-data | The update of the user entry | The HTTP request from the gateway |
nw-osos-core-rest | Audit and timeline entries for the change | A bus message published by data |
nw-osos-identity | The identity record re-read for the changed user | A bus message about the user entry |
The exact set of services depends on what the change triggers; what matters is that the id reaches services the request never called directly. Handbook lines: “Ask for the time, the address and the trace id from the error. Sign-in records are kept 180 days, second-factor records 90 days; everything else in Monitoring is kept until we agree a limit.”
✓ Practice (5 min) — Check your understanding
Section titled “✓ Practice (5 min) — Check your understanding”An integration partner’s failed calls appear in your logs only as NO-TRACE-ID, and you cannot find
them. What do you ask the partner to do?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
Sentry shows no errors, yet scheduled reports have not been generated for two days. Why might Sentry be silent?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
Northwind’s single-tenant release has run for three years, and the MongoDB volume keeps growing. The email log and the audit trail are the largest collections. What is the right next step?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
You raised global.log.level to debug to investigate, and every pod of the release restarted.
Why?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
↺ Recap (1 min) — After Module 5 you can
Section titled “↺ Recap (1 min) — After Module 5 you can”After this module you can read the health of every workload, scrape its metrics and alert on what matters, follow one request through every service by its correlation id, report errors to Sentry with its blind spots in mind, and plan for the records the platform keeps.
Next. Module 6 grows the release: scaling the right tier with the chart’s autoscaling, and keeping MongoDB, Redis and RabbitMQ highly available.