Skip to content

Commit 146d036

Browse files
committed
auto instrumentation for curl (#1420)
1 parent 0a41216 commit 146d036

File tree

14 files changed

+870
-0
lines changed

14 files changed

+870
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"psr-4": {
1818
"OpenTelemetry\\Contrib\\Aws\\": "src/Aws/src",
1919
"OpenTelemetry\\Contrib\\Context\\Swoole\\": "src/Context/Swoole/src",
20+
"OpenTelemetry\\Contrib\\Instrumentation\\Curl\\": "src/Instrumentation/Curl/src",
2021
"OpenTelemetry\\Contrib\\Instrumentation\\ExtAmqp\\": "src/Instrumentation/ExtAmqp/src",
2122
"OpenTelemetry\\Contrib\\Instrumentation\\ExtRdKafka\\": "src/Instrumentation/ExtRdKafka/src",
2223
"OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\": "src/Instrumentation/Laravel/src",
@@ -39,6 +40,7 @@
3940
"OpenTelemetry\\Contrib\\Symfony\\": "src/Symfony/src"
4041
},
4142
"files": [
43+
"src/Instrumentation/Curl/_register.php",
4244
"src/Instrumentation/ExtAmqp/_register.php",
4345
"src/Instrumentation/ExtRdKafka/_register.php",
4446
"src/Instrumentation/HttpAsyncClient/_register.php",
@@ -59,6 +61,7 @@
5961
"open-telemetry/contrib-aws": "self.version",
6062
"open-telemetry/contrib-sdk-bundle": "self.version",
6163
"open-telemetry/context-swoole": "self.version",
64+
"open-telemetry/opentelemetry-auto-curl": "self.version",
6265
"open-telemetry/opentelemetry-auto-laravel": "self.version",
6366
"open-telemetry/opentelemetry-auto-http-async": "self.version",
6467
"open-telemetry/opentelemetry-auto-io": "self.version",
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+

src/Instrumentation/Curl/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-auto-curl/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/curl)
4+
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-auto-curl)
5+
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-auto-curl/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-curl/)
6+
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-auto-curl/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-curl/)
7+
8+
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
9+
10+
# OpenTelemetry curl 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 `curl_exec` or `curl_multi_exec` functions.
17+
18+
## Limitations
19+
The curl_multi instrumentation is not resilient to shortcomings in the application and requires proper implementation. If the application does not call the curl_multi_info_read function, the instrumentation will be unable to measure the execution time for individual requests-time will be aggregated for all transfers. Similarly, error detection will be impacted, as the error code information will be missing in this case. In case of encountered issues, it is recommended to review the application code and adjust it to match example #1 provided in [curl_multi_exec documentation](https://www.php.net/manual/en/function.curl-multi-exec.php).
20+
21+
## Configuration
22+
23+
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration):
24+
25+
```shell
26+
OTEL_PHP_DISABLED_INSTRUMENTATIONS=curl
27+
```
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\Curl\CurlInstrumentation;
6+
use OpenTelemetry\SDK\Sdk;
7+
8+
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(CurlInstrumentation::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 curl auto-instrumentation', E_USER_WARNING);
14+
15+
return;
16+
}
17+
18+
CurlInstrumentation::register();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "open-telemetry/opentelemetry-auto-curl",
3+
"description": "OpenTelemetry auto-instrumentation for curl",
4+
"keywords": [
5+
"opentelemetry",
6+
"otel",
7+
"open-telemetry",
8+
"tracing",
9+
"curl",
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-curl": "*",
21+
"ext-opentelemetry": "*",
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\\Curl\\": "src/"
39+
},
40+
"files": [
41+
"_register.php"
42+
]
43+
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"OpenTelemetry\\Tests\\Instrumentation\\Curl\\": "tests/"
47+
}
48+
},
49+
"config": {
50+
"allow-plugins": {
51+
"php-http/discovery": false,
52+
"tbachert/spi": false
53+
}
54+
}
55+
}
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)