Skip to content

Commit e971b0f

Browse files
committed
Auto instrumentation for mysqli
1 parent f6a567b commit e971b0f

File tree

13 files changed

+1162
-0
lines changed

13 files changed

+1162
-0
lines changed
Lines changed: 12 additions & 0 deletions
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->exclude('vendor')
4+
->exclude('var/cache')
5+
->in(__DIR__);
6+
7+
$config = new PhpCsFixer\Config();
8+
return $config->setRules([
9+
'concat_space' => ['spacing' => 'one'],
10+
'declare_equal_normalize' => ['space' => 'none'],
11+
'is_null' => true,
12+
'modernize_types_casting' => true,
13+
'ordered_imports' => true,
14+
'php_unit_construct' => true,
15+
'single_line_comment_style' => true,
16+
'yoda_style' => false,
17+
'@PSR2' => true,
18+
'array_syntax' => ['syntax' => 'short'],
19+
'blank_line_after_opening_tag' => true,
20+
'blank_line_before_statement' => true,
21+
'cast_spaces' => true,
22+
'declare_strict_types' => true,
23+
'type_declaration_spaces' => true,
24+
'include' => true,
25+
'lowercase_cast' => true,
26+
'new_with_parentheses' => true,
27+
'no_extra_blank_lines' => true,
28+
'no_leading_import_slash' => true,
29+
'echo_tag_syntax' => true,
30+
'no_unused_imports' => true,
31+
'no_useless_else' => true,
32+
'no_useless_return' => true,
33+
'phpdoc_order' => true,
34+
'phpdoc_scalar' => true,
35+
'phpdoc_types' => true,
36+
'short_scalar_cast' => true,
37+
'blank_lines_before_namespace' => true,
38+
'single_quote' => true,
39+
'trailing_comma_in_multiline' => true,
40+
])
41+
->setRiskyAllowed(true)
42+
->setFinder($finder);
43+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-auto-mysqli/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/MySqli)
4+
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-auto-mysqli)
5+
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-auto-mysqli/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-mysqli/)
6+
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-auto-mysqli/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-mysqli/)
7+
8+
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
9+
10+
# OpenTelemetry mysqli 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 client kind spans will automatically be created when calling following functions or methods:
17+
18+
* `mysqli_connect`
19+
* `mysqli::__construct`
20+
* `mysqli::connect`
21+
* `mysqli::real_connect`
22+
* `mysqli_real_connect`
23+
24+
* `mysqli_query`
25+
* `mysqli::query`
26+
* `mysqli_real_query`
27+
* `mysqli::real_query`
28+
* `mysqli_execute_query`
29+
* `mysqli::execute_query`
30+
* `mysqli_multi_query`
31+
* `mysqli::multi_query`
32+
* `mysqli_next_result`
33+
* `mysqli::next_result`
34+
35+
* `mysqli_stmt::execute`
36+
* `mysqli_stmt_execute`
37+
* `mysqli_stmt::next_result`
38+
* `mysqli_stmt_next_result`
39+
40+
## Limitations
41+
42+
Transactions are not fully supported yet
43+
44+
## Configuration
45+
46+
### Disabling mysqli instrumentation
47+
48+
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration):
49+
50+
```shell
51+
OTEL_PHP_DISABLED_INSTRUMENTATIONS=mysqli
52+
```
53+
Lines changed: 18 additions & 0 deletions
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\MySqli\MySqliInstrumentation;
6+
use OpenTelemetry\SDK\Sdk;
7+
8+
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(MySqliInstrumentation::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 mysqli auto-instrumentation', E_USER_WARNING);
14+
15+
return;
16+
}
17+
18+
MySqliInstrumentation::register();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "open-telemetry/opentelemetry-auto-mysqli",
3+
"description": "OpenTelemetry auto-instrumentation for mysqli",
4+
"keywords": [
5+
"opentelemetry",
6+
"otel",
7+
"open-telemetry",
8+
"tracing",
9+
"mysql",
10+
"mysqli",
11+
"instrumentation"
12+
],
13+
"type": "library",
14+
"homepage": "https://opentelemetry.io/docs/php",
15+
"readme": "./README.md",
16+
"license": "Apache-2.0",
17+
"minimum-stability": "dev",
18+
"prefer-stable": true,
19+
"require": {
20+
"php": "^8.2",
21+
"ext-mysqli": "*",
22+
"ext-opentelemetry": "*",
23+
"open-telemetry/api": "^1.0",
24+
"open-telemetry/sem-conv": "^1.27.1",
25+
"symfony/polyfill-mbstring": "^1.31"
26+
},
27+
"suggest": {
28+
"ext-mbstring": "For better performance than symfony/polyfill-mbstring"
29+
},
30+
"require-dev": {
31+
"friendsofphp/php-cs-fixer": "^3",
32+
"phan/phan": "^5.0",
33+
"php-http/mock-client": "*",
34+
"phpstan/phpstan": "^1.1",
35+
"phpstan/phpstan-phpunit": "^1.0",
36+
"psalm/plugin-phpunit": "^0.18.4",
37+
"open-telemetry/sdk": "^1.0",
38+
"phpunit/phpunit": "^9.5",
39+
"vimeo/psalm": "^5.0"
40+
},
41+
"autoload": {
42+
"psr-4": {
43+
"OpenTelemetry\\Contrib\\Instrumentation\\MySqli\\": "src/"
44+
},
45+
"files": [
46+
"_register.php"
47+
]
48+
},
49+
"autoload-dev": {
50+
"psr-4": {
51+
"OpenTelemetry\\Tests\\Instrumentation\\MySqli\\": "tests/"
52+
}
53+
},
54+
"config": {
55+
"allow-plugins": {
56+
"php-http/discovery": false
57+
}
58+
}
59+
}
Lines changed: 9 additions & 0 deletions
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
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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="unit">
40+
<directory>tests/Unit</directory>
41+
</testsuite>
42+
<testsuite name="integration">
43+
<directory>tests/Integration</directory>
44+
</testsuite>
45+
</testsuites>
46+
47+
</phpunit>
Lines changed: 17 additions & 0 deletions
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)