Fix/1871 observability boot4 regressions
fix(observability): restore metrics, single span export and sampling under Spring Boot 4
Fixes #1871
Root cause
@ConditionalOnBean / @ConditionalOnMissingBean are evaluated while bean definitions are still being registered, so they depend on auto-configuration ordering. Boot 4 split observability into separate modules and dropped the ordering edges this module implicitly relied on.
Defects fixed
| # | Symptom | Cause | Fix |
|---|---|---|---|
| 1 | No business metrics at all | EmbabelMetricsEventListener gated on @ConditionalOnBean(MeterRegistry), evaluated before Boot's metrics auto-configurations |
@ConditionalOnClass + lazy ObjectProvider<MeterRegistry>, falling back to an empty CompositeMeterRegistry |
| 2 | Every span exported twice | sdkTracerProvider attached Boot's otelSpanProcessor (which already wraps every SpanExporter) and wrapped each exporter again |
Attach exporters only when no SpanProcessor is present |
| 3a | management.tracing.sampling.* ignored |
Boot's Sampler bean was never applied; provider stayed on AlwaysOn |
New embabelSamplerCustomizer applies it |
| 3b | management.tracing.enabled dead but shipped |
Not bound by Boot 4, yet present in agent-application.properties (a main resource imposed on every consumer) |
Removed; test resources and docs moved to management.tracing.export.enabled |
Design change
sdkTracerProvider is now an ordered chain instead of a monolithic method:
SdkTracerProviderBuilder builder = SdkTracerProvider.builder();
customizers.orderedStream().forEach(customizer -> customizer.customize(builder));
return builder.build();
| Bean | Order | Concern |
|---|---|---|
embabelResourceCustomizer |
0 | service identity |
embabelSamplerCustomizer |
100 | sampler |
embabelSpanProcessorCustomizer |
200 | SpanProcessor beans |
embabelSpanExporterCustomizer |
300 | SpanExporter beans |
SdkTracerProviderCustomizer is public - this is the idiom the module already uses for the ObservationRegistry, and it is how an application attaches an exporter that a foreign, non-exporting processor would otherwise swallow. No new configuration key is introduced.
Needs a reviewer decision
-
Full sampling now ships as a platform default. With the sampler honoured, Boot's 10% default would silently discard nine agent traces out of ten, so
agent-application.propertiessetsmanagement.tracing.sampling.probability=1.0. A consumer's ownapplication.propertiesoutranks it. -
One existing test changed meaning.
metricsListener_shouldNotBeCreated_whenNoMeterRegistry→metricsListener_shouldRecordNowhere_whenNoMeterRegistry. The "no registry, no listener" behaviour is deliberately gone: that condition cannot be evaluated reliably.
Testing
BootObservabilityInteropTest assembles Boot's real auto-configurations alongside Embabel's. The pre-existing metrics test passes today while the listener does not exist in production, because it supplies the MeterRegistry via withUserConfiguration — always registered first, hiding the ordering sensitivity.
Each new test failed before the fix:
| Test | Failure before |
|---|---|
metricsListener_shouldBeCreated_whenBootContributesTheMeterRegistry |
registry present, listener absent |
span_shouldReachEachExporterExactlyOnce |
Expected size: 1 but was: 2 |
span_shouldNotBeExported_whenSamplingProbabilityIsZero |
2 spans exported at probability=0.0 |
shipped properties declare no key that Spring Boot 4 no longer binds |
dead key present |
Two more pin the delegation rule and its escape hatch:
exporter_shouldBeSkipped_whenAnotherProcessorIsPresent and
exporter_shouldBeReached_whenApplicationContributesItsOwnCustomizer.
spring-boot-micrometer-tracing-opentelemetry and spring-boot-micrometer-metrics are added at
test scope - only the starter carried them, so the composition with Boot was structurally
untestable, which is how these regressions shipped.
Results: observability + auto-configure 311 tests green · embabel-agent-api 3961 tests green ·
embabel-agent-starter-observability builds clean.
Documentation
README.md, embabel-agent-observability/README.md and reference/integrations/page.adoc updated
for management.tracing.export.enabled.