Log aggregation
Goal
Let someone answer "what happened to request X" across services in one search.
A good setup logs one JSON object per event, carries an id through every hop, never writes secrets, and has a retention policy.
When to use
- Logs are scattered across hosts or only on stdout.
- Log lines are free text that cannot be filtered.
- A log bill or disk is growing without control.
- For alerts built on logs, use
use_skillwithmonitoring-alerts.
Steps
- Find current logging with
rgforconsole.log,logger,logging.andprint(, and note libraries in use withread_fileon the dependency file. - Choose one logger per language and one JSON schema: timestamp in UTC, level, message, service, version, environment, request id, and error fields.
- Edit the logger setup with
edit_file. Write to stdout and let the platform ship it; avoid log files inside containers. - Add middleware that reads or creates a request id, puts it in the log context, returns it in a response header and forwards it on outbound calls.
- Define levels: error means a person may need to act, warn means unexpected but handled, info is business events, debug is off in production.
- Add redaction for passwords, tokens, authorization headers, card numbers and personal data. Search the code with
rgfor places logging whole request bodies or objects. - Pick a shipping path suited to the platform (agent, sidecar, platform drain). Check current docs with
read_urlfor the chosen tool's config. - Set retention by value: short for debug volume, longer for audit. Set sampling or drop rules for health check spam.
- Estimate volume with
run_commandon a sample of real logs (lines per minute, bytes per line) before enabling a metered service. - Write the collector config with
create_fileand test locally by sending sample events. - Verify end to end: make one request, find its id in the store, and follow it across two services.
- Add a short note on how to search, with three saved queries.
Gotchas
- Logging full request or response objects leaks tokens and personal data into a store with wider access than the app.
- Local time stamps without a zone make cross-service ordering wrong. Use UTC with milliseconds.
- Multiline stack traces split into separate events unless the stack is one field in a JSON line.
- Debug logging left on in production is usually the biggest cost line.
- Request ids lost at queue or async boundaries break correlation exactly where it is needed.
- Cardinality matters: putting a user id into a metric label from a log pipeline can blow up the metrics bill.
Output
- The logging config and middleware changes, listed by file.
- The log schema in one short table.
- Volume and retention assumptions, and the end to end test result.
