[SDK] Add Entity support to Resource - #4490
Open
shashankxrm wants to merge 12 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4490 +/- ##
==========================================
+ Coverage 83.13% 83.24% +0.12%
==========================================
Files 519 521 +2
Lines 20256 20414 +158
==========================================
+ Hits 16837 16991 +154
- Misses 3419 3423 +4
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #3652. This PR implements the SDK Resource portion of entity propagation; follow-up work remains as noted below.
Changes
Adds Entity support to the SDK
Resourcelibrary, which is the next step identified on #3652 now thatEnvEntityDetector/OTEL_ENTITIESparsing exists (#3795).This PR:
Entityvalue type (type, identity, description, schema URL).Resourcetogether with unassociated attributes.GetAttributes()as the flattened view: entity identity and description plus unassociated attributes, as required when entities are present.GetEntities()andGetUnassociatedAttributes().Resourceconstructor that accepts attributes, schema URL, and entities, with entity validation and normalization.Mergewhen either resource contains entities.Resource::Create(attributes, schema_url, entities)while leaving the existing two-argumentCreatein place.sdk/test/resourcecoverage (newentity_test, plus Resource construction / merge / Create cases).This does not complete entity propagation end-to-end. Detectors still emit flattened attributes, and exporters are unchanged.
Merge behavior
Attribute-only merge is unchanged: if neither resource has entities, the existing attribute merge behavior is preserved.
If either resource has entities, merge follows the resource data model:
These rules match specification Examples 1–3 (loose attribute vs entity, updating loose attribute evicting an entity, same-type identity mismatch plus key conflict dropping the lower-priority entity).
Two points are specified less tightly than the examples, so this implementation is an interpretation:
hostand dropservice.Createstill doesGetDefault().Merge(OTELResourceDetector).Merge(user resource). When both attributes and entities are passed, the user resource is built so entity-owned keys are not left as unassociated attributes (equivalent to creating from attributes and then merging a resource that holds those entities).[service.name](http://service.name/)fallback inspects flattened attributes so an entity-owned[service.name](http://service.name/)is not overwritten.Compatibility
Resourceconstructors are unchanged.Resource::Create(attributes, schema_url)is unchanged for callers; it delegates to the new overload with an empty entity list.Mergebehavior is preserved.Entity, getters, three-argument constructor,Createoverload).Resourcenow storesentities_andunassociated_attributes_in addition to the flattenedattributes_map, so object layout changes. This is an SDK type; this PR does not claim ABI stability across versions.Scope / Follow-up work
This PR is limited to the SDK Resource library, as discussed on #3652: add entities to
Resourcefirst, then populate detectors and OTLP.Intentionally not in this PR:
Entityobjects from resource detectors (includingEnvEntityDetector, which still returns flattened attributes).OTEL_ENTITIESparsing.entity_refs(or exporter attribute helpers).ResourceDetector::Createoverload that accepts entities.EnvEntityDetectorfrom defaultResource::Create()(it remains opt-in viaopentelemetry_resource_detectors).Those are follow-up steps, not omissions.
Testing
Locally:
entity_test: 8/8 passedresource_test: 51/51 passed (existing Resource tests kept as regression coverage)clang-format-18 --Werror -npassedCI has not run on this PR yet.
References
EnvEntityDetector; out of scope here)CHANGELOG.mdupdated for non-trivial changes