From 23516b54dd9b382ae3daaba03e677e09d3ab9abe Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 10 Sep 2021 00:46:20 +0300 Subject: Fix issue with attributes.Init resets existing attributes Experiment with protoregistry Signed-off-by: Valery Piashchynski --- plugins/http/attributes/attributes.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'plugins/http/attributes/attributes.go') diff --git a/plugins/http/attributes/attributes.go b/plugins/http/attributes/attributes.go index 81d9f01d..5df80da4 100644 --- a/plugins/http/attributes/attributes.go +++ b/plugins/http/attributes/attributes.go @@ -37,9 +37,14 @@ func (v attrs) del(key string) { delete(v, key) } -// Init returns request with new context and attribute bag. +// Init is idempotent returns request with new context and attribute bag. func Init(r *http.Request) *http.Request { - return r.WithContext(context.WithValue(r.Context(), PsrContextKey, attrs{})) + // do not overwrite the PsrContextKey payload + if val := r.Context().Value(PsrContextKey); val == nil { + return r.WithContext(context.WithValue(r.Context(), PsrContextKey, attrs{})) + } + + return r } // All returns all context attributes. -- cgit v1.2.3