Php sdk
PHP SDK
Get started with the VedaTrace SDK for PHP and Laravel.
Installation
Install the VedaTrace PHP SDK using Composer:
composer require vedatrace/vedatrace-phpRequirements
- PHP 8.2 or higher
- PSR-3 Log implementation (included)
- Guzzle HTTP Client (included)
Post-Installation
The SDK comes with a global helper function vedatrace() which is automatically loaded by Composer's autoloader:
require_once 'vendor/autoload.php';Quickstart
To get started, use the vedatrace() global helper or the VedaTrace::create() factory method:
use VedaTrace\VedaTrace;
$logger = VedaTrace::create([
'apiKey' => 'your-api-key',
'service' => 'my-app-name',
]);
$logger->info('Service started', ['env' => 'production']);Global Helper
The vedatrace() helper is a convenient shorthand:
use function VedaTrace\vedatrace;
$logger = vedatrace(['apiKey' => 'your-api-key']);
$logger->info('Hello, VedaTrace!');Logging Messages
The logger implements Psr\Log\LoggerInterface, providing standard logging methods:
$logger->debug('Debugging message');
$logger->info('Informational message');
$logger->warn('Warning message');
$logger->error('Error message');
$logger->fatal('Fatal error message');Context Data
Pass an optional associative array as context — it will be automatically nested under metadata in VedaTrace:
$logger->info('User login successful', [
'user_id' => 123,
'ip_address' => '127.0.0.1',
]);Disposing the Logger
VedaTrace batches logs to optimize performance. In long-running processes, flushing happens automatically. For standalone CLI scripts, call dispose() to ensure all buffered logs are sent:
$logger->info('Script finished');
$logger->dispose(); // Flush and close