wavefrontHQ / wavefront-sdk-go

Wavefront Core Go SDK
Apache License 2.0
4 stars 21 forks source link

The application/Tags type acts like it supports by value semantics but really it doesn't #183

Open keep94 opened 2 months ago

keep94 commented 2 months ago

application.New() returns a Tags instance by value hinting that the Tags type supports by-value semantics. Unfortunately this is not the case. Consider this code:

tagsa := application.New("appName", "serviceName")
tagsb := tagsa

// Oops tagsb now has the same custom tag added to tagsa
tagsa.AddCustomTagFromEnv("varName", "tag")

Solution: application.New should be deprecated. A different new function that returns a Tags instead of Tags should be created. Documentation should stress that Tags does not support by-value semantics. Or application.New could just return Tags as a breaking change.

Alternatively, Tags could be made to support by-value semantics. To do this, modifications to CustomTags field of Tags would mean creating a new map each time rather than modifying it in place.