Correlate Microservice Logs Across Services Using Request IDs
Beginner Mode

Start your terminal to use beginner mode.

Scenario

Multiple microservices generate log files with events tracked by request IDs. You need to correlate logs across services to trace individual requests through the system.

Task

Write a Python script at /home/interview/trace_request.py that reads log files from three services (frontend.log, api.log, database.log in /home/interview/), finds all log entries for a specific request ID, sorts them chronologically, and saves the trace to /home/interview/request_trace.json.

The script should accept a request_id as a command-line argument: python3 trace_request.py <request_id>

All fields from the original log entries must be preserved in the output (some entries may contain additional fields like duration_ms).

Example

Log entry format (JSON lines):

{"timestamp": "2026-02-13T10:15:30.123Z", "service": "frontend", "level": "INFO", "request_id": "req_abc123", "message": "Request received", "duration_ms": 142}

Expected output in /home/interview/request_trace.json:

[
  {
    "timestamp": "2026-02-13T10:15:30.123Z",
    "service": "frontend",
    "level": "INFO",
    "request_id": "req_abc123",
    "message": "Request received",
    "duration_ms": 142
  },
  {
    "timestamp": "2026-02-13T10:15:30.245Z",
    "service": "api",
    "level": "INFO",
    "request_id": "req_abc123",
    "message": "Processing request"
  }
]

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →