opentelemetry-php icon indicating copy to clipboard operation
opentelemetry-php copied to clipboard

[opentelemtry-auto-wordpress]PHP Fatal Error: "OpenTelemetry\\API\\Common\\Instrumentation\\CachedInstrumentation" not found

Open jozsoka2222 opened this issue 1 year ago • 14 comments

Describe your environment php version: 8.2.14 wordpress version: 6.4.2 environment: k8s

I have base image, and I add to this base image the files and plugins...

FROM composer:2.5 as build
COPY composer.json ./
RUN composer install --ignore-platform-reqs

FROM ${REPO_NAME}:${WORDPRESS_VERSION}-php${PHP_VERSION}-apache
WORKDIR /usr/src/wordpress

RUN pecl install opentelemetry protobuf
COPY otel.php.ini $PHP_INI_DIR/conf.d/.
COPY --from=build /app/vendor /var/www/otel
RUN set -eux; \
	find /etc/apache2 -name '*.conf' -type f -exec sed -ri -e "s!/var/www/html!$PWD!g" -e "s!Directory /var/www/!Directory $PWD!g" '{}' +; \
	cp -s wp-config-docker.php wp-config.php

After build and deploy, on the log i see this error message: PHP Fatal error: Uncaught Error: Class "OpenTelemetry\\API\\Common\\Instrumentation\\CachedInstrumentation" not found in /var/www/otel/open-telemetry/opentelemetry-auto-wordpress/src/WordpressInstrumentation.php:25\nStack trace:\n#0 /var/www/otel/open-telemetry/opentelemetry-auto-wordpress/_register.php(18): OpenTelemetry\\Contrib\\Instrumentation\\Wordpress\\WordpressInstrumentation::register()\n#1 /var/www/otel/composer/autoload_real.php(39): require('/var/www/otel/o...')\n#2 /var/www/otel/composer/autoload_real.php(43): {closure}('2497cfe3497c24b...', '/var/www/otel/c...')\n#3 /var/www/otel/autoload.php(25): ComposerAutoloaderInit743de1c8df58bc7f2e839a57834297b8::getLoader()\n#4 {main}\n thrown in /var/www/otel/open-telemetry/opentelemetry-auto-wordpress/src/WordpressInstrumentation.php on line 25

What I do wrong? How can I solve this problem?

jozsoka2222 avatar Feb 26 '24 21:02 jozsoka2222

I think you're using an old version of the wordpress auto-instrumentation package. It's not clear from your info above how you installed it (not via composer, by the looks of it). From the error message, you're using a version <= 0.0.6, but the latest is 0.0.15

brettmc avatar Feb 28 '24 08:02 brettmc

I am installing with this composer file:

{
    "name": "opentelemetry/wordpress-example",
    "description": "An example of autoinstrumentation of wordpress with the official wordpress docker image",
    "type": "project",
    "minimum-stability": "beta",
    "require": {
        "open-telemetry/opentelemetry-auto-wordpress": "^0.0.5",
        "open-telemetry/sdk": "^1.0@beta",
        "open-telemetry/exporter-otlp": "^1.0@beta",
        "php-http/guzzle7-adapter": "^1.0"
    },
    "config": {
        "allow-plugins": {
            "php-http/discovery": true
        }
    }
}

This is from official example file. Maybe, I need write exact versions for packages?

jozsoka2222 avatar Feb 28 '24 12:02 jozsoka2222

I give the version to auto-wordpress package, but i don't get data, how can I check tracing connected to my exporter that inside other namespace? I give this values:

  OTEL_PHP_AUTOLOAD_ENABLED: true
  OTEL_SERVICE_NAME: "am-demo-wordpress"
  OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "grafana-agent-traces.monitoring.svc.cluster.local:4317"
  OTEL_TRACES_EXPORTER: "otlp"

Andother question, I have otlp tracing on my ingress, that will join span together automatic, or i need specify the connection between spans?

jozsoka2222 avatar Feb 28 '24 12:02 jozsoka2222

This is from official example file. Maybe, I need write exact versions for packages?

If you run composer update, does it update to later versions of the packages? In any case, the doco you are referring to is a little out of date - can you provide a link to it?

how can I check tracing connected to my exporter that inside other namespace

Set OTEL_TRACES_EXPORER=console and check stdout for traces is a quick way to do it. If you see some trace data being printed out, then you know it's generating traces. Then, switch back to otlp exporter, check for errors in PHP's error log (eg transport failure). If grafana-agent-traces doesn't allow you to turn up logging/debugging, you could install the opentelemetry collector with extra logging turned on to see if the traces made it to there.

I have otlp tracing on my ingress, that will join span together automatic

Yes, if ingress is correctly setting the traceparent header, they should be joined. See https://github.com/opentelemetry-php/contrib-auto-wordpress/blob/main/src/WordpressInstrumentation.php#L83

brettmc avatar Feb 28 '24 12:02 brettmc

When I try update(after install) I got this message, and not updating packages

Step 7/15 : RUN composer update --ignore-platform-reqs
 ---> Running in d8ddc464fe4a
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
10 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found

jozsoka2222 avatar Feb 28 '24 12:02 jozsoka2222

When I try update(after install) I got this message, and not updating packages

Had you already updated though? What does composer show say about which version is installed?

brettmc avatar Feb 28 '24 12:02 brettmc

Instead I try console out for tracing, and I can't see anything from tracing :/

jozsoka2222 avatar Feb 28 '24 12:02 jozsoka2222

I see composer show, and display this this:

Step 7/16 : RUN composer update --ignore-platform-reqs
 ---> Running in e76485e74e86
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
10 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
Removing intermediate container e76485e74e86
 ---> 2d27ab9c85a5
Step 8/16 : RUN composer show
 ---> Running in 3ba3df2c7957
google/protobuf                             v3.25.3 proto library for PHP
guzzlehttp/guzzle                           7.8.1   Guzzle is a PHP HTTP ...
guzzlehttp/promises                         2.0.2   Guzzle promises library
guzzlehttp/psr7                             2.6.2   PSR-7 message impleme...
nyholm/psr7                                 1.8.1   A fast PHP7 implement...
nyholm/psr7-server                          1.1.0   Helper classes to han...
open-telemetry/api                          1.0.3   API for OpenTelemetry...
open-telemetry/context                      1.0.2   Context implementatio...
open-telemetry/exporter-otlp                1.0.3   OTLP exporter for Ope...
open-telemetry/gen-otlp-protobuf            1.1.0   PHP protobuf files fo...
open-telemetry/opentelemetry-auto-wordpress 0.0.5   OpenTelemetry auto-in...
open-telemetry/sdk                          1.0.8   SDK for OpenTelemetry...
open-telemetry/sem-conv                     1.24.0  Semantic conventions ...
php-http/discovery                          1.19.2  Finds and installs PS...
php-http/guzzle7-adapter                    1.0.0   Guzzle 7 HTTP Adapter
php-http/httplug                            2.4.0   HTTPlug, the HTTP cli...
php-http/promise                            1.3.0   Promise used for asyn...
psr/http-client                             1.0.3   Common interface for ...
psr/http-factory                            1.0.2   Common interfaces for...
psr/http-message                            2.0     Common interface for ...
psr/log                                     3.0.0   Common interface for ...
ralouphie/getallheaders                     3.0.3   A polyfill for getall...
symfony/deprecation-contracts               v3.4.0  A generic function an...
symfony/polyfill-mbstring                   v1.29.0 Symfony polyfill for ...
symfony/polyfill-php80                      v1.29.0 Symfony polyfill back...
symfony/polyfill-php81                      v1.29.0 Symfony polyfill back...
symfony/polyfill-php82                      v1.29.0 Symfony polyfill back...

jozsoka2222 avatar Feb 28 '24 12:02 jozsoka2222

open-telemetry/opentelemetry-auto-wordpress 0.0.5 OpenTelemetry auto-in...

I don't know why that's so old, but can you update your composer.json to ^0.0.15 and then composer update? It may fail, but give more info on why it doesn't want to install a later version. If you're still on 0.0.5 then it's presumably still broken, and that's why it's not exporting anything. So let's fix that problem first.

brettmc avatar Feb 28 '24 12:02 brettmc

I got this output, maybe need compsoer fund?

Step 7/16 : RUN composer update --ignore-platform-reqs
 ---> Running in 86c2e2ae985e
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
10 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
Removing intermediate container 86c2e2ae985e
 ---> 39d6e541d52e
Step 8/16 : RUN composer show
 ---> Running in f2ae1c6db2b3
google/protobuf                             v3.25.3 proto library for PHP
guzzlehttp/guzzle                           7.8.1   Guzzle is a PHP HTTP ...
guzzlehttp/promises                         2.0.2   Guzzle promises library
guzzlehttp/psr7                             2.6.2   PSR-7 message impleme...
nyholm/psr7                                 1.8.1   A fast PHP7 implement...
nyholm/psr7-server                          1.1.0   Helper classes to han...
open-telemetry/api                          1.0.3   API for OpenTelemetry...
open-telemetry/context                      1.0.2   Context implementatio...
open-telemetry/exporter-otlp                1.0.3   OTLP exporter for Ope...
open-telemetry/gen-otlp-protobuf            1.1.0   PHP protobuf files fo...
open-telemetry/opentelemetry-auto-wordpress 0.0.15  OpenTelemetry auto-in...
open-telemetry/sdk                          1.0.8   SDK for OpenTelemetry...
open-telemetry/sem-conv                     1.24.0  Semantic conventions ...
php-http/discovery                          1.19.2  Finds and installs PS...
php-http/guzzle7-adapter                    1.0.0   Guzzle 7 HTTP Adapter
php-http/httplug                            2.4.0   HTTPlug, the HTTP cli...
php-http/promise                            1.3.0   Promise used for asyn...
psr/http-client                             1.0.3   Common interface for ...
psr/http-factory                            1.0.2   Common interfaces for...
psr/http-message                            2.0     Common interface for ...
psr/log                                     3.0.0   Common interface for ...
ralouphie/getallheaders                     3.0.3   A polyfill for getall...
symfony/deprecation-contracts               v3.4.0  A generic function an...
symfony/polyfill-mbstring                   v1.29.0 Symfony polyfill for ...
symfony/polyfill-php80                      v1.29.0 Symfony polyfill back...
symfony/polyfill-php81                      v1.29.0 Symfony polyfill back...
symfony/polyfill-php82                      v1.29.0 Symfony polyfill back...

jozsoka2222 avatar Feb 28 '24 13:02 jozsoka2222

It is resolve PHP Fatal error, but I still don't get tracing just get wordpress default log from request.

jozsoka2222 avatar Feb 28 '24 13:02 jozsoka2222

ok, that's progress. without knowing your setup, I can't say where stdout output (from the console logger) would go. According to https://stackoverflow.com/questions/11318768/php-stdout-on-apache then stdout goes to the web server (apache or nginx). You could try running the web server in the foreground to see that output. Or, having fixed the fatal, try again with otlp exporter.

brettmc avatar Feb 28 '24 13:02 brettmc

I am using apache2 in foreground, and i see the log/console with k9s "l" key, Thanks for the help in fatal error.

jozsoka2222 avatar Feb 28 '24 14:02 jozsoka2222

I am using apache2 in foreground, and i see the log/console with k9s "l" key, Thanks for the help in fatal error.

If you are still not seeing any output, then can you please create a reproduction of it in your personal github (preferably using docker) so that somebody can try to debug the issue?

brettmc avatar Feb 29 '24 23:02 brettmc

Closing due to inactivity. Please re-open or create a new issue if required.

brettmc avatar May 01 '24 00:05 brettmc