Skip to content

Conversation

HeenaBansal20
Copy link
Contributor

@HeenaBansal20 HeenaBansal20 commented Sep 16, 2025

This PR adds opcache instrumentation.

@HeenaBansal20 HeenaBansal20 requested a review from a team as a code owner September 16, 2025 17:15
@HeenaBansal20 HeenaBansal20 force-pushed the feature/add-opcache-instrumentation branch from e3d01c3 to bfdb728 Compare September 16, 2025 17:18
Copy link

codecov bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.90%. Comparing base (c876789) to head (8bb376b).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main     #440   +/-   ##
=========================================
  Coverage     81.90%   81.90%           
  Complexity     1988     1988           
=========================================
  Files           137      137           
  Lines          8096     8096           
=========================================
  Hits           6631     6631           
  Misses         1465     1465           
Flag Coverage Δ
Aws 93.41% <ø> (ø)
Context/Swoole 0.00% <ø> (ø)
Exporter/Instana 49.42% <ø> (ø)
Instrumentation/AwsSdk 81.13% <ø> (ø)
Instrumentation/CakePHP 20.40% <ø> (ø)
Instrumentation/CodeIgniter 73.98% <ø> (ø)
Instrumentation/Curl 87.66% <ø> (ø)
Instrumentation/Doctrine 92.92% <ø> (ø)
Instrumentation/ExtAmqp 88.48% <ø> (ø)
Instrumentation/ExtRdKafka 86.11% <ø> (ø)
Instrumentation/Guzzle 75.58% <ø> (ø)
Instrumentation/HttpAsyncClient 78.04% <ø> (ø)
Instrumentation/IO 0.00% <ø> (ø)
Instrumentation/Laravel 70.97% <ø> (ø)
Instrumentation/MySqli 95.81% <ø> (ø)
Instrumentation/OpenAIPHP 87.21% <ø> (ø)
Instrumentation/PDO 94.21% <ø> (ø)
Instrumentation/PostgreSql 93.54% <ø> (ø)
Instrumentation/Psr14 76.47% <ø> (ø)
Instrumentation/Psr15 89.15% <ø> (ø)
Instrumentation/Psr16 97.50% <ø> (ø)
Instrumentation/Psr18 77.46% <ø> (ø)
Instrumentation/Psr3 67.01% <ø> (ø)
Instrumentation/Psr6 97.61% <ø> (ø)
Instrumentation/ReactPHP 99.45% <ø> (ø)
Instrumentation/Session 94.52% <ø> (ø)
Instrumentation/Slim 86.11% <ø> (ø)
Instrumentation/Symfony 84.88% <ø> (ø)
Instrumentation/Yii 77.86% <ø> (ø)
Logs/Monolog 100.00% <ø> (ø)
Propagation/CloudTrace 89.77% <ø> (ø)
Propagation/Instana 98.11% <ø> (ø)
Propagation/ServerTiming 100.00% <ø> (ø)
Propagation/TraceResponse 100.00% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/Container 93.02% <ø> (ø)
ResourceDetectors/DigitalOcean 100.00% <ø> (ø)
Sampler/RuleBased 33.51% <ø> (ø)
Sampler/Xray 78.23% <ø> (ø)
Shims/OpenTracing 92.45% <ø> (ø)
Utils/Test 87.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c876789...8bb376b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HeenaBansal20 HeenaBansal20 force-pushed the feature/add-opcache-instrumentation branch 2 times, most recently from 7568b33 to d4b484e Compare September 16, 2025 18:49
@HeenaBansal20 HeenaBansal20 force-pushed the feature/add-opcache-instrumentation branch from 45eb208 to 8bb376b Compare September 16, 2025 18:54
@HeenaBansal20
Copy link
Contributor Author

@brettmc , GitHub actions is not triggering CI for Opcache project , However I am able to run it locally.


PROJECT=Instrumentation/Opcache  PHP_VERSION=8.3 make all
docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off composer update --no-plugins
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
75 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no -vvv
Setting PHP_CS_FIXER_IGNORE_ENV environment variable is deprecated and will be removed in 4.0, use unsupportedPhpVersionAllowed config instead.
PHP CS Fixer 3.87.2 Alexander by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.23
Running analysis on 1 core sequentially.
Loaded config default from ".php-cs-fixer.php".
 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


Fixed 0 of 3 files in 0.113 seconds, 8.00 MB memory used
docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off composer validate --no-plugins
./composer.json is valid
docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off env PHAN_DISABLE_XDEBUG_WARN=1 vendor/bin/phan
[debug] Checking PHAN_ALLOW_XDEBUG
[debug] Because xdebug was installed, Phan will restart.
[debug] The Xdebug extension is loaded (3.4.4) xdebug.mode=off
[debug] Process restarting (PHAN_ALLOW_XDEBUG=internal|3.4.4|1|*|*)
[debug] Running: [/usr/bin/php8.3, -n, -c, /tmp/AFZchh, vendor/bin/phan]
Phan did not parse any files in the project "/usr/src/myapp/src/Instrumentation/Opcache" - This may be an issue with the Phan config or CLI options.
[debug] Restarted process exited 0█████████████████████████████████████ 100.0% 15MB/15MB
docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off vendor/bin/psalm --threads=1 --no-cache --php-version=8.3

JIT acceleration: ON

Target PHP version: 8.3 (set by CLI argument) (unsupported extensions: opentelemetry, zend-opcache).

Scanning files...

780 / 780...

Analyzing files...

░░

------------------------------
                              
       No errors found!       
                              
------------------------------
5 other issues found.
You can display them with --show-info=true
------------------------------

Checks took 3.53 seconds and used 99.453MB of memory
Psalm was able to infer types for 79.7048% of the codebase
docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off vendor/bin/phpstan analyse --memory-limit=256M
Note: Using configuration file /usr/src/myapp/src/Instrumentation/Opcache/phpstan.neon.dist.
 2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

docker compose run --rm -w /usr/src/myapp/src/Instrumentation/Opcache php env XDEBUG_MODE=off vendor/bin/phpunit --testdox --colors=always
PHPUnit 9.6.27 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.23
Configuration: /usr/src/myapp/src/Instrumentation/Opcache/phpunit.xml.dist

Opcache Instrumentation (OpenTelemetry\Tests\Instrumentation\opcache\tests\Integration\OpcacheInstrumentation)
 ✔ Add opcache metrics to root span  46 ms
 ✔ Capture opcache metrics  1 ms

Time: 00:00.049, Memory: 4.00 MB

OK (2 tests, 18 assertions)

}

if (extension_loaded('opentelemetry') === false) {
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry IO auto-instrumentation', E_USER_WARNING);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry IO auto-instrumentation', E_USER_WARNING);
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry opcache auto-instrumentation', E_USER_WARNING);


// Register our own shutdown function to capture OPcache metrics
// register_shutdown_function([self::class, 'captureMetricsOnShutdown']);
register_shutdown_function('OpenTelemetry\Contrib\Instrumentation\opcache\opcacheInstrumentation::addOpcacheMetricsToRootSpan');
Copy link
Contributor

@brettmc brettmc Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this actually work? there's no guarantee that there is an active span during shutdown (I feel it's likely that there is not one), and also if there was an active span there's no guarantee that it's the root span. We do have an API method that would help, LocalRootSpan::current() however I think you need to re-think when this runs.
Perhaps a completely different approach where it emits metrics rather than attaching metric-like values to a span? You could do it with async/observable instruments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettmc , yeah I think you are right. we can take this up as a completely different way it emits metrics than span attributes.
I'll rework on this PR.
Thanks for the suggestion.

php-version: 8.1
- project: 'Instrumentation/PostgreSql'
php-version: 8.1
- project: 'Instrumentation/Opcache'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line excludes all versions. Since you're not actually hooking methods, you can just remove this line since it should work against 8.1

Suggested change
- project: 'Instrumentation/Opcache'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants