ref!: modify Attributes type for Logs and Metrics#1205
Conversation
This change eliminates preemptively boxing the attribute values and allows us to use the attribute.Builder for setting attributes with no allocations. This change also has the benefit of enforcing strong attribute types rather than any.
Semver Impact of This PR🔴 Major (breaking changes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Breaking Changes 🛠
New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Deps
Other
🤖 This preview updates automatically when you update the PR. |
| for _, v := range attrs { | ||
| t, ok := mapTypesToStr[v.Value.Type()] | ||
| if !ok || t == "" { | ||
| debuglog.Printf("invalid attribute type set: %v", t) |
There was a problem hiding this comment.
Should we keep the debug log if an invalid type is found?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| } | ||
|
|
||
| defaultAttrs := make(map[string]Attribute) | ||
| defaultAttrs := make(map[string]attribute.Value) |
There was a problem hiding this comment.
Missing capacity hint for map initialization
Low Severity
The defaultAttrs map is initialized without a capacity hint, unlike the identical code in log.go line 78 which uses make(map[string]attribute.Value, len(defaults)). This inconsistency causes an unnecessary reallocation when attributes are added since the map size is known upfront.


Description
This PR modifies attribute storing to be a
map[string]attribute.Value.The main drive for the attribute storing change is to strongly type the attributes API. Previously a user could bypass the attribute.Builder and set an attribute on a log with (highly unlikely, but good to guard against):
This change also eliminates preemptively boxing the attribute values and allows us to use the attribute.Builder for setting attributes with no allocations.
Changelog Entry Instructions
To add a custom changelog entry, uncomment the section above. Supports:
For more details: custom changelog entries
Reminders
feat:,fix:,ref:,meta:)Changelog Entry