(env []string, cmd *cobra.Command, plugin Plugin)
| 48 | } |
| 49 | |
| 50 | func 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 | } |
searching dependent graphs…