feat: Add Apache and FPM resource detectors with stable service instance IDs
This resolves high-cardinality issues in metrics by providing stable service instance IDs for Apache and FPM environments instead of random UUIDs that change on process restart.
Features:
- Apache detector: Generates stable IDs using server name + hostname + document root
- FPM detector: Generates stable IDs using pool name + hostname
- Cascading detection: Service UUID → Runtime-specific stable ID → User override
- Proper precedence: OTEL_SERVICE_NAME takes priority over OTEL_RESOURCE_ATTRIBUTES
Implementation:
- Added detector classes in src/SDK/Resource/Detectors/
- Added component providers for configuration system
- Registered detectors in SPI system and known values
- Updated ResourceInfoFactory with correct precedence order
- Comprehensive test coverage for unit and integration scenarios
The detectors only activate in their respective environments (apache2handler/fmp-fcgi SAPI) and return empty resources otherwise, allowing clean fallback behavior.
Note to reviewers: The remaining issues are in unreleated code.
About this PR: the issue is that systems that generate metrics from traces usually need an instance label. The uuid per process is an issue here as one uuid per spawned process would be set. we could use apcu to create even longer-running stable ids.
maybe related: https://github.com/open-telemetry/opentelemetry-php/issues/1489
definitely related. - this detector should always be included and always be progressively overriden if possible.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any updates on this? This would solve my issue where im using the new file based configuration in a phpfpm production setup. With the file based configuration the "service" resource discovery is mandatory, there is currently no way to override this instance id.
@cedricziel I hope you don't mind, I've ported these detectors over to contrib in https://github.com/open-telemetry/opentelemetry-php-contrib/pull/444 I've also merged the change to move service.instance.id into its own (non-default) detector to try to un-break service instance id. I plan to get the basic detectors in and published, then follow up with the component provider part.