Last week we saw the potential dangers of context key collisions. Today let’s look at how to avoid this problem. The GoDoc we looked at last week gave us a clue: // packages should define keys as an unexported type to avoid // collisions. Let’s dive into what this is suggesting, and why it works. First: context.WithValue accepts any comparable type as a key. This includes custom types. And by using a custom type that’s unexported, we can ensure that no other package uses our keys.