阅读php的opemtelemetry安装文档,尝试了挺久的,目前环境还是部分成功,记录一下便于查阅;
环境设置
(1)传统centos系统安装
yum install -y gcc make autoconf
php pickle.phar install --source https://github.com/open-telemetry/opentelemetry-php-instrumentation.git#1.0.0beta2 //此步骤出错,如下
- Installing opentelemetry-php-instrumentation (1.0.0beta2): Cloning 1.0.0beta2
Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+6e8acdc4a9ed+2023-04-13+0353
PHP Fatal error: Uncaught Error: Call to a member function getName() on null in phar:///pickle.phar/vendor/composer/composer/src/Composer/Util/GitHub.php:91
Stack trace:
#0 phar:///pickle.phar/vendor/composer/composer/src/Composer/Util/Git.php(110): Composer\Util\GitHub->authorizeOAuthInteractively()
#1 phar:///pickle.phar/vendor/composer/composer/src/Composer/Downloader/GitDownloader.php(90): Composer\Util\Git->runCommand()
#2 phar:///pickle.phar/vendor/composer/composer/src/Composer/Downloader/VcsDownloader.php(90): Composer\Downloader\GitDownloader->doDownload()
#3 phar:///pickle.phar/src/Package/Convey/Command/Git.php(105): Composer\Downloader\VcsDownloader->download()
#4 phar:///pickle.phar/src/Package/Convey/Command/Git.php(50): Pickle\Package\Convey\Command\Git->fetch()
#5 phar:///pickle.phar/src/Package/Convey.php(63): Pickle\Package\Convey\Command\Git->execute()
#6 phar:///pickle.phar/src/Console/Helper/PackageHelper.php(119): Pickle\Package\Convey->deliver()
#7 phar:///pickle.phar/src/Console/Command/InstallerCommand.php(217): Pickle\Console\Helper\PackageHelper->convey()
#8 phar:///pickle.phar/vendor/symfony/console/Command/Command.php(298): Pickle\Console\Command\InstallerCommand->execute()
#9 phar:///pickle.phar/vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run()
#10 phar:///pickle.phar/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#11 phar:///pickle.phar/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#12 phar:///pickle.phar/bin/pickle(38): Symfony\Component\Console\Application->run()
#13 /pickle.phar(10): require('...')
#14 {main}
thrown in phar:///pickle.phar/vendor/composer/composer/src/Composer/Util/GitHub.php on line 91Fatal error: Uncaught Error: Call to a member function getName() on null in phar:///pickle.phar/vendor/composer/composer/src/Composer/Util/GitHub.php:91
Stack trace:
#0 phar:///pickle.phar/vendor/composer/composer/src/Composer/Util/Git.php(110): Composer\Util\GitHub->authorizeOAuthInteractively()
#1 phar:///pickle.phar/vendor/composer/composer/src/Composer/Downloader/GitDownloader.php(90): Composer\Util\Git->runCommand()
#2 phar:///pickle.phar/vendor/composer/composer/src/Composer/Downloader/VcsDownloader.php(90): Composer\Downloader\GitDownloader->doDownload()
#3 phar:///pickle.phar/src/Package/Convey/Command/Git.php(105): Composer\Downloader\VcsDownloader->download()
#4 phar:///pickle.phar/src/Package/Convey/Command/Git.php(50): Pickle\Package\Convey\Command\Git->fetch()
#5 phar:///pickle.phar/src/Package/Convey.php(63): Pickle\Package\Convey\Command\Git->execute()
#6 phar:///pickle.phar/src/Console/Helper/PackageHelper.php(119): Pickle\Package\Convey->deliver()
#7 phar:///pickle.phar/src/Console/Command/InstallerCommand.php(217): Pickle\Console\Helper\PackageHelper->convey()
#8 phar:///pickle.phar/vendor/symfony/console/Command/Command.php(298): Pickle\Console\Command\InstallerCommand->execute()
#9 phar:///pickle.phar/vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run()
#10 phar:///pickle.phar/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#11 phar:///pickle.phar/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#12 phar:///pickle.phar/bin/pickle(38): Symfony\Component\Console\Application->run()
#13 /pickle.phar(10): require('...')
#14 {main}
thrown in phar:///pickle.phar/vendor/composer/composer/src/Composer/Util/GitHub.php on line 91
设置了认证,还是出错,目前按官方文档操作的错误还是没有解决;
vi /root/.config/composer/auth.json
{
"bitbucket-oauth": {},
"github-oauth": {"github.com":"ghp_6fomvltWFs6KAZxxx"},
"gitlab-oauth": {},
"gitlab-token": {},
"http-basic": {},
"bearer": {}
}
(2)镜像式安装环境
制作相应php环境镜像Dockerfile:
FROM php:8.2-fpm-alpine as build
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions open-telemetry/opentelemetry-php-instrumentation@1.0.0beta2
运行镜像,验证环境:
docker run -it -d --name centos3 -p 5023:22 -p 8088:80 --privileged=true oh_myphp:1.0.0 /sbin/init
docker exec -it centos3 /bin/sh
php -m | grep otel_instrumentation
接入设置环境
OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_SERVICE_NAME=your-service-name \
OTEL_TRACES_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317 \
OTEL_PROPAGATORS=baggage,tracecontext \
写入代码接入Example:
<?php
OpenTelemetry\Instrumentation\hook(
'class': DemoClass::class,
'function': 'run',
'pre': static function (DemoClass $demo, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($tracer) {
static $instrumentation;
$instrumentation ??= new CachedInstrumentation('example');
$instrumentation->tracer()->spanBuilder($class)
->startSpan()
->activate();
},
'post': static function (DemoClass $demo, array $params, $returnValue, ?Throwable $exception) use ($tracer) {
$scope = Context::storage()->scope();
$scope->detach();
$span = Span::fromContext($scope->context());
if ($exception) {
$span->recordException($exception);
$span->setStatus(StatusCode::STATUS_ERROR);
}
$span->end();
}
);
$demo = new DemoClass();
$demo->run();
参考: