Skip to content

Commit c06b139

Browse files
authored
Add support for Doctrine auto-instrumentation (#300)
Adding initial support for auto-instrumenting Doctrine * feat(#1393): implement integration test and suppress phpstan and psalm errors * feat(#1393): add split readonly repo and github workflows * fix: apply semantic conventions on db attributes
1 parent 65de07e commit c06b139

13 files changed

+714
-5
lines changed

.github/workflows/php.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
'Instrumentation/CakePHP',
2626
'Instrumentation/CodeIgniter',
2727
'Instrumentation/Curl',
28+
'Instrumentation/Doctrine',
2829
'Instrumentation/ExtAmqp',
2930
'Instrumentation/ExtRdKafka',
3031
'Instrumentation/Guzzle',
@@ -55,18 +56,21 @@ jobs:
5556
'Symfony',
5657
]
5758
exclude:
58-
- project: 'Instrumentation/IO'
59-
php-version: 8.1
59+
6060
- project: 'Instrumentation/Curl'
6161
php-version: 8.1
62-
- project: 'Instrumentation/MySqli'
63-
php-version: 8.1
64-
- project: 'Instrumentation/PDO'
62+
- project: 'Instrumentation/Doctrine'
6563
php-version: 8.1
6664
- project: 'Instrumentation/ExtAmqp'
6765
php-version: 8.1
6866
- project: 'Instrumentation/ExtRdKafka'
6967
php-version: 8.1
68+
- project: 'Instrumentation/IO'
69+
php-version: 8.1
70+
- project: 'Instrumentation/MySqli'
71+
php-version: 8.1
72+
- project: 'Instrumentation/PDO'
73+
php-version: 8.1
7074
steps:
7175
- uses: actions/checkout@v4
7276

.gitsplit.yml

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ splits:
5858
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-cakephp.git"
5959
- prefix: "src/Instrumentation/Yii"
6060
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-yii.git"
61+
- prefix: "src/Instrumentation/Doctrine"
62+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-doctrine.git"
6163
- prefix: "src/Context/Swoole"
6264
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context-swoole.git"
6365
- prefix: "src/AutoInstrumentationInstaller"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* text=auto
2+
3+
*.md diff=markdown
4+
*.php diff=php
5+
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.php-cs-fixer.php export-ignore
9+
/phpstan.neon.dist export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/psalm.xml.dist export-ignore
12+
/tests export-ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->exclude('var/cache')
6+
->in(__DIR__);
7+
8+
$config = new PhpCsFixer\Config();
9+
return $config->setRules([
10+
'concat_space' => ['spacing' => 'one'],
11+
'declare_equal_normalize' => ['space' => 'none'],
12+
'is_null' => true,
13+
'modernize_types_casting' => true,
14+
'ordered_imports' => true,
15+
'php_unit_construct' => true,
16+
'single_line_comment_style' => true,
17+
'yoda_style' => false,
18+
'@PSR2' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'blank_line_after_opening_tag' => true,
21+
'blank_line_before_statement' => true,
22+
'cast_spaces' => true,
23+
'declare_strict_types' => true,
24+
'type_declaration_spaces' => true,
25+
'include' => true,
26+
'lowercase_cast' => true,
27+
'new_with_parentheses' => true,
28+
'no_extra_blank_lines' => true,
29+
'no_leading_import_slash' => true,
30+
'echo_tag_syntax' => true,
31+
'no_unused_imports' => true,
32+
'no_useless_else' => true,
33+
'no_useless_return' => true,
34+
'phpdoc_order' => true,
35+
'phpdoc_scalar' => true,
36+
'phpdoc_types' => true,
37+
'short_scalar_cast' => true,
38+
'blank_lines_before_namespace' => true,
39+
'single_quote' => true,
40+
'trailing_comma_in_multiline' => true,
41+
])
42+
->setRiskyAllowed(true)
43+
->setFinder($finder);
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-auto-doctrine/releases)
2+
[![Issues](https://img.shields.io/badge/issues-pink)](https://github.com/open-telemetry/opentelemetry-php/issues)
3+
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/Doctrine)
4+
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-auto-doctrine)
5+
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-auto-doctrine/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-doctrine/)
6+
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-auto-doctrine/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-doctrine/)
7+
8+
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
9+
10+
# OpenTelemetry Doctrine auto-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+
Auto-instrumentation hooks are registered via composer, and spans will automatically be created for
17+
selected `Doctrine\DBAL\Driver` and `Doctrine\DBAL\Driver\Connection` methods.
18+
19+
## Configuration
20+
21+
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration):
22+
23+
```shell
24+
OTEL_PHP_DISABLED_INSTRUMENTATIONS=doctrine
25+
```
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use OpenTelemetry\Contrib\Instrumentation\Doctrine\DoctrineInstrumentation;
6+
use OpenTelemetry\SDK\Sdk;
7+
8+
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(DoctrineInstrumentation::NAME) === true) {
9+
return;
10+
}
11+
12+
if (extension_loaded('opentelemetry') === false) {
13+
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry Doctrine auto-instrumentation', E_USER_WARNING);
14+
15+
return;
16+
}
17+
18+
DoctrineInstrumentation::register();
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "open-telemetry/opentelemetry-auto-doctrine",
3+
"description": "OpenTelemetry auto-instrumentation for Doctrine",
4+
"keywords": [
5+
"opentelemetry",
6+
"otel",
7+
"open-telemetry",
8+
"tracing",
9+
"doctrine",
10+
"instrumentation"
11+
],
12+
"type": "library",
13+
"homepage": "https://opentelemetry.io/docs/php",
14+
"readme": "./README.md",
15+
"license": "Apache-2.0",
16+
"minimum-stability": "dev",
17+
"prefer-stable": true,
18+
"require": {
19+
"php": "^8.2",
20+
"ext-opentelemetry": "*",
21+
"doctrine/dbal": "^3 || ^4 || ^5",
22+
"open-telemetry/api": "^1.0",
23+
"open-telemetry/sem-conv": "^1.24"
24+
},
25+
"require-dev": {
26+
"friendsofphp/php-cs-fixer": "^3",
27+
"phan/phan": "^5.0",
28+
"php-http/mock-client": "*",
29+
"phpstan/phpstan": "^1.1",
30+
"phpstan/phpstan-phpunit": "^1.0",
31+
"psalm/plugin-phpunit": "^0.18.4",
32+
"open-telemetry/sdk": "^1.0",
33+
"phpunit/phpunit": "^9.5",
34+
"vimeo/psalm": "^5.0"
35+
},
36+
"autoload": {
37+
"psr-4": {
38+
"OpenTelemetry\\Contrib\\Instrumentation\\Doctrine\\": "src/"
39+
},
40+
"files": [
41+
"_register.php"
42+
]
43+
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"OpenTelemetry\\Tests\\Instrumentation\\Doctrine\\": "tests/"
47+
}
48+
},
49+
"config": {
50+
"allow-plugins": {
51+
"php-http/discovery": false,
52+
"tbachert/spi": true
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
4+
parameters:
5+
tmpDir: var/cache/phpstan
6+
level: 5
7+
paths:
8+
- src
9+
- tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
6+
backupGlobals="false"
7+
backupStaticAttributes="false"
8+
cacheResult="false"
9+
colors="false"
10+
convertErrorsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertWarningsToExceptions="true"
13+
forceCoversAnnotation="false"
14+
processIsolation="false"
15+
stopOnError="false"
16+
stopOnFailure="false"
17+
stopOnIncomplete="false"
18+
stopOnSkipped="false"
19+
stopOnRisky="false"
20+
timeoutForSmallTests="1"
21+
timeoutForMediumTests="10"
22+
timeoutForLargeTests="60"
23+
verbose="true">
24+
25+
<coverage processUncoveredFiles="true" disableCodeCoverageIgnore="false">
26+
<include>
27+
<directory>src</directory>
28+
</include>
29+
</coverage>
30+
31+
<php>
32+
<ini name="date.timezone" value="UTC" />
33+
<ini name="display_errors" value="On" />
34+
<ini name="display_startup_errors" value="On" />
35+
<ini name="error_reporting" value="E_ALL" />
36+
</php>
37+
38+
<testsuites>
39+
<testsuite name="integration">
40+
<directory>tests/Integration</directory>
41+
</testsuite>
42+
</testsuites>
43+
44+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="3"
4+
cacheDirectory="var/cache/psalm"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="false"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
10+
<projectFiles>
11+
<directory name="src"/>
12+
<directory name="tests"/>
13+
</projectFiles>
14+
<plugins>
15+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
16+
</plugins>
17+
</psalm>

0 commit comments

Comments
 (0)