Skip to content
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

PHP 8.4.1 missing PDO construct span #1455

Open
TomKeur opened this issue Dec 13, 2024 · 2 comments
Open

PHP 8.4.1 missing PDO construct span #1455

TomKeur opened this issue Dec 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@TomKeur
Copy link

TomKeur commented Dec 13, 2024

Hi!

When running open-telemetry/opentelemetry-auto-pdo
on PHP 8.4.1 I'm not getting a construct span for PDO, because I'm not seeing this span my observability tool is
missing the database service at all, i've tried different o11y tools, but they are all not working.

The spans debug are generated by Grafana Alloy (http page otelcol.receiver.otlp.default -> live debugging), but with
the OTel collector I'm having the same results.

Describe your environment

  • macOS (the latest and greatest)
  • OrbStack (the latest and greatest)
  • PHP in Docker (different versions)
  • Symfony 7.2.1 (latest and greatest)

./bin/console about:

/var/www/html $ ./bin/console about
 -------------------- ----------------------------------------------
  Symfony
 -------------------- ----------------------------------------------
  Version              7.2.1
  Long-Term Support    No
  End of maintenance   07/2025 (in +230 days)
  End of life          07/2025 (in +230 days)
 -------------------- ----------------------------------------------
  Kernel
 -------------------- ----------------------------------------------
  Type                 App\Kernel
  Environment          dev
  Debug                true
  Charset              UTF-8
  Cache directory      ./var/cache/dev (12.9 MiB)
  Build directory      ./var/cache/dev (12.9 MiB)
  Log directory        ./var/log (42.3 MiB)
 -------------------- ----------------------------------------------
  PHP
 -------------------- ----------------------------------------------
  Version              8.4.1
  Architecture         64 bits
  Intl locale          en_US_POSIX
  Timezone             Europe/Amsterdam (2024-12-13T11:41:40+01:00)
  OPcache              Enabled
  APCu                 Enabled
  Xdebug               Not enabled
 -------------------- ----------------------------------------------

Debug is disabled on my php on CLI, but it's enabled as plugin (it's the same for both PHP versions)

/var/www/html $ type php
php is /usr/local/sbin/php
/var/www/html $ cat /usr/local/sbin/php
#!/usr/bin/env sh
export XDEBUG_MODE=off
/usr/local/bin/php -d memory_limit=-1 "$@"

The traces are generated with a simple HTTP request (not CLI, so xdebug is enabled)

PHP 8.3.14

/var/www/html $ php -v
PHP 8.3.14 (cli) (built: Nov 21 2024 19:22:48) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.14, Copyright (c), by Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans

First span:

ResourceSpans #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.27.0
Resource attributes:
     -> host.name: Str(dc1894264040)
     -> host.arch: Str(aarch64)
     -> os.type: Str(linux)
     -> os.description: Str(6.11.10-orbstack-00282-g72f45320fe21)
     -> os.name: Str(Linux)
     -> os.version: Str(#14 SMP Fri Dec  6 02:13:45 UTC 2024)
     -> process.pid: Int(89)
     -> process.executable.path: Str(/usr/local/sbin/php-fpm)
     -> process.owner: Str(qlico)
     -> process.runtime.name: Str(fpm-fcgi)
     -> process.runtime.version: Str(8.3.14)
     -> telemetry.sdk.name: Str(opentelemetry)
     -> telemetry.sdk.language: Str(php)
     -> telemetry.sdk.version: Str(1.1.2)
     -> telemetry.distro.name: Str(opentelemetry-php-instrumentation)
     -> telemetry.distro.version: Str(1.1.0)
     -> service.name: Str(kkfm)
     -> service.version: Str(13.37)
     -> deployment.environment: Str(dev)
     -> service.namespace: Str(kkfm)
ScopeSpans #0
ScopeSpans SchemaURL: https://opentelemetry.io/schemas/1.24.0
InstrumentationScope io.opentelemetry.contrib.php.pdo
Span #0
    Trace ID       : 718cfc5298a265166453288bdd258c3b
    Parent ID      : 733d74fe73866b3a
    ID             : 790c7e2ecb9a6773
    Name           : PDO::__construct
    Kind           : Client
    Start time     : 2024-12-13 10:33:00.201057048 +0000 UTC
    End time       : 2024-12-13 10:33:00.207934694 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> code.function: Str(__construct)
     -> code.namespace: Str(PDO)
     -> db.connection_string: Str(pgsql:host=postgres17;port=5432;dbname=kkfm;)
     -> db.user: Str(postgres)
     -> net.peer.name: Str(postgres17)
     -> server.address: Str(postgres17)
     -> db.name: Str(kkfm)
     -> db.system: Str(postgresql)

When running PHP 8.4.1:

/var/www/html $ php -v
PHP 8.4.1 (cli) (built: Nov 21 2024 18:27:49) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans

First span:

ResourceSpans #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.27.0
Resource attributes:
     -> host.name: Str(b6b83fc97b11)
     -> host.arch: Str(aarch64)
     -> os.type: Str(linux)
     -> os.description: Str(6.11.10-orbstack-00282-g72f45320fe21)
     -> os.name: Str(Linux)
     -> os.version: Str(#14 SMP Fri Dec  6 02:13:45 UTC 2024)
     -> process.pid: Int(8)
     -> process.executable.path: Str(/usr/local/sbin/php-fpm)
     -> process.owner: Str(qlico)
     -> process.runtime.name: Str(fpm-fcgi)
     -> process.runtime.version: Str(8.4.1)
     -> telemetry.sdk.name: Str(opentelemetry)
     -> telemetry.sdk.language: Str(php)
     -> telemetry.sdk.version: Str(1.1.2)
     -> telemetry.distro.name: Str(opentelemetry-php-instrumentation)
     -> telemetry.distro.version: Str(1.1.0)
     -> service.name: Str(kkfm)
     -> service.version: Str(13.37)
     -> deployment.environment: Str(dev)
     -> service.namespace: Str(kkfm)
ScopeSpans #0
ScopeSpans SchemaURL: https://opentelemetry.io/schemas/1.24.0
InstrumentationScope io.opentelemetry.contrib.php.pdo
Span #0
    Trace ID       : b7d71fed46b2401f5e89fe8404138a57
    Parent ID      : 4e91cfc3521026b7
    ID             : 8e9dee38bbd298df
    Name           : PDO::exec
    Kind           : Client
    Start time     : 2024-12-13 10:43:47.689871339 +0000 UTC
    End time       : 2024-12-13 10:43:47.689989838 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> code.function: Str(exec)
     -> code.namespace: Str(PDO)
     -> db.statement: Str(SET NAMES 'utf8')

Steps to reproduce

Doing a HTTP request to a PHP application on PHP 8.4.1 with OTel, it's gives a different first span.

What is the expected behavior?

Seeing the PDO::__construct as a first span.

What is the actual behavior?

Getting a different first span, PDO::exec instead of PDO::__construct.
This is causing the database service to be missing in the observability tool.

Additional context

If you need additional information, please contact me :).

@TomKeur TomKeur added the bug Something isn't working label Dec 13, 2024
@brettmc
Copy link
Collaborator

brettmc commented Dec 19, 2024

Hi @TomKeur when I run the test suite on 8.4.1, the tests pass - including this one test_pdo_construct

I also spun if this little test and ran it via the built-in webserver:

pdo_construct.php:

<?php

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=console');
putenv('OTEL_METRICS_EXPORTER=none');
putenv('OTEL_LOGS_EXPORTER=none');

require_once __DIR__ . '/../vendor/autoload.php';

$pdo = new PDO('sqlite::memory:');
$ php -v
PHP 8.4.1 (cli) (built: Nov 21 2024 17:58:21) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans

$ php -S localhost:8000 examples/pdo_construct.php

Hitting port 8000 with curl requests, and I see:

[Thu Dec 19 05:54:48 2024] PHP 8.4.1 Development Server (http://localhost:8000) started
[Thu Dec 19 05:55:14 2024] 127.0.0.1:43056 Accepted
[
    {
        "name": "PDO::__construct",
        "context": {
            "trace_id": "3564daf8664aecd02a45c60bf79c683b",
            "span_id": "8f2545dfc7679864",
            "trace_state": "",
            "trace_flags": 1
        },
        "resource": {
            "host.name": "2ac24ae09333",
            "host.arch": "x86_64",
            "os.type": "linux",
            "os.description": "5.15.0-128-generic",
            "os.name": "Linux",
            "os.version": "#138-Ubuntu SMP Sat Nov 30 22:28:23 UTC 2024",
            "process.pid": 22,
            "process.executable.path": "\/usr\/local\/bin\/php",
            "process.owner": "php",
            "process.runtime.name": "cli-server",
            "process.runtime.version": "8.4.1",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.language": "php",
            "telemetry.sdk.version": "1.1.2",
            "telemetry.distro.name": "opentelemetry-php-instrumentation",
            "telemetry.distro.version": "1.1.0",
            "service.name": "open-telemetry\/opentelemetry-auto-pdo",
            "service.version": "dev-main"
        },
        "parent_span_id": "",
        "kind": "KIND_CLIENT",
        "start": 1734587714901326405,
        "end": 1734587714901690487,
        "attributes": {
            "code.function": "__construct",
            "code.namespace": "PDO",
            "db.connection_string": "sqlite::memory:",
            "db.user": "unknown",
            "db.system": "sqlite",
            "db.name": "memory"
        },
        "status": {
            "code": "Unset",
            "description": ""
        },
        "events": [],
        "links": [],
        "schema_url": "https:\/\/opentelemetry.io\/schemas\/1.24.0"
    }
]

So, there's nothing fundamentally broken about the constructor with 8.4.1

I think the next step would be to switch to console exporter so you can see the spans that PHP emits. That should tell us if the problem is upstream (us) or downstream (something further down the line is discarding this span).

@TomKeur
Copy link
Author

TomKeur commented Dec 19, 2024

Hi @brettmc

Thank you for your response!
I've been testing, in my container with the built in server I'm not seeing any difference for my Symfony applicaton.

But when I'm overwriting my index.php with:

<?php
require_once __DIR__.'/../vendor/autoload.php';

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=console');
putenv('OTEL_METRICS_EXPORTER=none');
putenv('OTEL_LOGS_EXPORTER=none');

$dsn = 'pgsql:host=postgres17;dbname=foobar';
$user = 'foo';
$pass = 'bar';

$pdo = new PDO($dsn, $user, $pass);

I'm seeing the construct PDO::__construct, so somehow it's going wrong downstream.

Special thanks for: putenv('OTEL_TRACES_EXPORTER=console'); today I learned :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants