Skip to content

[DRAFT] Entity SDK prototype#8464

Open
jsuereth wants to merge 4 commits into
open-telemetry:mainfrom
jsuereth:wip-entity-sdk-for-reals
Open

[DRAFT] Entity SDK prototype#8464
jsuereth wants to merge 4 commits into
open-telemetry:mainfrom
jsuereth:wip-entity-sdk-for-reals

Conversation

@jsuereth

@jsuereth jsuereth commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This is a more up-to-date PR accounting for changes from OpenTelemetry Configuraiton work for Entities.

What this does:

  • Implements Entity necessary components in core SDK, hidden in internal as much as feasible (this needs @open-telemetry/java-maintainers feedback on some of the challenges here)
  • Creates "public facing" SDK interface in sdk-extensions/incubating
  • Attempts to write in feature flag to turn on Entity capabilities.

A few issues though:

  • We want ResourceDetection to upgrade to use entities going forward. I have lots of questions for configuration I'll need to discuss with those folks and @jack-berg w/ Entities SIG to see a path forward here
  • Resource is exposed in the SDK as an autovalue - which has compatibility limitations. I"m not sure how to keep the auto API compat bot happy here as effectively you can't subclass this without breaking Java's visibiltiy rules, but also it appears like it can be subclassed if you do bytecode rewritting so it technically is a bincompat change.
  • The way I'm supporting Config is prretty bogus. I tried to keep it isolated but I'm not happy with it. Additionally the ResourceFactory code at some point is only keeping attributes for Resource - which is hugely problematic for Entity. I'd like to refactor the whole kit and kaboodle but I know stabilizaiton is coming

- Create new Entity Detectors that are completely separate from existing
  reosurce detectors so entity must be FULL opt-in before behavior
  changes, even if OTLP is non-breaking.
- Wire "either/or" scenarios into resource factory and declarative
  config.

TODOs we need to sort out:

- Features of ResourceConfiguration spec that interact poorly with
  entities, e.g. attribute-specific filters that aren't entity aware,
  raw attribute definitions.
- Adding `env` as a supported detector for reading in Entity env
  variable propagation.
- Dealing with oddities of ResourceBuilder/Factory wanting to only use
  attributes in Java - we worked around it for now.

@jack-berg jack-berg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You'll need to handle some merge conflicts since declarative config has been undergoing construction:

  • It moved out of the incubator into a dedicated artifact in #8265
  • We started commiting generated POJOs to VCS in #8408

As mentioned in the SIG meeting, I don't think you need the incubator copies of Entity interfaces. I pushed a commit here to delete them: jack-berg@3ea17f4

Per the discussion, resource detectors will need to updated to optionally produce entity-aware resources. If the user opts in, then those resource detectors can call the internal APIs from opentelemetry-sdk-common to produce those.

/**
* Returns a map of attributes that describe the resource.
*
* @return a map of attributes.
*/
public abstract Attributes getAttributes();
// @Memoized - This breaks nullaway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

???

}

/** Appends a new entity on to the end of the list of entities. */
ResourceBuilder add(Entity e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
ResourceBuilder add(Entity e) {
ResourceBuilder addEntity(Entity e) {

return this;
}

/** Appends a new collection of entities on to the end of the list of entities. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Omit this sugar to start.

});
// In merge rules, raw comes last, so we return these last.
result.putAll(getRawAttributes());
return result.build();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why compute / memoize these at get time instead of at initialization time? I.e. in Resource.create methods.

*
* @return a map of attributes.
*/
abstract Attributes getRawAttributes();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

???

*
* @param entityType the entity type string of this entity.
*/
public static final EntityBuilder builder(String entityType) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public static final EntityBuilder builder(String entityType) {
public static EntityBuilder builder(String entityType) {

* @param description a map of attributes that describe the entity.
* @return a {@code Entity}.
*/
static final Entity create(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
static final Entity create(
static Entity create(

* A service provider interface (SPI) for providing a collection of {@link Entity} that are merged
* into the {@link Resource#getDefault() default resource}.
*/
public interface EntityDetector extends Ordered {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need a new EntityDetector SPI rather than just using existing ResourceProvider and having implementations provide entity aware resources?


ExperimentalResourceDetectionModel detectionModel = model.getDetectionDevelopment();
if (detectionModel != null) {
if (context.isEntitiesEnabled()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's assume that the toggle flag is controlled on the instrumentation side of things (i.e. the implementations of resource detectors / entity detectors).

if (context.isEntitiesEnabled()) {
List<ExperimentalResourceDetectorModel> detectorModels = detectionModel.getDetectors();
if (detectorModels != null) {
List<EntityDetector> detectors = new ArrayList<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SPIs work differently in declarative config than in autoconfigure. Rather than having a dedicated SPI per extension plugin interface (i.e. ResourceProvider, ConfigurableSpanExporterProvider, etc), there's a single ComponentProvider SPI. Implementations specify the type of extension plugin interface they provide via ComponentProvider.getType().

Also, we we're discussing in DMs about adjusting the semantics of existing declarative configuration resource provider types to make them entity aware, such that YAML like:

resource:
  attributes_list: ${OTEL_RESOURCE_ATTRIBUTES}
  detection/development: # /development properties may not be supported in all SDKs
    detectors:
      - env: # We add this - it allows runtimes, like Cloud Run or AWS lambda to pass resource identity via ENV variable without blowing away existing working setups.
      - service:
      - host:
      - process:
      - container:

Which is valid today. The env, service, host, process, container detectors would be updated to produce entity-aware Resources.

Going this route, I think there's basically nothing that needs to be done in ResourceFactory. It will start configuring entity-aware resources when the detectors are updated to produce them.

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.

2 participants