Skip to content

Instantly share code, notes, and snippets.

@garystafford
Created July 5, 2021 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/9792131de51cddca766fb0aea443270e to your computer and use it in GitHub Desktop.
Save garystafford/9792131de51cddca766fb0aea443270e to your computer and use it in GitHub Desktop.
func injectHeadersIntoMetadata(ctx context.Context, req *http.Request) metadata.MD {
headers := []string{
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"}
var pairs []string
for _, h := range headers {
if v := req.Header.Get(h); len(v) > 0 {
pairs = append(pairs, h, v)
}
}
return metadata.Pairs(pairs...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment