From 5786f20687f334146a229f0954e968c8b43ab92a Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 28 Feb 2024 12:36:45 -0800 Subject: [PATCH] plugins: fix encoding for OTEL env var passed to plugin Signed-off-by: Tonis Tiigi --- cli-plugins/manager/cobra.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cli-plugins/manager/cobra.go b/cli-plugins/manager/cobra.go index 219c74ee67..feff8a8fd6 100644 --- a/cli-plugins/manager/cobra.go +++ b/cli-plugins/manager/cobra.go @@ -2,7 +2,9 @@ package manager import ( "fmt" + "net/url" "os" + "strings" "sync" "github.com/docker/cli/cli/command" @@ -133,8 +135,14 @@ func getPluginResourceAttributes(cmd *cobra.Command, plugin Plugin) attribute.Se func appendPluginResourceAttributesEnvvar(env []string, cmd *cobra.Command, plugin Plugin) []string { if attrs := getPluginResourceAttributes(cmd, plugin); attrs.Len() > 0 { - envVarVal := attrs.Encoded(attribute.DefaultEncoder()) - env = append(env, ResourceAttributesEnvvar+"="+envVarVal) + // values in environment variables need to be in baggage format + // otel/baggage package can be used after update to v1.22, currently it encodes incorrectly + attrsSlice := make([]string, attrs.Len()) + for iter := attrs.Iter(); iter.Next(); { + i, v := iter.IndexedAttribute() + attrsSlice[i] = string(v.Key) + "=" + url.PathEscape(v.Value.AsString()) + } + env = append(env, ResourceAttributesEnvvar+"="+strings.Join(attrsSlice, ",")) } return env }