build(monitoring): implement open-telemetry support

This commit is contained in:
Ondrej Vlach 2024-08-03 19:30:13 +02:00
parent 4361655127
commit 0bff14f820
No known key found for this signature in database
GPG Key ID: 7F141CDACEDEE2DE
6 changed files with 1061 additions and 2 deletions

View File

@ -12,7 +12,14 @@
"doctrine/doctrine-migrations-bundle": "^3.3", "doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.2", "doctrine/orm": "^3.2",
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",
"grpc/grpc": "^1.57",
"nubium/this-should-never-happen-exception": "^1.0", "nubium/this-should-never-happen-exception": "^1.0",
"nyholm/psr7": "^1.8",
"open-telemetry/exporter-otlp": "^1.0",
"open-telemetry/opentelemetry-auto-symfony": "1.0.0beta27",
"open-telemetry/opentelemetry-logger-monolog": "^1.0",
"open-telemetry/sdk": "^1.0",
"open-telemetry/transport-grpc": "^1.0",
"phpdocumentor/reflection-docblock": "^5.4", "phpdocumentor/reflection-docblock": "^5.4",
"phpstan/phpdoc-parser": "^1.29", "phpstan/phpdoc-parser": "^1.29",
"symfony/asset": "7.1.*", "symfony/asset": "7.1.*",

995
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
services:
Psr\Http\Message\RequestFactoryInterface: '@http_discovery.psr17_factory'
Psr\Http\Message\ResponseFactoryInterface: '@http_discovery.psr17_factory'
Psr\Http\Message\ServerRequestFactoryInterface: '@http_discovery.psr17_factory'
Psr\Http\Message\StreamFactoryInterface: '@http_discovery.psr17_factory'
Psr\Http\Message\UploadedFileFactoryInterface: '@http_discovery.psr17_factory'
Psr\Http\Message\UriFactoryInterface: '@http_discovery.psr17_factory'
http_discovery.psr17_factory:
class: Http\Discovery\Psr17Factory

View File

@ -4,7 +4,11 @@ monolog:
when@dev: when@dev:
monolog: monolog:
handlers: handlers:
otel:
type: service # I wouldn't use this in a real application in @dev environment
id: App\Bridge\Monolog\Handler\SymfonyOtelHandler
main: main:
type: stream type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log" path: "%kernel.logs_dir%/%kernel.environment%.log"

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Bridge\Monolog\Handler;
use Monolog\Handler\AbstractHandler;
use Monolog\LogRecord;
use OpenTelemetry\API\Globals;
use OpenTelemetry\Contrib\Logs\Monolog\Handler;
use Psr\Log\LogLevel;
/**
* This handler will send logs to OpenTelemetry using the Monolog adapter.
*/
final class SymfonyOtelHandler extends AbstractHandler
{
private readonly Handler $innerHandler;
public function __construct()
{
parent::__construct();
$this->innerHandler = new Handler(
Globals::loggerProvider(),
LogLevel::INFO, //or `Logger::INFO`, or `Level::Info` depending on monolog version
true,
);
}
public function handle(LogRecord $record): bool
{
return $this->innerHandler->handle($record);
}
}

View File

@ -26,6 +26,18 @@
"migrations/.gitignore" "migrations/.gitignore"
] ]
}, },
"php-http/discovery": {
"version": "1.19",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.18",
"ref": "f45b5dd173a27873ab19f5e3180b2f661c21de02"
},
"files": [
"config/packages/http_discovery.yaml"
]
},
"phpstan/phpstan": { "phpstan/phpstan": {
"version": "1.11", "version": "1.11",
"recipe": { "recipe": {