opentelemetry-php icon indicating copy to clipboard operation
opentelemetry-php copied to clipboard

feat: Add Apache and FPM resource detectors with stable service instance IDs

Open cedricziel opened this issue 6 months ago • 6 comments

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.

cedricziel avatar Jun 11 '25 10:06 cedricziel

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.

cedricziel avatar Jun 11 '25 10:06 cedricziel

maybe related: https://github.com/open-telemetry/opentelemetry-php/issues/1489

JoniJnm avatar Jun 11 '25 12:06 JoniJnm

definitely related. - this detector should always be included and always be progressively overriden if possible.

cedricziel avatar Jun 11 '25 12:06 cedricziel

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.

stale[bot] avatar Jul 19 '25 04:07 stale[bot]

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.

Thomas-Vos00 avatar Oct 01 '25 20:10 Thomas-Vos00

@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.

brettmc avatar Oct 02 '25 03:10 brettmc