MCPcopy Index your code
hub / github.com/docker/cli / appendPluginResourceAttributesEnvvar

Function appendPluginResourceAttributesEnvvar

cli-plugins/manager/telemetry.go:50–85  ·  view source on GitHub ↗
(env []string, cmd *cobra.Command, plugin Plugin)

Source from the content-addressed store, hash-verified

48}
49
50func appendPluginResourceAttributesEnvvar(env []string, cmd *cobra.Command, plugin Plugin) []string {
51 if attrs := getPluginResourceAttributes(cmd, plugin); attrs.Len() > 0 {
52 // Construct baggage members for each of the attributes.
53 // Ignore any failures as these aren't significant and
54 // represent an internal issue.
55 members := make([]baggage.Member, 0, attrs.Len())
56 for iter := attrs.Iter(); iter.Next(); {
57 attr := iter.Attribute()
58 m, err := baggage.NewMemberRaw(string(attr.Key), attr.Value.AsString())
59 if err != nil {
60 otel.Handle(err)
61 continue
62 }
63 members = append(members, m)
64 }
65
66 // Combine plugin added resource attributes with ones found in the environment
67 // variable. Our own attributes should be namespaced so there shouldn't be a
68 // conflict. We do not parse the environment variable because we do not want
69 // to handle errors in user configuration.
70 attrsSlice := make([]string, 0, 2)
71 if v := strings.TrimSpace(os.Getenv(resourceAttributesEnvVar)); v != "" {
72 attrsSlice = append(attrsSlice, v)
73 }
74 if b, err := baggage.New(members...); err != nil {
75 otel.Handle(err)
76 } else if b.Len() > 0 {
77 attrsSlice = append(attrsSlice, b.String())
78 }
79
80 if len(attrsSlice) > 0 {
81 env = append(env, resourceAttributesEnvVar+"="+strings.Join(attrsSlice, ","))
82 }
83 }
84 return env
85}

Callers 2

PluginRunCommandFunction · 0.85

Calls 4

NextMethod · 0.80
StringMethod · 0.65
LenMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…