feat: add support for OTEL logs
feat: add support for OTEL logs
This commit is contained in:
parent
1a3cf1c2e0
commit
192cfb9b73
@ -3,3 +3,4 @@ TODO:
|
||||
- [ ] Chybí speciální slovník nebo vypnutí slovníku pro testy
|
||||
- [ ] V reálný aplikaci bych použil Mockery, nicméně tady mě to přijde zbytečný
|
||||
- [ ] Nastavení cache ideálně v memcached/redis etc.
|
||||
- [ ] Vylepsit OTEL logs
|
||||
|
@ -13,6 +13,7 @@
|
||||
"nyholm/psr7": "*",
|
||||
"open-telemetry/exporter-otlp": "^1.0",
|
||||
"open-telemetry/opentelemetry-auto-symfony": "^1.0@beta",
|
||||
"open-telemetry/opentelemetry-logger-monolog": "^1.0",
|
||||
"open-telemetry/opentelemetry-propagation-server-timing": "^0.0.1",
|
||||
"open-telemetry/opentelemetry-propagation-traceresponse": "^0.0.2",
|
||||
"open-telemetry/sdk": "^1.0",
|
||||
|
60
composer.lock
generated
60
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "15e05e23293f0f945b50f450fe8213c3",
|
||||
"content-hash": "a62a11e50f44a0e917cf2ab753b0a5d8",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/semver",
|
||||
@ -761,6 +761,64 @@
|
||||
},
|
||||
"time": "2023-12-12T11:41:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "open-telemetry/opentelemetry-logger-monolog",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/opentelemetry-php/contrib-logger-monolog.git",
|
||||
"reference": "da70f3678aba1e8187f889e78f3a2a55f43f6395"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/opentelemetry-php/contrib-logger-monolog/zipball/da70f3678aba1e8187f889e78f3a2a55f43f6395",
|
||||
"reference": "da70f3678aba1e8187f889e78f3a2a55f43f6395",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"monolog/monolog": "^1.1|^2|^3",
|
||||
"open-telemetry/api": "^1.0.0beta16"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3",
|
||||
"google/protobuf": ">=3.5.0",
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"nyholm/psr7": "^1.6",
|
||||
"open-telemetry/exporter-otlp": ">=1.0.0beta6",
|
||||
"open-telemetry/sdk": ">=1.0.0beta7",
|
||||
"phan/phan": "^5.0",
|
||||
"phpbench/phpbench": "^1.2",
|
||||
"phpstan/phpstan": "^1.1",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"psalm/plugin-phpunit": "^0.16",
|
||||
"vimeo/psalm": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"OpenTelemetry\\Contrib\\Logs\\Monolog\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"description": "OpenTelemetry Monolog handler.",
|
||||
"homepage": "https://opentelemetry.io",
|
||||
"keywords": [
|
||||
"handler",
|
||||
"logs",
|
||||
"monolog",
|
||||
"open-telemetry",
|
||||
"opentelemetry",
|
||||
"otel"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/opentelemetry-php/contrib-logger-monolog/tree/1.0.0"
|
||||
},
|
||||
"time": "2023-10-17T21:44:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "open-telemetry/opentelemetry-propagation-server-timing",
|
||||
"version": "0.0.1",
|
||||
|
@ -5,6 +5,10 @@ monolog:
|
||||
when@dev:
|
||||
monolog:
|
||||
handlers:
|
||||
otel: # Tohle bych v realny aplikaci nepouzil na devu
|
||||
type: service
|
||||
id: App\Bridge\Monolog\Handler\SymfonyOtelHandler
|
||||
|
||||
main:
|
||||
type: stream
|
||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||
@ -40,6 +44,9 @@ when@test:
|
||||
when@prod:
|
||||
monolog:
|
||||
handlers:
|
||||
otel:
|
||||
type: service
|
||||
id: App\Bridge\Monolog\Handler\SymfonyOtelHandler
|
||||
main:
|
||||
type: fingers_crossed
|
||||
action_level: error
|
||||
|
@ -45,6 +45,7 @@ services:
|
||||
$innerGenerator: '@App\Service\Remote\UsetrenoQRCodeProvider'
|
||||
$cacheDuration: 'PT60S'
|
||||
|
||||
|
||||
App\Service\CurrencyListerInterface: '@App\Service\StaticCurrencyLister'
|
||||
App\Service\QRCodeQROptionsProviderInterface: '@App\Service\QRCodeQROptionsDefaultProvider'
|
||||
App\Service\QRCodeGeneratorInterface: '@App\Service\CachedQRCodeGenerator'
|
||||
|
@ -11,22 +11,40 @@ processors:
|
||||
actions:
|
||||
- action: insert
|
||||
key: loki.attribute.labels
|
||||
value: log.file, log.line, log.module_path, http.request_id, http.uri
|
||||
value: context, code.filepath, code.namespace, code.function, code.lineno, http.request.method, http.request.body.size, url.full, url.scheme, url.path, http.route, http.response.status_code
|
||||
- action: insert
|
||||
from_attribute: log.file
|
||||
key: log.file
|
||||
from_attribute: context
|
||||
key: context
|
||||
- action: insert
|
||||
from_attribute: log.line
|
||||
key: log.line
|
||||
from_attribute: code.namespace
|
||||
key: code.namespace
|
||||
- action: insert
|
||||
from_attribute: log.module_path
|
||||
key: log.module_path
|
||||
from_attribute: code.function
|
||||
key: code.function
|
||||
- action: insert
|
||||
from_attribute: http.request_id
|
||||
key: http.request_id
|
||||
from_attribute: code.lineno
|
||||
key: code.lineno
|
||||
- action: insert
|
||||
from_attribute: http.uri
|
||||
key: http.uri
|
||||
from_attribute: http.request.method
|
||||
key: http.request.method
|
||||
- action: insert
|
||||
from_attribute: http.request.body.size
|
||||
key: http.request.body.size
|
||||
- action: insert
|
||||
from_attribute: http.response.status_code
|
||||
key: http.response.status_code
|
||||
- action: insert
|
||||
from_attribute: url.full
|
||||
key: url.full
|
||||
- action: insert
|
||||
from_attribute: url.scheme
|
||||
key: url.scheme
|
||||
- action: insert
|
||||
from_attribute: url.path
|
||||
key: url.path
|
||||
- action: insert
|
||||
from_attribute: http.route
|
||||
key: http.route
|
||||
- action: insert
|
||||
key: loki.format
|
||||
value: raw
|
||||
|
33
src/Bridge/Monolog/Handler/SymfonyOtelHandler.php
Normal file
33
src/Bridge/Monolog/Handler/SymfonyOtelHandler.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bridge\Monolog\Handler;
|
||||
|
||||
use Monolog\Formatter\FormatterInterface;
|
||||
use Monolog\Formatter\JsonFormatter;
|
||||
use Monolog\Handler\AbstractHandler;
|
||||
use Monolog\Handler\FormattableHandlerTrait;
|
||||
use Monolog\LogRecord;
|
||||
use OpenTelemetry\API\Globals;
|
||||
use OpenTelemetry\Contrib\Logs\Monolog\Handler;
|
||||
use Psr\Log\LogLevel;
|
||||
use Symfony\Bridge\Monolog\Formatter\VarDumperFormatter;
|
||||
|
||||
final class SymfonyOtelHandler extends AbstractHandler
|
||||
{
|
||||
protected 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user