-
Couldn't load subscription status.
- Fork 117
PostgreSQL instrumentation #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brettmc
merged 19 commits into
open-telemetry:main
from
intuibase:postgresql_instrumentation
Aug 1, 2025
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
93c363a
chore: update dependabot configuration [skip ci]
github-actions[bot] 552df1f
PostgreSQL instrumentation
intuibase c5d146b
Instrumentation of asynchronous commands
intuibase 9b85a8f
Large object instrumentation
intuibase 80bb6c3
Merge branch 'open-telemetry:main' into main
intuibase 38f0f9c
Merge branch 'main' into postgresql_instrumentation
intuibase ccb94b0
PostgreSQL instrumentation test
intuibase e1585f9
PgSqlTracker tests
intuibase 6516226
Fixed static analysis issues
intuibase b179bea
Improved test
intuibase 7f999ac
Added readme
intuibase 38d7643
Add to workflow
intuibase cd973a7
Healtcheck fix
intuibase c4cb5f8
Healtcheck fix
intuibase d78ff39
Healtcheck fix
intuibase 839b141
Missing file
intuibase 5f03fe8
Missing .phan directory
intuibase 3edfabf
Fixed phpstan analysis issues
intuibase e6515b1
Added gitsplit entry
intuibase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ RUN install-php-extensions \ | |
| mongodb \ | ||
| amqp \ | ||
| rdkafka \ | ||
| mysqli | ||
| mysqli \ | ||
| pgsql | ||
|
|
||
| USER php | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| * text=auto | ||
|
|
||
| *.md diff=markdown | ||
| *.php diff=php | ||
|
|
||
| /.gitattributes export-ignore | ||
| /.gitignore export-ignore | ||
| /.php-cs-fixer.php export-ignore | ||
| /phpstan.neon.dist export-ignore | ||
| /phpunit.xml.dist export-ignore | ||
| /psalm.xml.dist export-ignore | ||
| /tests export-ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /vendor/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
| $finder = PhpCsFixer\Finder::create() | ||
| ->exclude('vendor') | ||
| ->exclude('var/cache') | ||
| ->in(__DIR__); | ||
|
|
||
| $config = new PhpCsFixer\Config(); | ||
| return $config->setRules([ | ||
| 'concat_space' => ['spacing' => 'one'], | ||
| 'declare_equal_normalize' => ['space' => 'none'], | ||
| 'is_null' => true, | ||
| 'modernize_types_casting' => true, | ||
| 'ordered_imports' => true, | ||
| 'php_unit_construct' => true, | ||
| 'single_line_comment_style' => true, | ||
| 'yoda_style' => false, | ||
| '@PSR2' => true, | ||
| 'array_syntax' => ['syntax' => 'short'], | ||
| 'blank_line_after_opening_tag' => true, | ||
| 'blank_line_before_statement' => true, | ||
| 'cast_spaces' => true, | ||
| 'declare_strict_types' => true, | ||
| 'type_declaration_spaces' => true, | ||
| 'include' => true, | ||
| 'lowercase_cast' => true, | ||
| 'new_with_parentheses' => true, | ||
| 'no_extra_blank_lines' => true, | ||
| 'no_leading_import_slash' => true, | ||
| 'echo_tag_syntax' => true, | ||
| 'no_unused_imports' => true, | ||
| 'no_useless_else' => true, | ||
| 'no_useless_return' => true, | ||
| 'phpdoc_order' => true, | ||
| 'phpdoc_scalar' => true, | ||
| 'phpdoc_types' => true, | ||
| 'short_scalar_cast' => true, | ||
| 'blank_lines_before_namespace' => true, | ||
| 'single_quote' => true, | ||
| 'trailing_comma_in_multiline' => true, | ||
| ]) | ||
| ->setRiskyAllowed(true) | ||
| ->setFinder($finder); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| [](https://github.com/open-telemetry/opentelemetry-php-contrib/releases) | ||
| [](https://github.com/open-telemetry/opentelemetry-php/issues) | ||
| [](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/PostgreSql) | ||
| [](https://github.com/open-telemetry/opentelemetry-php-contrib) | ||
| [](https://packagist.org/packages/open-telemetry/opentelemetry-auto-postgresql/) | ||
| [](https://packagist.org/packages/open-telemetry/opentelemetry-auto-postgresql/) | ||
|
|
||
| > This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib. | ||
|
|
||
| # OpenTelemetry PostgreSQL auto-instrumentation | ||
|
|
||
| Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to | ||
| install and configure the extension and SDK. | ||
|
|
||
| ## Overview | ||
|
|
||
| This package provides auto-instrumentation for the PostgreSQL native PHP extension (`ext-pgsql`). | ||
| Hooks are registered via Composer, and client spans are automatically created for key database operations. | ||
|
|
||
| Supported functions include: | ||
|
|
||
| ### Connection | ||
| - `pg_connect` | ||
| - `pg_pconnect` | ||
|
|
||
| ### Queries | ||
| - `pg_query` | ||
| - `pg_query_params` | ||
| - `pg_send_query` | ||
| - `pg_send_query_params` | ||
| - `pg_get_result` | ||
|
|
||
| ### Prepared Statements | ||
| - `pg_prepare` | ||
| - `pg_send_prepare` | ||
| - `pg_execute` | ||
| - `pg_send_execute` | ||
|
|
||
| ### Table/Row Operations | ||
| - `pg_insert` | ||
| - `pg_select` | ||
| - `pg_update` | ||
| - `pg_delete` | ||
|
|
||
| ### COPY | ||
| - `pg_copy_from` | ||
| - `pg_copy_to` | ||
|
|
||
| ### Large Objects (LOB) | ||
| - `pg_lo_create` | ||
| - `pg_lo_open` | ||
| - `pg_lo_write` | ||
| - `pg_lo_read` | ||
| - `pg_lo_read_all` | ||
| - `pg_lo_unlink` | ||
| - `pg_lo_import` | ||
| - `pg_lo_export` | ||
|
|
||
|
|
||
| ## Configuration | ||
|
|
||
| ### Disabling PostgreSQL instrumentation | ||
|
|
||
| The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration): | ||
|
|
||
| ```shell | ||
| OTEL_PHP_DISABLED_INSTRUMENTATIONS=postgresql | ||
| ``` | ||
|
|
||
| ## Compatibility | ||
|
|
||
| PHP 8.2 or newer is required |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use OpenTelemetry\Contrib\Instrumentation\PostgreSql\PostgreSqlInstrumentation; | ||
| use OpenTelemetry\SDK\Sdk; | ||
|
|
||
| if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(PostgreSqlInstrumentation::NAME) === true) { | ||
| return; | ||
| } | ||
|
|
||
| if (extension_loaded('opentelemetry') === false) { | ||
| trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry postgresql auto-instrumentation', E_USER_WARNING); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| PostgreSqlInstrumentation::register(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "name": "open-telemetry/opentelemetry-auto-postgresql", | ||
| "version": "dev-main", | ||
| "description": "OpenTelemetry auto-instrumentation for postgresql", | ||
| "keywords": [ | ||
| "opentelemetry", | ||
| "otel", | ||
| "open-telemetry", | ||
| "tracing", | ||
| "postgresql", | ||
| "instrumentation" | ||
| ], | ||
| "type": "library", | ||
| "homepage": "https://opentelemetry.io/docs/php", | ||
| "readme": "./README.md", | ||
| "license": "Apache-2.0", | ||
| "minimum-stability": "dev", | ||
| "prefer-stable": true, | ||
| "require": { | ||
| "php": "^8.2", | ||
| "ext-pgsql": "*", | ||
| "ext-opentelemetry": "*", | ||
| "open-telemetry/api": "^1.0", | ||
| "open-telemetry/sem-conv": "^1.30", | ||
| "symfony/polyfill-mbstring": "^1.31" | ||
| }, | ||
| "suggest": { | ||
| "ext-mbstring": "For better performance than symfony/polyfill-mbstring" | ||
| }, | ||
| "require-dev": { | ||
| "friendsofphp/php-cs-fixer": "^3", | ||
| "phan/phan": "^5.0", | ||
| "php-http/mock-client": "*", | ||
| "phpstan/phpstan": "^1.1", | ||
| "phpstan/phpstan-phpunit": "^1.0", | ||
| "psalm/plugin-phpunit": "^0.19.2", | ||
| "open-telemetry/sdk": "^1.0", | ||
| "phpunit/phpunit": "^9.5", | ||
| "vimeo/psalm": "6.4.0" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "OpenTelemetry\\Contrib\\Instrumentation\\PostgreSql\\": "src/" | ||
| }, | ||
| "files": [ | ||
| "_register.php" | ||
| ] | ||
| }, | ||
| "autoload-dev": { | ||
| "psr-4": { | ||
| "OpenTelemetry\\Tests\\Instrumentation\\PostgreSql\\": "tests/" | ||
| } | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "php-http/discovery": false | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| includes: | ||
| - vendor/phpstan/phpstan-phpunit/extension.neon | ||
|
|
||
| parameters: | ||
| tmpDir: var/cache/phpstan | ||
| level: 5 | ||
| paths: | ||
| - src | ||
| - tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <phpunit | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
| backupGlobals="false" | ||
| backupStaticAttributes="false" | ||
| cacheResult="false" | ||
| colors="false" | ||
| convertErrorsToExceptions="true" | ||
| convertNoticesToExceptions="true" | ||
| convertWarningsToExceptions="true" | ||
| forceCoversAnnotation="false" | ||
| processIsolation="false" | ||
| stopOnError="false" | ||
| stopOnFailure="false" | ||
| stopOnIncomplete="false" | ||
| stopOnSkipped="false" | ||
| stopOnRisky="false" | ||
| timeoutForSmallTests="1" | ||
| timeoutForMediumTests="10" | ||
| timeoutForLargeTests="60" | ||
| verbose="true"> | ||
|
|
||
| <coverage processUncoveredFiles="true" disableCodeCoverageIgnore="false"> | ||
| <include> | ||
| <directory>src</directory> | ||
| </include> | ||
| </coverage> | ||
|
|
||
| <php> | ||
| <ini name="date.timezone" value="UTC" /> | ||
| <ini name="display_errors" value="On" /> | ||
| <ini name="display_startup_errors" value="On" /> | ||
| <ini name="error_reporting" value="E_ALL" /> | ||
| </php> | ||
|
|
||
| <testsuites> | ||
| <testsuite name="unit"> | ||
| <directory>tests/Unit</directory> | ||
| </testsuite> | ||
| <testsuite name="integration"> | ||
| <directory>tests/Integration</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
|
|
||
| </phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0"?> | ||
| <psalm | ||
| errorLevel="3" | ||
| cacheDirectory="var/cache/psalm" | ||
| findUnusedBaselineEntry="true" | ||
| findUnusedCode="false" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xmlns="https://getpsalm.org/schema/config" | ||
| xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"> | ||
| <projectFiles> | ||
| <directory name="src"/> | ||
| <directory name="tests"/> | ||
| </projectFiles> | ||
| <plugins> | ||
| <pluginClass class="Psalm\PhpUnitPlugin\Plugin"/> | ||
| </plugins> | ||
| </psalm> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.