|  | 
|  | 1 | +[](https://github.com/opentelemetry-php/contrib-auto-opcache/releases) | 
|  | 2 | +[](https://github.com/open-telemetry/opentelemetry-php/issues) | 
|  | 3 | +[](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/PhpOpcache) | 
|  | 4 | +[](https://github.com/opentelemetry-php/contrib-auto-opcache) | 
|  | 5 | +[](https://packagist.org/packages/open-telemetry/opentelemetry-auto-opcache/) | 
|  | 6 | +[](https://packagist.org/packages/open-telemetry/opentelemetry-auto-opcache/) | 
|  | 7 | + | 
|  | 8 | +This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib. | 
|  | 9 | + | 
|  | 10 | +# OpenTelemetry PHP OPcache Instrumentation | 
|  | 11 | + | 
|  | 12 | +Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to | 
|  | 13 | +install and configure the extension and SDK. | 
|  | 14 | + | 
|  | 15 | +## Overview | 
|  | 16 | + | 
|  | 17 | +This instrumentation package captures PHP OPcache metrics and adds them as attributes to the active span. | 
|  | 18 | +It automatically registers a shutdown function to collect OPcache metrics at the end of the request. | 
|  | 19 | + | 
|  | 20 | +The following OPcache metrics are captured: | 
|  | 21 | + | 
|  | 22 | +### Basic Status | 
|  | 23 | +- `opcache.enabled` - Whether OPcache is enabled | 
|  | 24 | +- `opcache.available` - Whether OPcache is available | 
|  | 25 | + | 
|  | 26 | +### Memory Usage | 
|  | 27 | +- `opcache.memory.used_bytes` - Memory used by OPcache in bytes | 
|  | 28 | +- `opcache.memory.free_bytes` - Free memory available to OPcache in bytes | 
|  | 29 | +- `opcache.memory.wasted_bytes` - Wasted memory in bytes | 
|  | 30 | +- `opcache.memory.used_percentage` - Percentage of total memory used | 
|  | 31 | +- `opcache.memory.wasted_percentage` - Percentage of total memory wasted | 
|  | 32 | + | 
|  | 33 | +### Cache Statistics | 
|  | 34 | +- `opcache.scripts.cached` - Number of cached scripts | 
|  | 35 | +- `opcache.hits.total` - Total number of cache hits | 
|  | 36 | +- `opcache.misses.total` - Total number of cache misses | 
|  | 37 | +- `opcache.hit_rate.percentage` - Cache hit rate percentage | 
|  | 38 | +- `opcache.keys.cached` - Number of cached keys | 
|  | 39 | +- `opcache.keys.max_cached` - Maximum number of cached keys | 
|  | 40 | + | 
|  | 41 | +### Restart Statistics | 
|  | 42 | +- `opcache.restarts.oom` - Number of out-of-memory restarts | 
|  | 43 | +- `opcache.restarts.hash` - Number of hash restarts | 
|  | 44 | +- `opcache.restarts.manual` - Number of manual restarts | 
|  | 45 | + | 
|  | 46 | +### Interned Strings | 
|  | 47 | +- `opcache.interned_strings.buffer_size` - Interned strings buffer size | 
|  | 48 | +- `opcache.interned_strings.used_memory` - Memory used by interned strings | 
|  | 49 | +- `opcache.interned_strings.free_memory` - Free memory for interned strings | 
|  | 50 | +- `opcache.interned_strings.strings_count` - Number of interned strings | 
|  | 51 | +- `opcache.interned_strings.usage_percentage` - Percentage of interned strings buffer used | 
|  | 52 | + | 
|  | 53 | +## Usage | 
|  | 54 | + | 
|  | 55 | +The instrumentation is automatically registered via composer. No additional configuration is required. | 
|  | 56 | + | 
|  | 57 | +You can also manually add OPcache metrics to the current active span: | 
|  | 58 | + | 
|  | 59 | +```php | 
|  | 60 | +use OpenTelemetry\Contrib\Instrumentation\PhpOpcache\PhpOpcacheInstrumentation; | 
|  | 61 | + | 
|  | 62 | +// Add OPcache metrics to the current active span | 
|  | 63 | +PhpOpcacheInstrumentation::addOpcacheMetricsToRootSpan(); | 
|  | 64 | +``` | 
|  | 65 | + | 
|  | 66 | +## Configuration | 
|  | 67 | + | 
|  | 68 | +The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration): | 
|  | 69 | + | 
|  | 70 | +```shell | 
|  | 71 | +OTEL_PHP_DISABLED_INSTRUMENTATIONS=opcache | 
|  | 72 | +``` | 
|  | 73 | + | 
|  | 74 | +## Requirements | 
|  | 75 | + | 
|  | 76 | +- PHP 8.0 or higher | 
|  | 77 | +- OPcache extension | 
|  | 78 | +- OpenTelemetry extension | 
0 commit comments