<?php

declare(strict_types=1);

namespace App\Framework\Tracing\Exporters;

use App\Framework\Tracing\TraceExporter;

final readonly class FileTraceExporter implements TraceExporter
{
    public function __construct(
        private string $filePath
    ) {
    }

    public function export(array $traceData): void
    {
        $json = json_encode($traceData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
        $line = $json . "\n";

        file_put_contents($this->filePath, $line, FILE_APPEND | LOCK_EX);
    }
}
