Logging and Observability
Log Context
Include an Identifier
Context fields connect a log line to a request, job, or user action. Keeping the field name stable makes later filtering simple.
Program
Play the script to choose the request id and see it included in the log line.
log_context_line.sh
#!/usr/bin/env bash
request_id=
service="api"
status="ok"
line="service=$service request=$request_id status=$status"
echo "$line"
#!/usr/bin/env bash
request_id=
service="api"
status="ok"
line="service=$service request=$request_id status=$status"
echo "$line"
context field
A context field links the line to a specific operation.
request id
A request id lets multiple lines from one request be found together.
field name
Stable field names make logs useful to both humans and tools.