Skip to content

Table of Contents

Exercises — Month 6 · Week 1 (Production & Observability)

Standard-library-only exercises that rebuild the small, well-specified pieces beneath an observability stack: trace propagation, readiness aggregation, and a log-redaction policy. Run all tests:

go test ./exercises/month-06/week-1/...

Prompts

1. traceparent — W3C Trace Context header

Implement Parse and SpanContext.String for the version-00 traceparent header 00-<32 hex trace-id>-<16 hex span-id>-<2 hex flags>.

  • Reject wrong versions, wrong field lengths, non-hex characters, and the all-zero trace-id/span-id (invalid per spec).
  • The sampled flag is the low bit of the flags byte; String must normalise it back to the canonical 00/01.
  • Wrap every failure so errors.Is(err, ErrMalformed) holds.

2. health — readiness aggregator

Implement an Aggregator that runs named component Checks and reduces them to an overall status with worst-wins precedence (Down > Degraded > Up).

  • No components ⇒ overall Up (nothing can be unhealthy).
  • A failing check becomes Down and carries its error message.
  • Component results are sorted by name for deterministic output.

3. redact — slog secret-redaction policy

Implement Redactor(keys...) returning a slog.HandlerOptions.ReplaceAttr function that masks the value of any attribute whose key (case-insensitive) is sensitive, leaving the key and all other attrs intact.

  • Match is case-insensitive; the mask is [REDACTED].
  • Must work for non-string values too (the masked output is always a string).
  • End-to-end: wired into a JSON handler, the secret value must never appear in the output while non-sensitive fields survive.

Results

Exercise Focus Status
traceparent W3C trace-context parse/format ✅ green
health readiness aggregation, worst-wins ✅ green
redact slog ReplaceAttr secret masking ✅ green