Skip to content

Conversation

@Hasv07
Copy link
Contributor

@Hasv07 Hasv07 commented Dec 19, 2025

Related #3652
Changes:

  • Add EnvEntityDetector class to parse OTEL_ENTITIES environment variable
  • Parse entity format: type{id_attrs}[desc_attrs]@schema_url
  • Support percent-encoding for reserved characters
  • Handle duplicate entities, conflicting attributes, and malformed input per spec
  • Include basic test coverage

Details:

  • EnvEntityDetector::Detect() reads OTEL_ENTITIES and returns Resource with parsed attributes
  • ParseEntities() splits input by semicolons and parses each entity definition
  • ParseSingleEntity() extracts type, id_attrs, desc_attrs, and schema_url from entity string
  • ParseKeyValueList() parses comma-separated key=value pairs
  • PercentDecode() decodes percent-encoded values
  • BuildEntityIdentityKey() creates stable key for duplicate detection
  • Error handling malformed entities skipped, duplicates use last occurrence, conflicts log warnings

Implements entity propagation spec:
https://opentelemetry.io/docs/specs/otel/entities/entity-propagation/

@Hasv07 Hasv07 requested a review from a team as a code owner December 19, 2025 18:50
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 19, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@Hasv07 Hasv07 marked this pull request as draft December 19, 2025 21:18
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.91%. Comparing base (162246f) to head (d37895a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3795      +/-   ##
==========================================
- Coverage   89.93%   89.91%   -0.01%     
==========================================
  Files         225      225              
  Lines        7163     7163              
==========================================
- Hits         6441     6440       -1     
- Misses        722      723       +1     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hasv07 Hasv07 force-pushed the sdk/implement-env-entity-detector branch from 1d75005 to f7a5844 Compare December 19, 2025 21:29
@Hasv07 Hasv07 marked this pull request as ready for review December 19, 2025 21:42
@Hasv07 Hasv07 force-pushed the sdk/implement-env-entity-detector branch 2 times, most recently from 4e42cbc to 296d576 Compare December 20, 2025 18:41
…emetry#3652)

Changes:

Add EnvEntityDetector class to parse OTEL_ENTITIES environment variable
Parse entity format: type{id_attrs}[desc_attrs]@schema_url
Support percent-encoding for reserved characters
Handle duplicate entities, conflicting attributes, and malformed input per spec
Include comprehensive test coverage
Fix schema URL handling to pass to Resource

Details:

EnvEntityDetector::Detect() reads OTEL_ENTITIES and returns Resource with parsed attributes
ParseEntities() splits input by semicolons and parses each entity definition
ParseSingleEntity() extracts type, id_attrs, desc_attrs, and schema_url from entity string
ParseKeyValueList() parses comma-separated key=value pairs
PercentDecode() decodes percent-encoded values
BuildEntityIdentityKey() creates stable key for duplicate detection
Error handling: malformed entities skipped, duplicates use last occurrence, conflicts log warnings
Implements entity propagation spec: https://opentelemetry.io/docs/specs/otel/entities/entity-propagation
@Hasv07 Hasv07 force-pushed the sdk/implement-env-entity-detector branch from 296d576 to aeec00f Compare December 21, 2025 17:33
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contribution

Copy link
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! One minor request - please move this resource detector and tests to the resource_detectors folder.
https://github.com/open-telemetry/opentelemetry-cpp/tree/main/resource_detectors

std::string{opentelemetry::common::StringUtil::Trim(entity_str.substr(cursor + 1))};

// TODO: Use a proper Schema URL validator when available.
if (out.schema_url.empty() || out.schema_url.find("://") == std::string::npos)
Copy link
Member

@lalitb lalitb Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the TODO mentions that schema validation needs work, but right now it's too loose - it accepts anything with :// in it. We should at least check that the scheme is http or https like the spec requires.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From:
https://opentelemetry.io/docs/specs/otel/entities/entity-propagation/#validation-requirements

Schema URL, if present, MUST be a valid URI

so this should not be restricted to http or https only.

But I agree, this probably needs revision, as one of the examples given:

# Multiple entities with schema URL
OTEL_ENTITIES="service{service.name=my-app,service.instance.id=instance-1}[service.version=1.0.0]@/schemas/1.21.0;host{host.id=host-123}[host.name=web-server-01]"

does not even use a scheme with ://.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it for now to validate general URIs. Stricter schema URI checks can be updated when new guidance is available. Thanks

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Have couple of non-blocking comments - can be handled in current PR or as separate improvement.

Hasv07 added 4 commits January 5, 2026 20:29
…n EnvEntityDetector

- Use nostd::get_if instead of nostd::get for safe string access
- Use direct variant comparison instead of string conversion
- Handles type mismatches correctly (variants with different types compare as unequal)
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contribution

@marcalff marcalff merged commit 6cafbac into open-telemetry:main Jan 6, 2026
110 of 114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants