Description
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.