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

[opentelemetry-php-contrib] _register.php scripts + composer autoload issues

Open petrisorciprian-vitals opened this issue 8 months ago • 5 comments

Hi,

I realize this is a bit of an awkward one, but I'm having some issues with the instrumentation still being loaded, even though the SDK is not explicitly enabled.

I believe all _register.php scripts should check if the SDK is enabled via OTEL_SDK_DISABLED env, and if not, exit without registering any hooks.

As it is, any other tool/process that may include vendor/autoload.php, generated by Composer, ends up also invoking the _register.php methods, and since the instrumentation is not explicitly disabled for a package, it ends up registering the hooks.

An example of such a tool is grumphp.

Is there a reason we need to register the instrumentation hooks even when the OTEL_SDK_DISABLED is not configured or set to true? If not, an easy fix would be to make all _register.php files also check via Sdk::isDisabled and early exit. Another option is to have Sdk::isInstrumentationDisabled always return true if the SDK is disabled (although this seems like the worse solution).

https://github.com/open-telemetry/opentelemetry-php/blob/8316c50e9371a94908b77a0deb7bc8277f835f87/src/SDK/Sdk.php#L36-L41

petrisorciprian-vitals avatar Feb 14 '25 13:02 petrisorciprian-vitals