in http/server/contextlogger/context_logging.go [72:99]
func BuildAttributes(ctx context.Context, r *http.Request, extractFunc func(ctx context.Context, r *http.Request) map[string]interface{}) []interface{} {
md, ok := metadata.FromIncomingContext(ctx)
headers := make(map[string]string)
if ok {
for key, values := range md {
if len(values) > 0 {
headers[key] = values[0]
}
}
}
attributes := defaultCtxLogAttributes(r)
logAttrs := make(map[string]interface{})
// Use the extract function to get additional attributes.
if extractFunc != nil {
extractedAttrs := extractFunc(ctx, r)
for k, v := range extractedAttrs {
logAttrs[k] = v
}
}
// Include metadata headers as part of the attributes.
attributes = append(attributes, "log", logAttrs)
// grab desired headers from the request (based on extraction function passed to request ID middleware)
attributes = append(attributes, "headers", headers)
return attributes
}