Dear all,
TL;DR
This topic has been discussed many times already here and in issues. Go intentionally doesn't offer a way to identify the current goroutine. There are good reasons for that decision. But there are sometimes also good reasons for having some kind of goroutine-local context. Thats why there have been a couple of workarounds, but they didn't work too well and seem to be abandoned.
I recently was thinking about how to add context-aware debug logging in a library and found myself in the same situation as many others before. Because there didn’t seem to be a maintained library that solved that problem, I looked into it myself and eventually found an efficient and relatively "stable" way to store a context in the goroutine-local storage, by piggybacking it onto the profiling labels. (It’s still a hack of course, but I hope less than the previous gls attempts.)
Given the frequent reoccurrence of the topic, I guess it could be useful to others as well so I wrapped it up in a small module. (see above) Feedback as always appreciated.
Sven (@ansiwen)