Skip to content

Transporters ​

Transporters determine how events are sent from your application to Nadi.

Available Transporters ​

TransporterDescriptionUse Case
fileWrite to local log filesProduction (recommended)
httpSend directly via HTTPSimple setups, testing

The file transporter writes events to local log files. The Shipper agent then reads these files and sends them to Nadi.

Why File Transport? ​

  • Non-blocking - Writing to files is fast
  • Resilient - Events are queued locally if network is unavailable
  • No request overhead - Doesn't add latency to your application
  • Reliable - Shipper handles retries and delivery confirmation

Configuration ​

php
$client = new Client([
    'transporter' => 'file',
    'storagePath' => '/var/log/nadi',
]);

Credentials in nadi.yaml

When using the file transporter, API credentials are configured in nadi.yaml for the Shipper agent, not in your application code. See Shipper Configuration for details.

Log File Format ​

Events are written as JSON, one per line:

json
{"type":"exception","message":"Error occurred","timestamp":"2024-01-15T10:30:00Z",...}
{"type":"exception","message":"Another error","timestamp":"2024-01-15T10:31:00Z",...}

Log File Naming ​

Files are named by date: nadi-YYYY-MM-DD.log

/var/log/nadi/
├── nadi-2024-01-15.log
├── nadi-2024-01-14.log
└── nadi-2024-01-13.log

Directory Setup ​

Ensure the directory exists and is writable:

bash
sudo mkdir -p /var/log/nadi
sudo chown www-data:www-data /var/log/nadi
sudo chmod 755 /var/log/nadi

Log Rotation ​

Shipper handles cleanup of old logs. Configure in nadi.yaml:

yaml
nadi:
  persistent: false  # Delete logs after sending

Or keep logs for backup:

yaml
nadi:
  persistent: true  # Keep logs after sending

HTTP Transporter ​

The HTTP transporter sends events directly to Nadi via HTTP requests.

Configuration ​

php
$client = new Client([
    'apiKey' => getenv('NADI_API_KEY'),
    'appKey' => getenv('NADI_APP_KEY'),
    'transporter' => 'http',
    'endpoint' => 'https://nadi.pro/api/',
    'timeout' => 5,
]);

When to Use HTTP Transport ​

  • Testing - Quick setup without Shipper
  • Serverless - Lambda, Cloud Functions
  • Low volume - Few events per day
  • Simple deployments - Single server, simple setup

Limitations ​

  • Blocking - Adds latency to requests
  • No retry - Failed requests are lost
  • Network dependent - Fails if network is down

Timeout Configuration ​

php
[
    'timeout' => 5,        // Connection timeout (seconds)
    'connectTimeout' => 2, // TCP connect timeout (seconds)
]

Custom Transporters ​

Create custom transporters for special requirements.

Interface ​

php
<?php

namespace Nadi\Transport;

interface TransporterInterface
{
    public function send(array $event): bool;
    public function flush(): void;
}

Example: Queue Transporter ​

Send events via a message queue:

php
<?php

namespace App\Nadi;

use Nadi\Transport\TransporterInterface;

class QueueTransporter implements TransporterInterface
{
    private $queue;

    public function __construct($queueConnection)
    {
        $this->queue = $queueConnection;
    }

    public function send(array $event): bool
    {
        return $this->queue->push('nadi_events', json_encode($event));
    }

    public function flush(): void
    {
        // Flush the queue buffer if needed
    }
}

Registration ​

php
use App\Nadi\QueueTransporter;

$transporter = new QueueTransporter($redisConnection);

$client = new Client([
    'transporter' => 'file',
    'storagePath' => '/var/log/nadi',
]);

$client->setTransporter($transporter);

Example: Multi Transporter ​

Send to multiple destinations:

php
<?php

namespace App\Nadi;

use Nadi\Transport\TransporterInterface;

class MultiTransporter implements TransporterInterface
{
    private array $transporters;

    public function __construct(array $transporters)
    {
        $this->transporters = $transporters;
    }

    public function send(array $event): bool
    {
        $success = true;
        foreach ($this->transporters as $transporter) {
            if (!$transporter->send($event)) {
                $success = false;
            }
        }
        return $success;
    }

    public function flush(): void
    {
        foreach ($this->transporters as $transporter) {
            $transporter->flush();
        }
    }
}

Transporter Comparison ​

FeatureFileHTTP
Latency ImpactNone~50-500ms
ReliabilityHighMedium
Network RequiredNo (at capture)Yes
Requires ShipperYesNo
Retry on FailureYes (via Shipper)No
Batch ProcessingYesNo
Offline SupportYesNo

Troubleshooting ​

File Transporter Issues ​

Permission denied:

bash
sudo chown www-data:www-data /var/log/nadi
sudo chmod 755 /var/log/nadi

Disk full:

bash
# Check disk space
df -h /var/log/nadi

# Check log size
du -sh /var/log/nadi/*

Logs not being sent:

  • Verify Shipper is running
  • Check Shipper configuration
  • Review Shipper logs

HTTP Transporter Issues ​

Timeout errors:

php
[
    'timeout' => 10,  // Increase timeout
]

SSL/TLS errors:

php
[
    'verifySsl' => true,  // Ensure certificates are valid
]

Connection refused:

  • Check network connectivity
  • Verify endpoint URL
  • Check firewall rules

Next Steps ​

Released under the MIT License.