zero-code計装シリーズも終盤、PHPでのzero-code計装をやってみる。
kmuto.hatenablog.com kmuto.hatenablog.com kmuto.hatenablog.com kmuto.hatenablog.com
いつものように雑なWebサーバーを立てる。まぁフレームワーク前提だよねということで、ユーザーも多そうなLaravel。大昔にSymphonyしか触わったことがないので初見。
DBはPostgreSQLにしてみる。
apt-get install composer php-pear php8.2-dev php-pgsql
Laravelのプロジェクト作成。デフォルトはsqlite3を使うみたいで、マイグレーション失敗のWARNINGが出た。
composer create-project laravel/laravel hello-world-app cd hello-world-app
DB設定のために.envファイルを編集する(ローカル用でパスワードなどが雑)。
DB_CONNECTION=pgsql DB_HOST=127.0.0.1 DB_PORT=5432 DB_DATABASE=laravel_hello_world DB_USERNAME=laravel DB_PASSWORD=laravel
PostgreSQLのほうでも対応するDBを準備しておく。
CREATE DATABASE laravel_hello_world; CREATE USER laravel WITH PASSWORD 'laravel'; GRANT ALL PRIVILEGES ON DATABASE laravel_hello_world TO laravel; \c laravel_hello_world GRANT USAGE, CREATE ON SCHEMA public TO laravel;
SCHEMAはこう設定しないとLaravelで作れなかったので。よくはわかっていない。
マイグレーションを実行。
php artisan migrate
ルーティングファイルroutes/web.phpにHello Worldと、例外発生、ステータスコード500返答を仕込む。
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return 'Hello World';
});
Route::get('/error', function () {
1 / 0;
});
Route::get('/500', function () {
abort(500, 'Internal Server Error');
});
例外起こすのが連載通してどんどん雑になってきているけど、0除算(静的評価されるとこれダメなんだよねぇ)。
とりあえず起動して期待どおりかテストする。デフォルトは8000ポートで起動する。
php artisan serve
curlから叩いてみると
$ curl http://localhost:8000
Hello World
$ curl http://localhost:8000/error
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<title>Laravel</title>
...
100 98304 0 98304 0 0 891k 0 --:--:-- --:--:-- --:--:-- 888k
curl: (23) Failure writing output to destination
$ curl http://localhost:8000/500
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
...
1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}}
OpenTelemetry Collectorをいつものように用意し、実行しておく。
receivers:
otlp:
protocols:
http:
exporters:
debug:
verbosity: detailed
service:
pipelines:
metrics:
receivers: [otlp]
exporters: [debug]
logs:
receivers: [otlp]
exporters: [debug]
traces:
receivers: [otlp]
exporters: [debug]
PHPのzero-code計装はやや複雑な印象。まずOpenTelemetry Extensionをビルドする必要がある。RPMとAPKはパッケージがあるが、それ以外のOSではpeclかpickleを使う。これもしかしてWindowsだと動かないってやつかも。
とりあえずpeclでやってみる。
sudo pecl install opentelemetry
opentelemetry.soファイルができてインストールされるので、有効化されるよう/etc/php/8.2/cli/conf.d/99-opentelemetry.iniを作る。
[opentelemetry] extension=opentelemetry.so
これはベースができただけなので、対象に計装するにはSDKやライブラリに対応する計装パッケージを追加する必要があるようだ。今回は以下のようにした。
composer require open-telemetry/sdk open-telemetry/opentelemetry-auto-laravel open-telemetry/exporter-otlp
exporter-otlpが必要なのがちょっと罠だった。リストを見るとSymphonyやSlimのほか、WordPressなども。
Do you trust "tbachert/spi" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
はnでいいんだろうか。
ではzero-code計装で実行。OTEL_PHP_AUTOLOAD_ENABLED=trueで有効化されるので、わかりやすい。
OTEL_PHP_AUTOLOAD_ENABLED=true OTEL_SERVICE_NAME=php-zerocode php artisan serve
curlを叩いて、トレースを送る。
2025-01-26T23:08:18.602+0900 info Traces {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 4}
2025-01-26T23:08:18.602+0900 info ResourceSpans #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.27.0
Resource attributes:
-> host.name: Str(...)
-> host.arch: Str(x86_64)
-> host.id: Str(86fdb17091114232ba104aea4bc5250d)
-> os.type: Str(linux)
-> os.description: Str(6.1.0-30-amd64)
-> os.name: Str(Linux)
-> os.version: Str(#1 SMP PREEMPT_DYNAMIC Debian 6.1.124-1 (2025-01-12))
-> process.pid: Int(848077)
-> process.executable.path: Str(/usr/bin/php8.2)
-> process.owner: Str(kmuto)
-> process.runtime.name: Str(cli-server)
-> process.runtime.version: Str(8.2.26)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(php)
-> telemetry.sdk.version: Str(1.2.0)
-> telemetry.distro.name: Str(opentelemetry-php-instrumentation)
-> telemetry.distro.version: Str(1.1.2)
-> service.name: Str(php-zerocode)
-> service.version: Str(1.0.0+no-version-set)
ScopeSpans #0
ScopeSpans SchemaURL: https://opentelemetry.io/schemas/1.24.0
InstrumentationScope io.opentelemetry.contrib.php.laravel
Span #0
Trace ID : 3d4f2ba3e710aebed390dac187d5eb05
Parent ID : 947b9b1df3b43ccc
ID : 9f46dbf889c30c2d
Name : sql SELECT
Kind : Client
Start time : 2025-01-26 14:08:18.561135104 +0000 UTC
End time : 2025-01-26 14:08:18.572734976 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(SELECT)
-> db.user: Str(laravel)
-> db.statement: Str(select * from "sessions" where "id" = ? limit 1)
Span #1
Trace ID : 3d4f2ba3e710aebed390dac187d5eb05
Parent ID : 947b9b1df3b43ccc
ID : 282c12089b375083
Name : sql SELECT
Kind : Client
Start time : 2025-01-26 14:08:18.581395968 +0000 UTC
End time : 2025-01-26 14:08:18.581725952 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(SELECT)
-> db.user: Str(laravel)
-> db.statement: Str(select * from "sessions" where "id" = ? limit 1)
Span #2
Trace ID : 3d4f2ba3e710aebed390dac187d5eb05
Parent ID : 947b9b1df3b43ccc
ID : c653096a13be530e
Name : sql INSERT
Kind : Client
Start time : 2025-01-26 14:08:18.58180992 +0000 UTC
End time : 2025-01-26 14:08:18.584399872 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(INSERT)
-> db.user: Str(laravel)
-> db.statement: Str(insert into "sessions" ("payload", "last_activity", "user_id", "ip_address", "user_agent", "id") values (?, ?, ?, ?, ?, ?))
Span #3
Trace ID : 3d4f2ba3e710aebed390dac187d5eb05
Parent ID :
ID : 947b9b1df3b43ccc
Name : GET /
Kind : Server
Start time : 2025-01-26 14:08:18.476215131 +0000 UTC
End time : 2025-01-26 14:08:18.584681958 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> code.function: Str(handle)
-> code.namespace: Str(Illuminate\Foundation\Http\Kernel)
-> code.filepath: Str(/home/kmuto/php-zerocode/hello-world-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php)
-> code.lineno: Int(138)
-> url.full: Str(http://localhost:8000)
-> http.request.method: Str(GET)
-> url.scheme: Str(http)
-> network.protocol.version: Str(1.1)
-> network.peer.address: Str(127.0.0.1)
-> url.path: Str(/)
-> server.address: Str(localhost)
-> server.port: Int(8000)
-> client.port: Str(36044)
-> user_agent.original: Str(curl/7.88.1)
-> http.route: Str(/)
-> http.response.status_code: Int(200)
{"kind": "exporter", "data_type": "traces", "name": "debug"}
2025-01-26T23:08:22.906+0900 info Logs {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 1, "log records": 1}
2025-01-26T23:08:22.906+0900 info ResourceLog #0
Resource SchemaURL:
Resource attributes:
-> host.name: Str(...)
-> host.arch: Str(x86_64)
-> host.id: Str(86fdb17091114232ba104aea4bc5250d)
-> os.type: Str(linux)
-> os.description: Str(6.1.0-30-amd64)
-> os.name: Str(Linux)
-> os.version: Str(#1 SMP PREEMPT_DYNAMIC Debian 6.1.124-1 (2025-01-12))
-> process.pid: Int(848079)
-> process.executable.path: Str(/usr/bin/php8.2)
-> process.owner: Str(kmuto)
-> process.runtime.name: Str(cli-server)
-> process.runtime.version: Str(8.2.26)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(php)
-> telemetry.sdk.version: Str(1.2.0)
-> telemetry.distro.name: Str(opentelemetry-php-instrumentation)
-> telemetry.distro.version: Str(1.1.2)
-> service.name: Str(php-zerocode)
-> service.version: Str(1.0.0+no-version-set)
ScopeLogs #0
ScopeLogs SchemaURL: https://opentelemetry.io/schemas/1.24.0
InstrumentationScope io.opentelemetry.contrib.php.laravel
LogRecord #0
ObservedTimestamp: 2025-01-26 14:08:22.827527936 +0000 UTC
Timestamp: 1970-01-01 00:00:00 +0000 UTC
SeverityText: error
SeverityNumber: Error(17)
Body: Str(Division by zero)
Attributes:
-> context: Str({"exception":{}})
Trace ID: 90de68340f9885fa382cee66ba8530e7
Span ID: 99f91f836e892c6d
Flags: 1
{"kind": "exporter", "data_type": "logs", "name": "debug"}
2025-01-26T23:08:22.911+0900 info Traces {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 4}
2025-01-26T23:08:22.911+0900 info ResourceSpans #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.27.0
Resource attributes:
-> host.name: Str(...)
-> host.arch: Str(x86_64)
-> host.id: Str(86fdb17091114232ba104aea4bc5250d)
-> os.type: Str(linux)
-> os.description: Str(6.1.0-30-amd64)
-> os.name: Str(Linux)
-> os.version: Str(#1 SMP PREEMPT_DYNAMIC Debian 6.1.124-1 (2025-01-12))
-> process.pid: Int(848079)
-> process.executable.path: Str(/usr/bin/php8.2)
-> process.owner: Str(kmuto)
-> process.runtime.name: Str(cli-server)
-> process.runtime.version: Str(8.2.26)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(php)
-> telemetry.sdk.version: Str(1.2.0)
-> telemetry.distro.name: Str(opentelemetry-php-instrumentation)
-> telemetry.distro.version: Str(1.1.2)
-> service.name: Str(php-zerocode)
-> service.version: Str(1.0.0+no-version-set)
ScopeSpans #0
ScopeSpans SchemaURL: https://opentelemetry.io/schemas/1.24.0
InstrumentationScope io.opentelemetry.contrib.php.laravel
Span #0
Trace ID : 90de68340f9885fa382cee66ba8530e7
Parent ID : 99f91f836e892c6d
ID : a92c837bcacac6a9
Name : sql SELECT
Kind : Client
Start time : 2025-01-26 14:08:22.8019648 +0000 UTC
End time : 2025-01-26 14:08:22.816504832 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(SELECT)
-> db.user: Str(laravel)
-> db.statement: Str(select * from "sessions" where "id" = ? limit 1)
Span #1
Trace ID : 90de68340f9885fa382cee66ba8530e7
Parent ID : 99f91f836e892c6d
ID : 32eaaaa96555afe8
Name : sql SELECT
Kind : Client
Start time : 2025-01-26 14:08:22.899186944 +0000 UTC
End time : 2025-01-26 14:08:22.899617024 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(SELECT)
-> db.user: Str(laravel)
-> db.statement: Str(select * from "sessions" where "id" = ? limit 1)
Span #2
Trace ID : 90de68340f9885fa382cee66ba8530e7
Parent ID : 99f91f836e892c6d
ID : de58c4891e6175de
Name : sql INSERT
Kind : Client
Start time : 2025-01-26 14:08:22.899713024 +0000 UTC
End time : 2025-01-26 14:08:22.901542912 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(INSERT)
-> db.user: Str(laravel)
-> db.statement: Str(insert into "sessions" ("payload", "last_activity", "user_id", "ip_address", "user_agent", "id") values (?, ?, ?, ?, ?, ?))
Span #3
Trace ID : 90de68340f9885fa382cee66ba8530e7
Parent ID :
ID : 99f91f836e892c6d
Name : GET /error
Kind : Server
Start time : 2025-01-26 14:08:22.794552067 +0000 UTC
End time : 2025-01-26 14:08:22.901732926 +0000 UTC
Status code : Error
Status message :
Attributes:
-> code.function: Str(handle)
-> code.namespace: Str(Illuminate\Foundation\Http\Kernel)
-> code.filepath: Str(/home/kmuto/php-zerocode/hello-world-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php)
-> code.lineno: Int(138)
-> url.full: Str(http://localhost:8000/error)
-> http.request.method: Str(GET)
-> url.scheme: Str(http)
-> network.protocol.version: Str(1.1)
-> network.peer.address: Str(127.0.0.1)
-> url.path: Str(error)
-> server.address: Str(localhost)
-> server.port: Int(8000)
-> client.port: Str(36056)
-> user_agent.original: Str(curl/7.88.1)
-> http.route: Str(error)
-> http.response.status_code: Int(500)
Events:
SpanEvent #0
-> Name: exception
-> Timestamp: 2025-01-26 14:08:22.826098822 +0000 UTC
-> DroppedAttributesCount: 0
-> Attributes::
-> exception.type: Str(DivisionByZeroError)
-> exception.message: Str(Division by zero)
-> exception.stacktrace: Str(DivisionByZeroError: Division by zero
at Illuminate.Routing.RouteFileRegistrar.{closure}(web.php:10)
at Illuminate.Routing.CallableDispatcher.dispatch(CallableDispatcher.php:40)
at Illuminate.Routing.Route.runCallable(Route.php:244)
at Illuminate.Routing.Route.run(Route.php:215)
at Illuminate.Routing.Router.Illuminate.Routing.{closure}(Router.php:808)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:170)
at Illuminate.Routing.Middleware.SubstituteBindings.handle(SubstituteBindings.php:51)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Foundation.Http.Middleware.VerifyCsrfToken.handle(VerifyCsrfToken.php:88)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.View.Middleware.ShareErrorsFromSession.handle(ShareErrorsFromSession.php:49)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Session.Middleware.StartSession.handleStatefulRequest(StartSession.php:121)
at Illuminate.Session.Middleware.StartSession.handle(StartSession.php:64)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Cookie.Middleware.AddQueuedCookiesToResponse.handle(AddQueuedCookiesToResponse.php:37)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Cookie.Middleware.EncryptCookies.handle(EncryptCookies.php:75)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Pipeline.Pipeline.then(Pipeline.php:127)
at Illuminate.Routing.Router.runRouteWithinStack(Router.php:807)
at Illuminate.Routing.Router.runRoute(Router.php:786)
at Illuminate.Routing.Router.dispatchToRoute(Router.php:750)
at Illuminate.Routing.Router.dispatch(Router.php:739)
at Illuminate.Foundation.Http.Kernel.Illuminate.Foundation.Http.{closure}(Kernel.php:201)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:170)
at Illuminate.Foundation.Http.Middleware.TransformsRequest.handle(TransformsRequest.php:21)
at Illuminate.Foundation.Http.Middleware.ConvertEmptyStringsToNull.handle(ConvertEmptyStringsToNull.php:31)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Foundation.Http.Middleware.TransformsRequest.handle(TransformsRequest.php:21)
at Illuminate.Foundation.Http.Middleware.TrimStrings.handle(TrimStrings.php:51)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Http.Middleware.ValidatePostSize.handle(ValidatePostSize.php:27)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Foundation.Http.Middleware.PreventRequestsDuringMaintenance.handle(PreventRequestsDuringMaintenance.php:110)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Http.Middleware.HandleCors.handle(HandleCors.php:49)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Http.Middleware.TrustProxies.handle(TrustProxies.php:58)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Foundation.Http.Middleware.InvokeDeferredCallbacks.handle(InvokeDeferredCallbacks.php:22)
at Illuminate.Pipeline.Pipeline.Illuminate.Pipeline.{closure}(Pipeline.php:209)
at Illuminate.Pipeline.Pipeline.then(Pipeline.php:127)
at Illuminate.Foundation.Http.Kernel.sendRequestThroughRouter(Kernel.php:176)
at Illuminate.Foundation.Http.Kernel.handle(Kernel.php:145)
at Illuminate.Foundation.Application.handleRequest(Application.php:1193)
at require_once(index.php:17)
at {main}(server.php:23))
-> exception.escaped: Bool(true)
{"kind": "exporter", "data_type": "traces", "name": "debug"}
2025-01-26T23:08:24.849+0900 info Traces {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 4}
2025-01-26T23:08:24.849+0900 info ResourceSpans #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.27.0
Resource attributes:
-> host.name: Str(...)
-> host.arch: Str(x86_64)
-> host.id: Str(86fdb17091114232ba104aea4bc5250d)
-> os.type: Str(linux)
-> os.description: Str(6.1.0-30-amd64)
-> os.name: Str(Linux)
-> os.version: Str(#1 SMP PREEMPT_DYNAMIC Debian 6.1.124-1 (2025-01-12))
-> process.pid: Int(848078)
-> process.executable.path: Str(/usr/bin/php8.2)
-> process.owner: Str(kmuto)
-> process.runtime.name: Str(cli-server)
-> process.runtime.version: Str(8.2.26)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(php)
-> telemetry.sdk.version: Str(1.2.0)
-> telemetry.distro.name: Str(opentelemetry-php-instrumentation)
-> telemetry.distro.version: Str(1.1.2)
-> service.name: Str(php-zerocode)
-> service.version: Str(1.0.0+no-version-set)
ScopeSpans #0
ScopeSpans SchemaURL: https://opentelemetry.io/schemas/1.24.0
InstrumentationScope io.opentelemetry.contrib.php.laravel
Span #0
Trace ID : 7f0e09261dd1fd7b615c6844089482b5
Parent ID : 58ade41ee832eae5
ID : dbfc50ada3a33725
Name : sql SELECT
Kind : Client
Start time : 2025-01-26 14:08:24.818509056 +0000 UTC
End time : 2025-01-26 14:08:24.83318912 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(SELECT)
-> db.user: Str(laravel)
-> db.statement: Str(select * from "sessions" where "id" = ? limit 1)
Span #1
Trace ID : 7f0e09261dd1fd7b615c6844089482b5
Parent ID : 58ade41ee832eae5
ID : 12fb5f4b020ec35e
Name : sql SELECT
Kind : Client
Start time : 2025-01-26 14:08:24.839294976 +0000 UTC
End time : 2025-01-26 14:08:24.83967488 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(SELECT)
-> db.user: Str(laravel)
-> db.statement: Str(select * from "sessions" where "id" = ? limit 1)
Span #2
Trace ID : 7f0e09261dd1fd7b615c6844089482b5
Parent ID : 58ade41ee832eae5
ID : 59d0af4a720849ec
Name : sql INSERT
Kind : Client
Start time : 2025-01-26 14:08:24.83978496 +0000 UTC
End time : 2025-01-26 14:08:24.842264832 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(pgsql)
-> db.name: Str(laravel_hello_world)
-> db.operation: Str(INSERT)
-> db.user: Str(laravel)
-> db.statement: Str(insert into "sessions" ("payload", "last_activity", "user_id", "ip_address", "user_agent", "id") values (?, ?, ?, ?, ?, ?))
Span #3
Trace ID : 7f0e09261dd1fd7b615c6844089482b5
Parent ID :
ID : 58ade41ee832eae5
Name : GET /500
Kind : Server
Start time : 2025-01-26 14:08:24.812321874 +0000 UTC
End time : 2025-01-26 14:08:24.842457809 +0000 UTC
Status code : Error
Status message :
Attributes:
-> code.function: Str(handle)
-> code.namespace: Str(Illuminate\Foundation\Http\Kernel)
-> code.filepath: Str(/home/kmuto/php-zerocode/hello-world-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php)
-> code.lineno: Int(138)
-> url.full: Str(http://localhost:8000/500)
-> http.request.method: Str(GET)
-> url.scheme: Str(http)
-> network.protocol.version: Str(1.1)
-> network.peer.address: Str(127.0.0.1)
-> url.path: Str(500)
-> server.address: Str(localhost)
-> server.port: Int(8000)
-> client.port: Str(36072)
-> user_agent.original: Str(curl/7.88.1)
-> http.route: Str(500)
-> http.response.status_code: Int(500)
{"kind": "exporter", "data_type": "traces", "name": "debug"}
単なるリクエストではあるがORM経由でDBクエリのスパンも送られており、だいぶそれっぽいのが書き出されていて楽しげな雰囲気がある。0除算例外を起こしたところはエラーイベントも出力されていた。
せっかくなので、Mackerelでもどう見えるのか送ってみよう。
OpenTelemetry Collectorの設定を変更。
...
processors:
resource/namespace:
attributes:
- key: service.namespace
value: "kmuto/php-zerocode"
action: upsert
batch:
send_batch_size: 5000
send_batch_max_size: 5000
exporters:
debug:
verbosity: detailed
otlphttp/vaxila:
endpoint: "https://otlp-vaxila.mackerelio.com"
headers:
Accept: "*/*"
"Mackerel-Api-Key": ${env:MACKEREL_APIKEY}
service:
...
traces:
receivers: [otlp]
processors: [resource/namespace, batch]
exporters: [debug, otlphttp/vaxila]
...
いいじゃん。


