Ravindra BagaleCourses & study guides मराठी

Chapter 95: Logging with Loki, Elastic Stack and CloudWatch

DevOps

95.13 Time zones, parsing and multiline stack traces

Story (fictional teaching scenario). At a fictional Pune support desk, Sara from Oslo sees 00:00 UTC while Priya sees 05:30 IST. They realize it is the same instant, not two outages.

Time zones, parsing and multiline stack traces
Time zones, parsing and multiline stack traces

Why

Incorrect time interpretation and broken multiline grouping can hide the event you need.

What

  • UTC is a common reference time; IST here is Asia/Calcutta at UTC+05:30.
  • An offset-aware timestamp states its relationship to UTC.
  • Parsing converts text into structured values; a malformed record must be accounted for.
  • A multiline event spans physical lines, such as a stack trace. A framing rule decides which lines belong together.

How

  1. Store explicit offsets or UTC and choose display time intentionally.

  2. Reject or quarantine malformed synthetic records without hiding a rejected count.

  3. Join stack lines near the producer with format-specific rules.

  4. Keep one JSON object per line by encoding embedded newlines inside a string.

Example 1: Convert one instant locally

  1. Read the command or request.
from datetime import datetime, timezone, timedelta
dt = datetime.fromisoformat("2026-11-01T00:00:00+00:00")
print(dt.astimezone(timezone(timedelta(hours=5, minutes=30))).isoformat())
  1. Read the result.

Output (ACTUAL deterministic local Python; NOT a logging-stack integration)

2026-11-01T05:30:00+05:30
  1. Line by line: The import supplies time handling. fromisoformat reads an explicit UTC offset. astimezone converts the instant to IST without adding a second false offset. This same transform is actually tested in the local lab, including date rollover.

Example 2: Frame a fake stack

  1. Read the command or request.
ERROR fictional_failure
  at demo.py:1
ERROR next_failure
  1. Read the result.

Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)

Event 1: ERROR fictional_failure plus its indented continuation.
Event 2: ERROR next_failure.
  1. Line by line: This is an artificial start-line rule, not a general stack parser. Wrong framing can merge unrelated requests or split one failure into many alerts. No real exception log is read.

Ravindra Bagale's Tip

Changing display time is not changing when the event happened.

Did you understand? Let us try it once more.