Skip to content

Conversation

@trask
Copy link
Member

@trask trask commented Aug 21, 2025

The generic type makes it awkward to use with @AutoService, because it requires you to use SuppressWarnings("rawtypes") (some background at google/auto#870), e.g.

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/c7dd76454f5af080a1c385fdb7fda2c6bace68f5/instrumentation/resources/library/src/main/java/io/opentelemetry/instrumentation/resources/internal/ProcessResourceComponentProvider.java#L19-L20

Plus, it doesn't seem like we lose much by removing the generic type (in fact it ends up being slightly less code).

@trask trask force-pushed the remove-component-provider-generic-type branch 4 times, most recently from 696ddc4 to 03ea864 Compare August 21, 2025 23:55
@codecov
Copy link

codecov bot commented Aug 22, 2025

Codecov Report

❌ Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.16%. Comparing base (36ca9b8) to head (0a14e97).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...incubator/fileconfig/DeclarativeConfigContext.java 44.44% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7606      +/-   ##
============================================
- Coverage     90.18%   90.16%   -0.03%     
+ Complexity     7226     7225       -1     
============================================
  Files           820      820              
  Lines         21790    21794       +4     
  Branches       2135     2136       +1     
============================================
- Hits          19651    19650       -1     
- Misses         1468     1472       +4     
- Partials        671      672       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@trask trask force-pushed the remove-component-provider-generic-type branch 2 times, most recently from 391e7a6 to d25ee3c Compare August 22, 2025 02:21

assertThat(exporter.toString()).isEqualTo(expectedExporter.toString());

assertThat(exporter.toString()).isEqualTo(expectedExporter.toString());
Copy link
Member Author

Choose a reason for hiding this comment

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

this is just removing an existing duplicative line


assertThat(exporter.toString()).isEqualTo(expectedExporter.toString());

assertThat(exporter.toString()).isEqualTo(expectedExporter.toString());
Copy link
Member Author

Choose a reason for hiding this comment

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

this is just removing an existing duplicative line

@trask trask force-pushed the remove-component-provider-generic-type branch 4 times, most recently from c3590d0 to 6c64fe5 Compare August 22, 2025 02:48
@trask trask force-pushed the remove-component-provider-generic-type branch from 6c64fe5 to 5a22503 Compare August 22, 2025 02:48
@trask trask marked this pull request as ready for review August 22, 2025 03:23
@trask trask requested a review from a team as a code owner August 22, 2025 03:23
Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me.

Java generics strike again..... 🙈

OtlpHttpSpanExporter expectedExporter = OtlpHttpSpanExporter.getDefault();
OtlpHttpSpanExporter expectedExporter =
OtlpHttpSpanExporter.getDefault().toBuilder()
.setComponentLoader(capturingComponentLoader) // needed for the toString() check to pass
Copy link
Contributor

Choose a reason for hiding this comment

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

bummer, but yeah ok.

@jkwatson
Copy link
Contributor

I'm fine with it. Don't know if we want to wait for @jack-berg or ask for forgiveness if he hates the change?

// TODO (jack-berg): consider dynamic configuration use case before stabilizing in case that
// affects any API decisions
T create(DeclarativeConfigProperties config);
Object create(DeclarativeConfigProperties config);
Copy link
Member

Choose a reason for hiding this comment

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

that feels very odd to me - like deliberately defeating the type checker

@zeitlinger
Copy link
Member

I don't think this is a good idea - in makes the API less clear than it is now

@robsunday
Copy link
Contributor

robsunday commented Sep 29, 2025

It is great you attempted to solve this coding issue, however I'd say that old implementation has some important strengths that are missing in new generic-less approach.
I mean - with a new approach there is nothing preventing developers from introducing getType() and create() return type inconsistencies.
With new approach it is possible to declare component provider like this:

public final class ConsoleMetricExporterComponentProvider
    implements ComponentProvider {

  @Override
  public Class<?> getType() {
    return SpanProcessor.class;
  }

  @Override
  public String getName() {
    return "console";
  }

  @Override
  public Object create(DeclarativeConfigProperties config) {
    return LoggingMetricExporter.create();
  }
}

Maybe it's just me, but in my opinion this API becomes somehow "fragile" now.
I know that exception will be thrown at runtime, however I think it is better to add one more annotation to silence some warnings in concrete ComponentProvider implementations.

@brunobat
Copy link
Contributor

This will cause disruption on PPL implementing their own exporters.
Do we really need to do this?

@trask trask closed this Oct 16, 2025
@trask trask deleted the remove-component-provider-generic-type branch October 20, 2025 17:27
@laurit
Copy link
Contributor

laurit commented Oct 28, 2025

I'd support this. In instrumentation repo after changing a module that contains a ComponentProvider build often fails with warning: Service provider io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider is generic, so it can't be named exactly by @AutoService. If this is OK, add @SuppressWarnings("rawtypes"). Which is quite annoying, cleaning the affected module gets the build going again.

@trask trask restored the remove-component-provider-generic-type branch October 28, 2025 16:34
@trask trask reopened this Oct 28, 2025
@trask
Copy link
Member Author

trask commented Oct 28, 2025

@jack-berg @jkwatson reopening because this is two problems now that this generic type is causing for downstream consumers

@trask
Copy link
Member Author

trask commented Nov 4, 2025

I'd support this. In instrumentation repo after changing a module that contains a ComponentProvider build often fails with warning: Service provider io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider is generic, so it can't be named exactly by @AutoService. If this is OK, add @SuppressWarnings("rawtypes"). Which is quite annoying, cleaning the affected module gets the build going again.

ugh, this just bit me today

Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

I don't hate this. Its a bit more error prone than the generic version, but a bit more user friendly because it avoids errors with autoservice tooling. Its weird that autoservice throws this error given how popular generic types are for other common autoservice use cases like DAOs. 🤷

**Sorry wrote this review on 10/28 but apparently forgot to hit the submit button 🤦 **

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to add an additional check here to check if create returns the same type as getType().

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

great - that restores the type safety (even though only at runtime)

@jack-berg jack-berg merged commit de48d1b into open-telemetry:main Nov 6, 2025
29 checks passed
the-clam pushed a commit to the-clam/opentelemetry-java that referenced this pull request Nov 11, 2025
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.

8 participants