attribute: add MAP type with key deduplication#8130
attribute: add MAP type with key deduplication#8130iyashjayesh wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
Implements issues open-telemetry#7935 and open-telemetry#7957. Adds a new MAP attribute value type (map<string, AnyValue>) to the attribute package, as required by the OpenTelemetry specification: https://opentelemetry.io/docs/specs/otel/common/#anyvalue Key changes: - attribute/value.go: add MAP Type constant, MapValue() constructor with last-write-wins key deduplication, AsMap() accessor, and MAP support in Emit() and AsInterface(). - attribute/hash.go: add mapID type identifier and MAP case in hashKV() — keys are sorted before hashing for order-independence. - attribute/type_string.go: regenerated via 'go generate ./attribute/...' Deduplication semantics (per spec 'e.g. by removing duplicates'): - If the same key appears more than once, the last value wins. - The relative order of the first occurrences of each key is preserved. Resolves: open-telemetry#7935 Resolves: open-telemetry#7957
Implements issues open-telemetry#7935 and open-telemetry#7957. Adds a new MAP attribute value type (map<string, AnyValue>) to the attribute package, as required by the OpenTelemetry specification: https://opentelemetry.io/docs/specs/otel/common/#anyvalue Key changes: - attribute/value.go: add MAP Type constant, MapValue() constructor with last-write-wins key deduplication, AsMap() accessor, and MAP support in Emit() and AsInterface(). - attribute/hash.go: add mapID type identifier and MAP case in hashKV() — keys are sorted before hashing for order-independence. - attribute/type_string.go: regenerated via 'go generate ./attribute/...' Deduplication semantics (per spec 'e.g. by removing duplicates'): - If the same key appears more than once, the last value wins. - The relative order of the first occurrences of each key is preserved. Resolves: open-telemetry#7935 Resolves: open-telemetry#7957
|
Have you seen #7943? |
|
@pellared Yes, I did look at #7943 before opening this PR. It has been in draft since February and appears stalled, no commits since early March and still marked as draft. Given that both #7935 and #7957 remain open, I opened this PR as a fresh, ready-to-review implementation. That said, I'm happy to coordinate, if @itssaharsh is actively working on #7943 and plans to bring it to a reviewable state soon, I can close this one to avoid duplication. Otherwise, I'd suggest proceeding here since this PR is ready for review and covers both issues. Happy to do whatever the maintainers prefer! |
|
I was working actively it's just that after my last commit, I got no review as I think all the maintainers are busy. So I had nothing to add to that. |
|
@iyashjayesh, please see the comments that I have already posted in #7943. A lot of comments that I submitted previously apply to this PR as well. It also violates other patterns that we follow in this repository. This issue is complex and requires deep understanding and analysis. |
Closes #7935
Closes #7957
What changed
Adds a
MAPattribute value type (map<string, AnyValue>) to thego.opentelemetry.io/otel/attributepackage, as required by the OpenTelemetry specification.New API surface
attribute.MAP- newTypeconstantattribute.MapValue(kvs []KeyValue) Value- constructor(Value).AsMap() []KeyValue- accessorDeduplication (spec compliance)
Per the spec:
Enforcement happens at construction time in
MapValue:value is kept.
maintained in the output.
Hashing
hashKVinhash.gohandles theMAPcase by sorting keys beforehashing, so two MAP values with the same entries in different order
produce the same hash (order-independent).
Notes for reviewers
[]KeyValueis stored directly asanyinValue.slicerather thanvia the generic
SliceValuehelper (which is constrained tobool | int64 | float64 | string). This is the only storagedifference from other slice types.
first-write-winsis preferred overlast-write-wins- happy to adjust.