Skip to content

Commit 7568b33

Browse files
committed
Add opcache instrumentation
1 parent fec51f9 commit 7568b33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3549
-7
lines changed

.github/workflows/fossa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fossa:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1616

1717
- uses: fossas/fossa-action@3ebcea1862c6ffbd5cf1b4d0bd6b3fe7bd6f2cac # v1.7.0
1818
with:

.github/workflows/ossf-scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
# Needed for GitHub OIDC token if publish_results is true
2020
id-token: write
2121
steps:
22-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2323
with:
2424
persist-credentials: false
2525

@@ -45,6 +45,6 @@ jobs:
4545
# Upload the results to GitHub's code scanning dashboard (optional).
4646
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
4747
- name: "Upload to code-scanning"
48-
uses: github/codeql-action/upload-sarif@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
48+
uses: github/codeql-action/upload-sarif@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3.29.5
4949
with:
5050
sarif_file: results.sarif

.github/workflows/php.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
'Instrumentation/MySqli',
4242
'Instrumentation/OpenAIPHP',
4343
'Instrumentation/PDO',
44+
'Instrumentation/Opcache',
4445
'Instrumentation/PostgreSql',
4546
# Sort PSRs numerically.
4647
'Instrumentation/Psr3',
@@ -50,6 +51,7 @@ jobs:
5051
'Instrumentation/Psr16',
5152
'Instrumentation/Psr18',
5253
'Instrumentation/ReactPHP',
54+
'Instrumentation/Session',
5355
'Instrumentation/Slim',
5456
'Instrumentation/Symfony',
5557
'Instrumentation/Yii',
@@ -62,6 +64,7 @@ jobs:
6264
'ResourceDetectors/Container',
6365
'ResourceDetectors/DigitalOcean',
6466
'Sampler/RuleBased',
67+
'Sampler/Xray',
6568
'Shims/OpenTracing',
6669
'Symfony',
6770
'Utils/Test'
@@ -82,8 +85,11 @@ jobs:
8285
php-version: 8.1
8386
- project: 'Instrumentation/PostgreSql'
8487
php-version: 8.1
88+
- project: 'Instrumentation/Opcache'
89+
- project: 'Instrumentation/Session'
90+
php-version: 8.1
8591
steps:
86-
- uses: actions/checkout@v4
92+
- uses: actions/checkout@v5
8793

8894
- name: Setup PHP
8995
uses: shivammathur/setup-php@v2

.github/workflows/update-dependabot-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: Checkout code
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v5
2222

2323
- name: Set up PHP
2424
uses: shivammathur/setup-php@v2

.gitsplit.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ splits:
4444
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-openai.git"
4545
- prefix: "src/Instrumentation/PDO"
4646
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-pdo.git"
47+
- prefix: "src/Instrumentation/opcache"
48+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-opcache.git"
4749
- prefix: "src/Instrumentation/PostgreSql"
4850
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-postgresql.git"
4951
- prefix: "src/Instrumentation/Psr3"
@@ -60,6 +62,8 @@ splits:
6062
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-psr18.git"
6163
- prefix: "src/Instrumentation/ReactPHP"
6264
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-reactphp.git"
65+
- prefix: "src/Instrumentation/Session"
66+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-session.git"
6367
- prefix: "src/Instrumentation/Slim"
6468
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-slim.git"
6569
- prefix: "src/Instrumentation/Symfony"
@@ -88,6 +92,8 @@ splits:
8892
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-detector-digitalocean.git"
8993
- prefix: "src/Sampler/RuleBased"
9094
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sampler-rulebased.git"
95+
- prefix: "src/Sampler/Xray"
96+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sampler-aws-xray.git"
9197
- prefix: "src/Shims/OpenTracing"
9298
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-shim-opentracing.git"
9399
- prefix: "src/Symfony"

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
"OpenTelemetry\\Contrib\\Instrumentation\\MySqli\\": "src/Instrumentation/MySqli/src",
3434
"OpenTelemetry\\Contrib\\Instrumentation\\OpenAIPHP\\": "src/Instrumentation/OpenAIPHP/src",
3535
"OpenTelemetry\\Contrib\\Instrumentation\\PDO\\": "src/Instrumentation/PDO/src",
36+
"OpenTelemetry\\Contrib\\Instrumentation\\Opcache\\": "src/Instrumentation/Opcache/src",
3637
"OpenTelemetry\\Contrib\\Instrumentation\\Psr3\\": "src/Instrumentation/Psr3/src",
3738
"OpenTelemetry\\Contrib\\Instrumentation\\Psr6\\": "src/Instrumentation/Psr6/src",
3839
"OpenTelemetry\\Contrib\\Instrumentation\\Psr14\\": "src/Instrumentation/Psr14/src",
3940
"OpenTelemetry\\Contrib\\Instrumentation\\Psr15\\": "src/Instrumentation/Psr15/src",
4041
"OpenTelemetry\\Contrib\\Instrumentation\\Psr16\\": "src/Instrumentation/Psr16/src",
4142
"OpenTelemetry\\Contrib\\Instrumentation\\Psr18\\": "src/Instrumentation/Psr18/src",
4243
"OpenTelemetry\\Contrib\\Instrumentation\\ReactPHP\\": "src/Instrumentation/ReactPHP/src",
44+
"OpenTelemetry\\Contrib\\Instrumentation\\Session\\": "src/Instrumentation/Session/src",
4345
"OpenTelemetry\\Contrib\\Instrumentation\\Slim\\": "src/Instrumentation/Slim/src",
4446
"OpenTelemetry\\Contrib\\Instrumentation\\Symfony\\": "src/Instrumentation/Symfony/src",
4547
"OpenTelemetry\\Contrib\\Instrumentation\\Wordpress\\": "src/Instrumentation/Wordpress/src",
@@ -74,13 +76,15 @@
7476
"src/Instrumentation/MySqli/_register.php",
7577
"src/Instrumentation/OpenAIPHP/_register.php",
7678
"src/Instrumentation/PDO/_register.php",
79+
"src/Instrumentation/Opcache/_register.php",
7780
"src/Instrumentation/Psr3/_register.php",
7881
"src/Instrumentation/Psr6/_register.php",
7982
"src/Instrumentation/Psr14/_register.php",
8083
"src/Instrumentation/Psr15/_register.php",
8184
"src/Instrumentation/Psr16/_register.php",
8285
"src/Instrumentation/Psr18/_register.php",
8386
"src/Instrumentation/ReactPHP/_register.php",
87+
"src/Instrumentation/Session/_register.php",
8488
"src/Instrumentation/Slim/_register.php",
8589
"src/Instrumentation/Symfony/_register.php",
8690
"src/Instrumentation/Wordpress/_register.php",
@@ -111,10 +115,12 @@
111115
"OpenTelemetry\\Tests\\Instrumentation\\MySqli\\": "src/Instrumentation/MySqli/tests",
112116
"OpenTelemetry\\Contrib\\Instrumentation\\OpenAIPHP\\Tests\\": "src/Instrumentation/OpenAIPHP/tests",
113117
"OpenTelemetry\\Tests\\Instrumentation\\PDO\\": "src/Instrumentation/PDO/tests",
118+
"OpenTelemetry\\Tests\\Instrumentation\\Opcache\\": "src/Instrumentation/Opcache/tests",
114119
"OpenTelemetry\\Tests\\Instrumentation\\Psr6\\": "src/Instrumentation/Psr6/tests",
115120
"OpenTelemetry\\Instrumentation\\Psr14\\Tests\\": "src/Instrumentation/Psr14/tests",
116121
"OpenTelemetry\\Tests\\Instrumentation\\Psr16\\": "src/Instrumentation/Psr16/tests",
117122
"OpenTelemetry\\Tests\\Instrumentation\\ReactPHP\\": "src/Instrumentation/ReactPHP/tests",
123+
"OpenTelemetry\\Tests\\Instrumentation\\Session\\": "src/Instrumentation/Session/tests",
118124
"OpenTelemetry\\Tests\\Instrumentation\\Slim\\": "src/Instrumentation/Slim/tests",
119125
"OpenTelemetry\\Tests\\Instrumentation\\Symfony\\tests\\": "src/Instrumentation/Symfony/tests",
120126
"OpenTelemetry\\Tests\\Instrumentation\\Wordpress\\": "src/Instrumentation/Wordpress/tests",
@@ -149,13 +155,15 @@
149155
"open-telemetry/opentelemetry-auto-mysqli": "self.version",
150156
"open-telemetry/opentelemetry-auto-openai-php": "self.version",
151157
"open-telemetry/opentelemetry-auto-pdo": "self.version",
158+
"open-telemetry/opentelemetry-auto-opcache": "self.version",
152159
"open-telemetry/opentelemetry-auto-psr3": "self.version",
153160
"open-telemetry/opentelemetry-auto-psr6": "self.version",
154161
"open-telemetry/opentelemetry-auto-psr14": "self.version",
155162
"open-telemetry/opentelemetry-auto-psr15": "self.version",
156163
"open-telemetry/opentelemetry-auto-psr16": "self.version",
157164
"open-telemetry/opentelemetry-auto-psr18": "self.version",
158165
"open-telemetry/opentelemetry-auto-reactphp": "self.version",
166+
"open-telemetry/opentelemetry-auto-php-session": "self.version",
159167
"open-telemetry/opentelemetry-auto-slim": "self.version",
160168
"open-telemetry/opentelemetry-auto-symfony": "self.version",
161169
"open-telemetry/opentelemetry-auto-wordpress": "self.version",

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION}
55
volumes:
66
- ./:/usr/src/myapp
7+
- ./docker/opcache/opcache.ini:/etc/php/${PHP_VERSION}/cli/conf.d/opcache.ini
78
user: "${PHP_USER}:root"
89
environment:
910
XDEBUG_MODE: ${XDEBUG_MODE:-off}

docker/opcache/opcache.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; OPcache configuration
2+
[opcache]
3+
opcache.enable=1
4+
opcache.enable_cli=1
5+
opcache.memory_consumption=128
6+
opcache.interned_strings_buffer=8
7+
opcache.max_accelerated_files=10000
8+
opcache.revalidate_freq=60
9+
opcache.validate_timestamps=1
10+
opcache.save_comments=1
11+
opcache.enable_file_override=0

src/Instrumentation/IO/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ following functions:
2222
- `file_put_contents`
2323
- `curl_init`
2424
- `curl_exec`
25+
- `ob_start`
26+
- `ob_clean`
27+
- `ob_flush`
28+
- `flush`
2529

2630
## Configuration
2731

2832
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration):
2933

3034
```shell
3135
OTEL_PHP_DISABLED_INSTRUMENTATIONS=io
32-
```
36+
```

src/Instrumentation/IO/src/IOInstrumentation.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public static function register(): void
3333
self::_hook($instrumentation, null, 'file_get_contents', 'file_get_contents');
3434
self::_hook($instrumentation, null, 'file_put_contents', 'file_put_contents');
3535

36+
// Output buffer functions
37+
self::_hook($instrumentation, null, 'ob_start', 'ob_start');
38+
self::_hook($instrumentation, null, 'ob_clean', 'ob_clean');
39+
self::_hook($instrumentation, null, 'ob_flush', 'ob_flush');
40+
self::_hook($instrumentation, null, 'flush', 'flush');
41+
3642
self::_hook($instrumentation, null, 'curl_init', 'curl_init');
3743
self::_hook($instrumentation, null, 'curl_exec', 'curl_exec');
3844
}
@@ -109,6 +115,19 @@ private static function addParams(SpanBuilderInterface $builder, string $functio
109115
case 'file_put_contents':
110116
$builder->setAttribute('code.params.filename', $params[0]);
111117

118+
break;
119+
case 'ob_start':
120+
if (isset($params[0]) && is_callable($params[0])) {
121+
// We can't directly serialize the callback, so we'll just note that one was provided
122+
$builder->setAttribute('code.params.has_callback', true);
123+
}
124+
if (isset($params[1])) {
125+
$builder->setAttribute('code.params.chunk_size', $params[1]);
126+
}
127+
if (isset($params[2])) {
128+
$builder->setAttribute('code.params.flags', $params[2]);
129+
}
130+
112131
break;
113132
}
114133
}

0 commit comments

Comments
 (0)