Logging, Tracing, And Correlation
Logs and traces make integrations operable. Klok standardizes logging around stable context fields and correlation identifiers so a flow can be followed across services.
Structured Logging
Backend and integration code should log structured events. For external calls and mutating operations, log start, success, and failure with duration.
Recommended fields:
event.tenant.domain.environment.userIdwhere relevant.solutionId.routeIdorintegrationId.systemSlug.projectPath.topic.correlationId.durationMs.
Do Not Log Secrets
Never log:
- Tokens.
- API keys.
- Bearer headers.
- Refresh tokens.
- Client secrets.
- Passwords.
- Full prompts.
- Full files.
- Sensitive business payloads.
Use short previews, hashes, lengths, slugs, IDs, or metadata instead.
Correlation IDs
A correlation ID follows a business flow across route legs. It should appear in CloudEvents, logs, traces, task runs, and failure events. In klok.dev, Run → Logs finds a transaction by the start of its correlation ID and shows every event of it in order, and Run → Process runs filters runs by it (tab Runs). klok.dev follows tenant klok's log events so far (frontend-klok-dev#51); OpenSearch Dashboards has tenant klok's too, for 30 days; other tenants' events are not indexed yet (ipaas-service-deploy-manifests#10).
If a message reaches the broker without a correlation ID, the onramp should create one. If it already has a valid ID, the route should preserve it.
Tracing
OpenTelemetry-style tracing should connect ingress, broker, processing, and egress. Traces are especially valuable when latency is distributed across multiple route legs or external calls.
Investigation Pattern
- Start from the failed or hung transaction on Run → Logs → Problems, or from the link in an analysis mail.
- Read Kloker's analysis of it, if there is one: what happened, the likely cause and what to do, with the facts it was written from.
- Open the transaction: its events in order show the route where the status changed, the error code, the exception and the payload preview.
- Search the console lines and older logs in OpenSearch Dashboards with the transaction's In OpenSearch query
(
correlation_id:"…"), or read them from a terminal withklok logs(below). - Check the dead letter topic or the retry state if delivery failed (Run → Broker).
- Use the context graph (Build → Context graph) to find owners, source files, and related systems.
- Decide whether the issue is data, target availability, access, code, or platform.
From A Terminal, Or With Your Coding Agent
klok logs reads the same events, transactions and console lines of the last 30 days, with your klok login and what
your Keycloak groups give you. It only reads, and your coding agent uses it the same way, so ask it to look before it
guesses:
klok logs problems --since 24h # hung and failed transactions, grouped by error
klok logs transaction <correlation-id> # per route, what is still open, the first failure, the pods
klok logs console --correlation <correlation-id> # what the pods printed around it
klok logs search --route KLK007E1 --status FAILED --since 7d
Hung is a count of starts and ends, so one lost end can make a finished transaction look hung. klok logs transaction
names the invocation that never reported an end, and shows when the pods changed, which points at a rollout. Check the
outcome where it shows before you call it stuck.
Payloads are left out and stack traces cut unless you ask (--include-payload, --stack), because what an agent reads
leaves your machine. The walk and what each field tells are in klok-cli's documentation (Reading what a service did
with klok logs).