Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| ObservabilityOrchestrator | |
0.00% |
0 / 45 |
|
0.00% |
0 / 8 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| captureException | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| log | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| incident | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| broadcastException | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| broadcastLog | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| broadcastIncident | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| normalize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Modules\SupportModule\Services; |
| 4 | |
| 5 | use Throwable; |
| 6 | |
| 7 | class ObservabilityOrchestrator |
| 8 | { |
| 9 | public function __construct( |
| 10 | protected GlitchTipService $glitchTip, |
| 11 | protected SigNozService $signoz, |
| 12 | protected OpenObservableService $openObserve |
| 13 | ) {} |
| 14 | |
| 15 | /** |
| 16 | * Exception |
| 17 | */ |
| 18 | public function captureException(Throwable $e, array $context = []): void |
| 19 | { |
| 20 | $payload = $this->normalize([ |
| 21 | 'type' => 'exception', |
| 22 | 'message' => $e->getMessage(), |
| 23 | 'trace' => $e->getTraceAsString(), |
| 24 | 'context' => $context, |
| 25 | ]); |
| 26 | |
| 27 | $this->broadcastException($e, $payload); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Log métier |
| 32 | */ |
| 33 | public function log(string $message, array $context = []): void |
| 34 | { |
| 35 | $payload = $this->normalize([ |
| 36 | 'type' => 'log', |
| 37 | 'message' => $message, |
| 38 | 'context' => $context, |
| 39 | ]); |
| 40 | |
| 41 | $this->broadcastLog($payload); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Incident |
| 46 | */ |
| 47 | public function incident(array $payload): void |
| 48 | { |
| 49 | $payload = $this->normalize(array_merge([ |
| 50 | 'type' => 'incident', |
| 51 | ], $payload)); |
| 52 | |
| 53 | $this->broadcastIncident($payload); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * FAN OUT Exception |
| 58 | */ |
| 59 | protected function broadcastException(Throwable $e, array $payload): void |
| 60 | { |
| 61 | try { |
| 62 | $this->glitchTip->captureException($e); |
| 63 | } catch (Throwable) {} |
| 64 | |
| 65 | try { |
| 66 | $this->signoz->sendTrace([ |
| 67 | 'name' => 'exception', |
| 68 | 'status' => 'error', |
| 69 | 'duration_ms' => 0, |
| 70 | ]); |
| 71 | } catch (Throwable) {} |
| 72 | |
| 73 | try { |
| 74 | $this->openObserve->trace('exception', fn() => null, $payload); |
| 75 | } catch (Throwable) {} |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * FAN OUT Log |
| 80 | */ |
| 81 | protected function broadcastLog(array $payload): void |
| 82 | { |
| 83 | try { |
| 84 | $this->signoz->sendTrace([ |
| 85 | 'name' => 'log', |
| 86 | 'status' => 'info', |
| 87 | 'duration_ms' => 0, |
| 88 | ]); |
| 89 | } catch (Throwable) {} |
| 90 | |
| 91 | try { |
| 92 | $this->openObserve->trace('log', fn() => null, $payload); |
| 93 | } catch (Throwable) {} |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * FAN OUT Incident |
| 98 | */ |
| 99 | protected function broadcastIncident(array $payload): void |
| 100 | { |
| 101 | try { |
| 102 | $this->glitchTip->captureMessage($payload['message'] ?? 'incident', 'error'); |
| 103 | } catch (Throwable) {} |
| 104 | |
| 105 | try { |
| 106 | $this->openObserve->trace('incident', fn() => null, $payload); |
| 107 | } catch (Throwable) {} |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Normalisation unique |
| 112 | */ |
| 113 | protected function normalize(array $data): array |
| 114 | { |
| 115 | return array_merge($data, [ |
| 116 | 'user_id' => session()->get('user_id'), |
| 117 | 'url' => current_url(), |
| 118 | 'timestamp' => date('c'), |
| 119 | ]); |
| 120 | } |
| 121 | } |