@@ -3,14 +3,10 @@ package manager
33import (
44 "fmt"
55 "os"
6- "strings"
76 "sync"
87
98 "github.com/docker/cli/cli/command"
109 "github.com/spf13/cobra"
11- "go.opentelemetry.io/otel"
12- "go.opentelemetry.io/otel/attribute"
13- "go.opentelemetry.io/otel/baggage"
1410)
1511
1612const (
@@ -105,75 +101,3 @@ func AddPluginCommandStubs(dockerCli command.Cli, rootCmd *cobra.Command) (err e
105101 })
106102 return err
107103}
108-
109- const (
110- // resourceAttributesEnvVar is the name of the envvar that includes additional
111- // resource attributes for OTEL as defined in the [OpenTelemetry specification].
112- //
113- // [OpenTelemetry specification]: https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration
114- resourceAttributesEnvVar = "OTEL_RESOURCE_ATTRIBUTES"
115-
116- // dockerCLIAttributePrefix is the prefix for any docker cli OTEL attributes.
117- //
118- // It is a copy of the const defined in [command.dockerCLIAttributePrefix].
119- dockerCLIAttributePrefix = "docker.cli."
120- cobraCommandPath = attribute .Key ("cobra.command_path" )
121- )
122-
123- func getPluginResourceAttributes (cmd * cobra.Command , plugin Plugin ) attribute.Set {
124- commandPath := cmd .Annotations [CommandAnnotationPluginCommandPath ]
125- if commandPath == "" {
126- commandPath = fmt .Sprintf ("%s %s" , cmd .CommandPath (), plugin .Name )
127- }
128-
129- attrSet := attribute .NewSet (
130- cobraCommandPath .String (commandPath ),
131- )
132-
133- kvs := make ([]attribute.KeyValue , 0 , attrSet .Len ())
134- for iter := attrSet .Iter (); iter .Next (); {
135- attr := iter .Attribute ()
136- kvs = append (kvs , attribute.KeyValue {
137- Key : dockerCLIAttributePrefix + attr .Key ,
138- Value : attr .Value ,
139- })
140- }
141- return attribute .NewSet (kvs ... )
142- }
143-
144- func appendPluginResourceAttributesEnvvar (env []string , cmd * cobra.Command , plugin Plugin ) []string {
145- if attrs := getPluginResourceAttributes (cmd , plugin ); attrs .Len () > 0 {
146- // Construct baggage members for each of the attributes.
147- // Ignore any failures as these aren't significant and
148- // represent an internal issue.
149- members := make ([]baggage.Member , 0 , attrs .Len ())
150- for iter := attrs .Iter (); iter .Next (); {
151- attr := iter .Attribute ()
152- m , err := baggage .NewMemberRaw (string (attr .Key ), attr .Value .AsString ())
153- if err != nil {
154- otel .Handle (err )
155- continue
156- }
157- members = append (members , m )
158- }
159-
160- // Combine plugin added resource attributes with ones found in the environment
161- // variable. Our own attributes should be namespaced so there shouldn't be a
162- // conflict. We do not parse the environment variable because we do not want
163- // to handle errors in user configuration.
164- attrsSlice := make ([]string , 0 , 2 )
165- if v := strings .TrimSpace (os .Getenv (resourceAttributesEnvVar )); v != "" {
166- attrsSlice = append (attrsSlice , v )
167- }
168- if b , err := baggage .New (members ... ); err != nil {
169- otel .Handle (err )
170- } else if b .Len () > 0 {
171- attrsSlice = append (attrsSlice , b .String ())
172- }
173-
174- if len (attrsSlice ) > 0 {
175- env = append (env , resourceAttributesEnvVar + "=" + strings .Join (attrsSlice , "," ))
176- }
177- }
178- return env
179- }
0 commit comments