Bird
0
0

Consider this simplified code snippet in a microservice receiving an HTTP request:

medium📝 Analysis Q13 of 15
Microservices - Monitoring and Observability
Consider this simplified code snippet in a microservice receiving an HTTP request:
def handle_request(request):
    correlation_id = request.headers.get('X-Correlation-ID')
    log(f"Start processing request {correlation_id}")
    # ... process ...
    log(f"End processing request {correlation_id}")
What will be logged if the incoming request has header X-Correlation-ID: abc123?
ANo logs will be generated
BStart processing request abc123 End processing request abc123
CStart processing request X-Correlation-ID End processing request X-Correlation-ID
DStart processing request None End processing request None
Step-by-Step Solution
Solution:
  1. Step 1: Extract Correlation ID from headers

    The code uses request.headers.get('X-Correlation-ID') which returns the header value if present.
  2. Step 2: Check the header value in the request

    The request has X-Correlation-ID: abc123, so correlation_id will be 'abc123'.
  3. Final Answer:

    Start processing request abc123 End processing request abc123 -> Option B
  4. Quick Check:

    Header value read correctly = logs with abc123 [OK]
Quick Trick: Headers.get returns value or None; here value exists [OK]
Common Mistakes:
MISTAKES
  • Assuming header key is logged instead of value
  • Thinking None is logged when header exists
  • Believing no logs are generated

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes