build(monitoring): implement open-telemetry support
This commit is contained in:
parent
4361655127
commit
0bff14f820
@ -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
995
composer.lock
generated
File diff suppressed because it is too large
Load Diff
10
config/packages/http_discovery.yaml
Normal file
10
config/packages/http_discovery.yaml
Normal 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
|
@ -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"
|
||||||
|
35
src/Bridge/Monolog/Handler/SymfonyOtelHandler.php
Normal file
35
src/Bridge/Monolog/Handler/SymfonyOtelHandler.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
12
symfony.lock
12
symfony.lock
@ -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": {
|
||||||
|
Loading…
Reference in New Issue
Block a user