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 zero code article code doesn't work #1437

Closed
RichardJECooke opened this issue Nov 25, 2024 · 5 comments · May be fixed by open-telemetry/opentelemetry.io#5747
Closed

PHP zero code article code doesn't work #1437

RichardJECooke opened this issue Nov 25, 2024 · 5 comments · May be fixed by open-telemetry/opentelemetry.io#5747
Labels
bug Something isn't working

Comments

@RichardJECooke
Copy link

RichardJECooke commented Nov 25, 2024

I've been trying to set this up for days: https://opentelemetry.io/docs/zero-code/php/.

Here's my dockerfile for PHP, built with docker build --platform linux/amd64 -t phpbox -f dockerfile .:

FROM --platform=linux/amd64 php:8.3.13-alpine3.20
RUN apk add unzip git curl autoconf gcc g++ make linux-headers zlib-dev file
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN pecl install excimer

RUN pecl install opentelemetry && docker-php-ext-enable opentelemetry

RUN composer require  slim/slim:4.14  slim/psr7  nyholm/psr7  nyholm/psr7-server  laminas/laminas-diactoros  open-telemetry/sdk  open-telemetry/opentelemetry-auto-slim open-telemetry/opentelemetry-auto-psr18 open-telemetry/exporter-otlp

and index.php

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

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

$app = AppFactory::create();

$app->get('/', function (Request $request, Response $response, $args) {
    $response->getBody()->write("Hello world!");
    return $response;
});

$app->run();

and my Docker commands:

docker run --rm -v ".:/app" -w "/app" phpbox sh -c  "composer require slim/slim:4.14 slim/psr7 nyholm/psr7 nyholm/psr7-server laminas/laminas-diactoros open-telemetry/sdk open-telemetry/opentelemetry-auto-slim open-telemetry/opentelemetry-auto-psr18 open-telemetry/exporter-otlp"

docker run --rm  -p "8000:8000" -v ".:/app" -w "/app" phpbox sh -c "env OTEL_PHP_AUTOLOAD_ENABLED=true   OTEL_SERVICE_NAME=app   OTEL_TRACES_EXPORTER=otlp   OTEL_EXPORTER_OTLP_PROTOCOL=grpc   OTEL_EXPORTER_OTLP_ENDPOINT=http://jbox:4317   OTEL_PROPAGATORS=baggage,tracecontext   OTEL_LOGS_LEVEL=debug   php -S 0.0.0.0:8000"

and I get this error:

[Mon Nov 25 13:24:24 2024] PHP 8.3.13 Development Server (http://0.0.0.0:8000) started
[Mon Nov 25 13:24:31 2024] 172.18.0.1:48636 Accepted
[Mon Nov 25 13:24:31 2024] OpenTelemetry: [warning] Unable to create otlp meter provider: Transport factory not defined for protocol: grpc in /app/vendor/open-telemetry/sdk/Metrics/MeterProviderFactory.php(48)
[Mon Nov 25 13:24:31 2024] OpenTelemetry: [warning] Error during opentelemetry initialization: Transport factory not defined for protocol: grpc
#0 /app/vendor/open-telemetry/exporter-otlp/LogsExporterFactory.php(48): OpenTelemetry\SDK\Registry::transportFactory('grpc')
#1 /app/vendor/open-telemetry/exporter-otlp/LogsExporterFactory.php(34): OpenTelemetry\Contrib\Otlp\LogsExporterFactory->buildTransport('grpc')
#2 /app/vendor/open-telemetry/sdk/Logs/ExporterFactory.php(27): OpenTelemetry\Contrib\Otlp\LogsExporterFactory->create()
#3 /app/vendor/open-telemetry/sdk/Logs/LoggerProviderFactory.php(19): OpenTelemetry\SDK\Logs\ExporterFactory->create()
#4 /app/vendor/open-telemetry/sdk/SdkAutoloader.php(96): OpenTelemetry\SDK\Logs\LoggerProviderFactory->create(NULL, Object(OpenTelemetry\SDK\Resource\ResourceInfo))
#5 /app/vendor/open-telemetry/sdk/SdkAutoloader.php(62): OpenTelemetry\SDK\SdkAutoloader::environmentBasedInitializer(Object(OpenTelemetry\API\Instrumentation\Configurator))
#6 /app/vendor/open-telemetry/api/Globals.php(93): OpenTelemetry\SDK\SdkAutoloader::OpenTelemetry\SDK\{closure}(Object(OpenTelemetry\API\Instrumentation\Configurator))
#7 /app/vendor/open-telemetry/api/Globals.php(43): OpenTelemetry\API\Globals::globals()
#8 /app/vendor/open-telemetry/api/Instrumentation/CachedInstrumentation.php(54): OpenTelemetry\API\Globals::tracerProvider()
#9 /app/vendor/open-telemetry/opentelemetry-auto-slim/src/SlimInstrumentation.php(49): OpenTelemetry\API\Instrumentation\CachedInstrumentation->tracer()
#10 /app/vendor/slim/slim/Slim/App.php(207): OpenTelemetry\Contrib\Instrumentation\Slim\SlimInstrumentation::OpenTelemetry\Contrib\Instrumentation\Slim\{closure}(Object(Slim\App), Array, 'Slim\\App', 'handle', '/app/vendor/sli...', 207, Array, Array)
#11 /app/vendor/slim/slim/Slim/App.php(193): Slim\App->handle(Object(Slim\Psr7\Request))
#12 /app/index.php(15): Slim\App->run()
#13 {main} in /app/vendor/open-telemetry/api/Globals.php(95)

Please help. The article doesn't give precise instructions with code and specific Docker images to reproduce the example they think should work.

@RichardJECooke RichardJECooke added the bug Something isn't working label Nov 25, 2024
@bobstrecansky
Copy link
Collaborator

I'm working on testing your implementation locally as well:
https://github.com/bobstrecansky/otel-php-no-code-test

I believe this has to do with grpc.

In your example, you have OTEL_EXPORTER_OTLP_ENDPOINT=http://jbox:4317 - what is jbox in this particular scenario?

@RichardJECooke
Copy link
Author

Ultimately I want to route traces to OTLP collector instead of console:

docker network create jnet

docker run --rm --network jnet --name jbox -p 4317:4317 -p 16686:16686 jaegertracing/all-in-one:latest

@brettmc
Copy link
Collaborator

brettmc commented Nov 26, 2024

It looks like you also need to install the open-telemetry/transport-grpc package, which the documentation missed. Can you please try it with that package installed and report back?

@RichardJECooke
Copy link
Author

@brettmc thanks, works now. Yall should really put some specific code like in this issue in the documentation. It's hard to reproduce as it is.

Updated dockerfile:

FROM --platform=linux/amd64 php:8.3.13-alpine3.20
RUN apk add unzip git curl autoconf gcc g++ make linux-headers zlib-dev file
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN pecl install excimer

RUN pecl install opentelemetry && docker-php-ext-enable opentelemetry

RUN pecl install grpc
RUN docker-php-ext-enable grpc

RUN composer require slim/slim:4.14 slim/psr7 nyholm/psr7 nyholm/psr7-server laminas/laminas-diactoros open-telemetry/sdk open-telemetry/opentelemetry-auto-slim open-telemetry/opentelemetry-auto-psr18 open-telemetry/exporter-otlp  open-telemetry/transport-grpc

Update compose command:

docker run --rm -v ".:/app" -w "/app" phpbox sh -c  "composer require  slim/slim:4.14 slim/psr7  nyholm/psr7  nyholm/psr7-server  laminas/laminas-diactoros open-telemetry/sdk  open-telemetry/opentelemetry-auto-slim  open-telemetry/opentelemetry-auto-psr18  open-telemetry/exporter-otlp  open-telemetry/transport-grpc"

@bobstrecansky
Copy link
Collaborator

@RichardJECooke - We'll add this to the README.md. Thanks for your contribution!

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

Successfully merging a pull request may close this issue.

3 participants