Skip to content

Proposal: Remove AttributeValue class and implement attribute value type-safety with a type-indicating Key. #1580

@jkwatson

Description

@jkwatson

Is your feature request related to a problem? Please describe.

  1. Users have expressed some confusion about the way the Semantic conventions for Attribute keys/values are implemented. The usage of the AttributeSetter classes is awkward, and when you aren't using a pre-defined instance of the SemanticAttributes class, it's awkward for API users to have to define their own AttributeSetters to make their API usage consistent.
  2. The use of AttributeValue requires, in almost every case, an additional instance allocation to wrap the value that is being set in the Attributes. Most commonly, in instrumentation, the attribute Keys are the thing that is known ahead of time and can be statically allocated, requiring no additional runtime allocation overhead, after the instrumentation (or the API itself, in the case of pre-defined semantic attributers) is initialized. Our current implementation requires the wrapping of every value, at runtime, in the hot path of the application of the instrumentation.

Describe the solution you'd like
Rather than provide the type-safe wrapper the value side of the attribute, I propose to make the type safety be enforced by providing type-information on the key side. The API would look something like (for the Span interface):

 void setAttribute(StringValuedKey key, String value);
 void setAttribute(LongValuedKey key, long value);
 void setAttribute(DoubleValuedKey key, double value);
 void setAttribute(BooleanValuedKey key, boolean value);
...

As mentioned above, this would have the significant allocation advantage of not needing to do any extra allocations at runtime for the values of the attributes, at least for the String valued attributes (which make up the majority of our semantic attributes). The implementation would probably need to wrap the primitives in boxed versions in the storage, so there would be a net zero gain in runtime allocations for the 3 primitive-typed values [again, assuming the keys are statically pre-defined, either in the instrumentation, or in the API's semantic attribute definitions].

A version of this solution was prototyped in this PR: #1097

Describe alternatives you've considered
Several other alternatives have been prototyped and proposed:

Additional context
This change would be a significant API-breaking change, and would be hard to retrofit post GA. It could be done as an API addition, but would then have the significant downside of having duplicated Attribute management APIs and semantic conventions. Hence, I have marked this issue as required-for-ga, because I think it could only feasibly be done before then.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions