"Demystifying Context Values"
summary
Shows concrete rules for using Go's context values: use them for HTTP header propagation and distributed tracing, not to hide API dependencies; implement small dedicated packages that expose contextual logging helpers, keep keys as an unexported key type, and centralize defaults and error handling. Benchmarks and examples show context layering costs are tiny but warn about loop-wrapping bugs, and give exact code patterns for reading, writing, and propagating request-scoped IDs and log fields across microservices.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 1:20Context Values
- 2:30HTTP Request Information
- 4:25Background
- 5:43Header Data
- 6:25Cognitive Load
- 7:29Dedicated Functions
- 8:32General API
- 9:58Logging
- 14:08Interacting with Context
- 16:00Performance Concerns
- 17:47Making Bugs
- 19:18Summary
related talks
21mContextual Logging for Modern Go Applications
50mThe context package internals
22mType. Context.
07mHow Should We Access Global Resources?
32mHow to correctly use package context
42mBounded Context: Keep It Simple!
35m"Rush Tactics: Writing Go Code You Won’t Regret Later"
30mManaging Contextual Metadata Across a gRPC Ecosystem
