104
// "contextmetadata-<key>" entries plus unprefixed well-known keys. Old readers that
105
// don't understand the proto key will fall back to these.
107
>
var trailerPairs []string
108
>
109
>
// Proto format: serialize all metadata into a single protobuf message.
110
>
protoMsg := &contextpropagationspb.ContextMetadata{
111
>
Entries: make(map[string]string, len(allMetadata)),
112
>
}
113
>
for key, value := range allMetadata {
114
protoMsg.Entries[key] = fmt.Sprint(value)
115
}
117
c.throttledLogger.Warn("ContextMetadataInterceptor: Failed to marshal proto metadata, falling back to legacy-only",
118
tag.Error(err),
119
)
121
>
trailerPairs = append(trailerPairs, protoTrailerKey, string(protoBytes))
122
>
}
123
124
// Legacy format: emit individual keys for backward compatibility with older readers.
125
// Skip entries with HTTP/2-unsafe values (the proto key handles those).
127
valStr := fmt.Sprint(value)
128
if !isHTTP2SafeValue(valStr) {