Skip to content

Conversation

zeitlinger
Copy link
Member

Fixes #7435

@zeitlinger zeitlinger requested a review from a team as a code owner July 8, 2025 14:48
@zeitlinger zeitlinger self-assigned this Jul 8, 2025
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.01%. Comparing base (5186238) to head (6506694).
Report is 16 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7475      +/-   ##
============================================
+ Coverage     89.82%   90.01%   +0.19%     
- Complexity     6999     7082      +83     
============================================
  Files           798      803       +5     
  Lines         21199    21414     +215     
  Branches       2055     2088      +33     
============================================
+ Hits          19042    19276     +234     
+ Misses         1496     1476      -20     
- Partials        661      662       +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.

@zeitlinger
Copy link
Member Author

@jack-berg please have a look 😄

@@ -47,6 +48,11 @@ public SpanProcessor create(SpanProcessorModel model, DeclarativeConfigContext c
if (batchModel.getScheduleDelay() != null) {
builder.setScheduleDelay(Duration.ofMillis(batchModel.getScheduleDelay()));
}
MeterProvider meterProvider = context.getMeterProvider();
if (meterProvider != null) {
builder.setMeterProvider(meterProvider);
Copy link
Member

Choose a reason for hiding this comment

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

This partially solves the problem, but we still won't get the internal exporter telemetry.

The way we solve this in autoconfigure today is with the AutoConfigureListener. SDK components which are loaded via SPI and which report internal telemetry implement AutoConfigureListener and get a callback to update MeterProvider after OpenTelemetrySdk has been initialized. For example, see OtlpSpanExporterProvider.

I think what you've done here does work for SDK components which report internal telemetry and which are NOT loaded via SPI.

Copy link
Member Author

Choose a reason for hiding this comment

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

That SPI would implement create and can just take the meter provider from DeclarativeConfigContext IIUC.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the SPI guaranteed to be run on the same thread that set the value onto the context? If not, then we will need a memory barrier on the setting of the value into the context, I think.

}

public void setMeterProvider(MeterProvider meterProvider) {
this.meterProvider = meterProvider;
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance this needs to be cross-thread safe? In which case, putting a memory barrier around the assignment would be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

no, this doesn't need to be thread safe - it belongs to the set up logic that is done in a single thread at the start

.create(model.getMeterProvider(), context)
.setResource(resource)
.build();
context.setMeterProvider(meterProvider);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be less error prone if context.setMeterProvider call addCloseable internally.
Then builder.setMeterProvider(context.addCloseable(meterProvider)); could be just: builder.setMeterProvider(meterProvider); and we would be guaranteed that meterProvider will always be closed.

Copy link
Member Author

Choose a reason for hiding this comment

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

it would work if we change the parameter type to SdkMeterProvider - but it would be harder to understand why the closeable logic is hidden here, but not for tracer and logger

@@ -77,15 +88,6 @@ public OpenTelemetrySdk create(
.build()));
}

if (model.getMeterProvider() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there any reason to move this code block upper? If not then it leaving it in the same place would make changes analysis a bit simpler.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, the meter provider is taken out of the context for logger and tracer

@zeitlinger
Copy link
Member Author

@robsunday @jkwatson please check again

1 similar comment
@zeitlinger
Copy link
Member Author

@robsunday @jkwatson please check again

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.

Internal telemetry always uses GlobalOpenTelemetry when declarative config is used
4 participants