Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentelemetry-php-contrib] Auto-instrumentation packages are loaded even when OTEL_PHP_AUTOLOAD_ENABLED=false #1206

Closed
joaojacome opened this issue Jan 8, 2024 · 19 comments
Labels
bug Something isn't working

Comments

@joaojacome
Copy link
Contributor

Describe your environment

Package Version
php 8.2
open-telemetry/opentelemetry-auto-http-async ^0.0.7
open-telemetry/opentelemetry-auto-pdo ^0.0.11
open-telemetry/opentelemetry-auto-psr3 ^0.0.5
open-telemetry/opentelemetry-auto-psr18 ^1.0
open-telemetry/opentelemetry-auto-symfony 1.0.0beta21

Steps to reproduce

  1. install any of the auto instrumentation packages
  2. disable the opentelemetry extension
  3. run echo "require('vendor/autoload.php');" | OTEL_PHP_AUTOLOAD_ENABLED=false php -a

What is the expected behavior?
I'd expect the auto instrumentation packages to be ignored.

What is the actual behavior?
The auto instrumentation packages are loaded, and you'll see a PHP warning:

PHP Warning:  The opentelemetry extension must be loaded in order to autoload the OpenTelemetry HTTPlug async auto-instrumentation in /app/vendor/open-telemetry/opentelemetry-auto-http-async/_register.php on line 13
PHP Warning:  The opentelemetry extension must be loaded in order to autoload the OpenTelemetry PDO auto-instrumentation in /app/vendor/open-telemetry/opentelemetry-auto-pdo/_register.php on line 13
PHP Warning:  The opentelemetry extension must be loaded in order to autoload the OpenTelemetry PSR-3 auto-instrumentation in /app/vendor/open-telemetry/opentelemetry-auto-psr3/_register.php on line 13
PHP Warning:  The opentelemetry extension must be loaded in order to autoload the OpenTelemetry PSR-18 auto-instrumentation in /app/vendor/open-telemetry/opentelemetry-auto-psr18/_register.php on line 13
PHP Warning:  The opentelemetry extension must be loaded in order to autoload the OpenTelemetry Symfony auto-instrumentation in /app/vendor/open-telemetry/opentelemetry-auto-symfony/_register.php on line 15
@joaojacome joaojacome added the bug Something isn't working label Jan 8, 2024
@bobstrecansky
Copy link
Collaborator

What method are you using to disable the opentelemetry extension?

@joaojacome
Copy link
Contributor Author

I'm removing the extension .ini file from PHP config paths.

I've pushed a small reproducer here: https://github.com/joaojacome/otel-auto-reproducer

You can reproduce it with docker compose run without-extension-autoload-disabled

@brettmc
Copy link
Collaborator

brettmc commented Jan 8, 2024

That env var only controls SDK autoloading (setting up an SDK from environment variables). That said, SDK autoloading is a requirement for auto-instrumentation to work (or if not that, then some other thing that configures and registers an SDK as part of composer's autoloader).
It sounds reasonable that OTEL_PHP_AUTOLOAD_ENABLED could also disable auto-instrumentations...

@joaojacome
Copy link
Contributor Author

joaojacome commented Jan 8, 2024 via email

@joaojacome
Copy link
Contributor Author

joaojacome commented Jan 9, 2024

I've pushed a PR with the SDK changes - the idea is to expose the OTEL_PHP_AUTOLOAD_ENABLED value on the SDK, and use it whenever an auto-instrumentation packages is loaded.

Example for the PSR18 package:

@@ -1,18 +1,21 @@
 <?php
 
 declare(strict_types=1);
 
 use OpenTelemetry\Contrib\Instrumentation\Psr18\Psr18Instrumentation;
 use OpenTelemetry\SDK\Sdk;
 
-if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(Psr18Instrumentation::NAME) === true) {
+if (class_exists(Sdk::class) && (
+    Sdk::isInstrumentationDisabled(Psr18Instrumentation::NAME) === true
+    || Sdk::isAutoloadEnabled() === false
+)) {
     return;
 }
 
 if (extension_loaded('opentelemetry') === false) {
     trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry PSR-18 auto-instrumentation', E_USER_WARNING);
 
     return;
 }
 
 Psr18Instrumentation::register();

Another approach would be to have an isAutoInstrumentationDisabled method, that would check both disabled instrumentations and the autoload. That would simplify the check a bit.

If the PR is approved, I'll follow up with a PR for updating the auto-instrumentation packages.

@brettmc
Copy link
Collaborator

brettmc commented Jan 9, 2024

I think this is the same issue as #1191

Thinking about it more, I don't think disabling the package based on whether autoload is enabled or not is correct; they're not the same thing and while it's true today that they're strongly coupled, I can imagine somebody writing their own SDK loader that runs via composer's autoload.files rather than using our autoloading functionality.

I asked in the linked issue what would happen if we made the error less dramatic (error_log instead of trigger_error) - which might achieve our aim of letting users know when they've done something wrong whilst making your issue less bad? Could you try that out?

@joaojacome
Copy link
Contributor Author

joaojacome commented Jan 9, 2024

It looks like its the same, yes.

The reason I opened this wasn't really the warnings themselves, but rather that I'm facing some segmantation faults when running tests with the opentelemetry extension enabled.

When mocking a PSR18 ClientInterface the process is hanging after loading open telemetry packages.

Sample strace (collapsed) ```
access("/app/vendor/composer/../open-telemetry/api/Trace/NoopSpanBuilder.php", F_OK) = 0
lstat("/app/vendor/composer/../open-telemetry/api/Trace/NoopSpanBuilder.php", {st_mode=S_IFREG|0644, st_size=1579, ...}) = 0
open("/app/vendor/open-telemetry/api/Trace/NoopSpanBuilder.php", O_RDONLY|O_LARGEFILE) = 6
fstat(6, {st_mode=S_IFREG|0644, st_size=1579, ...}) = 0
read(6, "<?php\n\ndeclare(strict_types=1);\n"..., 1579) = 1579
close(6)                                = 0
access("/app/vendor/composer/../open-telemetry/api/Trace/SpanBuilderInterface.php", F_OK) = 0
lstat("/app/vendor/composer/../open-telemetry/api/Trace/SpanBuilderInterface.php", {st_mode=S_IFREG|0644, st_size=1861, ...}) = 0
open("/app/vendor/open-telemetry/api/Trace/SpanBuilderInterface.php", O_RDONLY|O_LARGEFILE) = 6
fstat(6, {st_mode=S_IFREG|0644, st_size=1861, ...}) = 0
read(6, "<?php\n\ndeclare(strict_types=1);\n"..., 1861) = 1861
close(6)                                = 0
access("/app/vendor/composer/../open-telemetry/api/Trace/SpanKind.php", F_OK) = 0
lstat("/app/vendor/composer/../open-telemetry/api/Trace/SpanKind.php", {st_mode=S_IFREG|0644, st_size=394, ...}) = 0
open("/app/vendor/open-telemetry/api/Trace/SpanKind.php", O_RDONLY|O_LARGEFILE) = 6
fstat(6, {st_mode=S_IFREG|0644, st_size=394, ...}) = 0
read(6, "<?php\n\ndeclare(strict_types=1);\n"..., 394) = 394
close(6)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db5000
munmap(0x7fc0e0db5000, 4096)            = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d8e000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d8c000
munmap(0x7fc0e0d8e000, 16384)           = 0
munmap(0x7fc0e0d8c000, 8192)            = 0
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d8a000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db5000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
munmap(0x7fc0e0db5000, 4096)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d86000
munmap(0x7fc0e0d8a000, 32768)           = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
mmap(NULL, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d8d000
munmap(0x7fc0e0d86000, 16384)           = 0
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
select(5, [4], NULL, NULL, {tv_sec=0, tv_usec=0}) = 0 (Timeout)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db5000
munmap(0x7fc0e0db5000, 4096)            = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d89000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d87000
munmap(0x7fc0e0d89000, 16384)           = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d8b000
munmap(0x7fc0e0d87000, 8192)            = 0
munmap(0x7fc0e0d8b000, 8192)            = 0
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d85000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db5000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
munmap(0x7fc0e0db5000, 4096)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d81000
munmap(0x7fc0e0d85000, 32768)           = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
mmap(NULL, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0d88000
munmap(0x7fc0e0d81000, 16384)           = 0
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0e0db1000
munmap(0x7fc0e0db1000, 8192)            = 0
munmap(0x7fc0e0d8d000, 20480)           = 0
```

Somehow that issue is gone if I update psr/http-message from 1.1 to 2.0.

Given that there's no reason (at least for me) to have auto-instrumentation enabled on unit tests, I could disable the extension (and get the warnings), or set the OTEL_PHP_DISABLED_INSTRUMENTATIONS=psr18 before running the tests.

Of course, that's not a big deal, but if we had an easy way of "fully disable open-telemetry auto-instrumentation", I'd rather use that.

@brettmc
Copy link
Collaborator

brettmc commented Jan 10, 2024

if we had an easy way of "fully disable open-telemetry auto-instrumentation", I'd rather use that.

How about OTEL_PHP_DISABLED_INSTRUMENTATIONS=all ? (which doesn't currently exist, but would be easy to implement)

@brettmc
Copy link
Collaborator

brettmc commented Jan 10, 2024

When mocking a PSR18 ClientInterface the process is hanging after loading open telemetry packages.

I've seen something similar this week, and it was due to the type-hint for pre/post hook being incompatible with the actual type. Just as a test, you could remove the type-hints and see if your error goes away. If so, it could be that the mocked object's type isn't quite what the pre or post hook expects. There may be a bug in the extension we need to understand and fix, there's certainly a semi-related issue logged...

@joaojacome
Copy link
Contributor Author

How about OTEL_PHP_DISABLED_INSTRUMENTATIONS=all ? (which doesn't currently exist, but would be easy to implement)

That would be perfect. I'll give the implementation a go here.

I've seen something similar this week, and it was due to the type-hint for pre/post hook being incompatible with the actual type. Just as a test, you could remove the type-hints and see if your error goes away. If so, it could be that the mocked object's type isn't quite what the pre or post hook expects. There may be a bug in the extension we need to understand and fix, there's certainly a semi-related issue logged...

It seems to be the case. I've removed a few type-hints on psr/http-message and I managed to reproduce it. I guess open-telemetry/opentelemetry-auto-psr18 should be updated to reflect this requirement. I couldn't find a related issue to link to this one here.

@brettmc
Copy link
Collaborator

brettmc commented Jan 22, 2024

I couldn't find a related issue to link to this one here.

I think it could be fixed by open-telemetry/opentelemetry-php-instrumentation#118

@brettmc
Copy link
Collaborator

brettmc commented Jan 22, 2024

@joaojacome Added a test which I think confirms that your bug fails nicely rather than hang with the just-merged fix: open-telemetry/opentelemetry-php-instrumentation#119
Once that test gets merged, I'll push out a beta release for you to confirm.

I guess open-telemetry/opentelemetry-auto-psr18 should be updated to reflect this requirement.

Can you create a new issue for this?

@joaojacome
Copy link
Contributor Author

How about OTEL_PHP_DISABLED_INSTRUMENTATIONS=all ? (which doesn't currently exist, but would be easy to implement)

#1220 PR adding the option

I'll follow up with a PR for the docs too.

Can you create a new issue for this?

Is that necessary even with the hook exception handling fix?

@brettmc
Copy link
Collaborator

brettmc commented Jan 24, 2024

Is that necessary even with the hook exception handling fix?

Maybe not. I wasn't clear on whether you thought there was an actual bug in opentelemetry-auto-psr18 or not. If the only fix required is in the extension, then nothing further needed except to verify.

@joaojacome
Copy link
Contributor Author

Maybe not. I wasn't clear on whether you thought there was an actual bug in opentelemetry-auto-psr18 or not. If the only fix required is in the extension, then nothing further needed except to verify.

Given that the psr18 auto-instrumentation package requires psr/http-message:"^1.0" , with the extension hook fix you won't have the application crashing, but you would still need to deal with the new warnings, right? Considering that, I think that it might be better to change the requirement to ^2.0.


About the OTEL_PHP_DISABLED_INSTRUMENTATIONS=all, I've submitted a PR for the docs here: open-telemetry/opentelemetry.io#3864

Thanks!

@brettmc
Copy link
Collaborator

brettmc commented Jan 27, 2024

I couldn't reproduce (what I think is) your issue with a test, using psr/http-message 1.1 and extension 1.0.1beta1

Drop this into Integration/Psr18InstrumentationTest.php and let me know what you think:

public function test_send_mock_request(): void
    {
        $request = $this->createMock(RequestInterface::class);
        $uri = $this->createMock(UriInterface::class);
        $request->method('getUri')->willReturn($uri);
        $request->method('withoutHeader')->willReturnSelf();
        $request->method('withAddedHeader')->willReturnSelf();
        $this->client->sendRequest($request);
    }

It doesn't fail, but did whilst I worked out those willReturnSelf bits - could that be the problem? phpunit is smart enough to automagically return something useful if the return types are type-hinted a-la psr/http-message 2.0 ?

@brettmc
Copy link
Collaborator

brettmc commented Jan 29, 2024

Update: with the just-released extension 1.0.1beta2, now if I break the above test it fails as expected and more helpfully:
Warning: Mock_ClientInterface_032c23a5::sendRequest(): OpenTelemetry: pre hook threw exception, class=Mock_ClientInterface_032c23a5 function=sendRequest message=Call to a member function withoutHeader() on null in Unknown on line 0

Could you please re-test, @joaojacome ?

@brettmc
Copy link
Collaborator

brettmc commented Feb 6, 2024

Closing, as the original issue is resolved, and I'm pretty confident the extra issue (hanging whilst mocking) is also fixed in the latest version of the extension.

@brettmc brettmc closed this as completed Feb 6, 2024
@joaojacome
Copy link
Contributor Author

All working good now :)

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants