PHP code example of rivium-trace / laravel-sdk
1. Go to this page and download the library: Download rivium-trace/laravel-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rivium-trace / laravel-sdk example snippets
use RiviumTrace\Laravel\RiviumTraceFacade as RiviumTrace;
try {
riskyOperation();
} catch (\Throwable $e) {
RiviumTrace::captureException($e, [
'extra' => ['order_id' => $orderId],
]);
}
RiviumTrace::captureMessage('Payment processed', [
'extra' => ['amount' => 99.99],
]);
use RiviumTrace\Laravel\Models\Breadcrumb;
RiviumTrace::addBreadcrumb(
Breadcrumb::custom('User signed up', 'auth', ['plan' => 'pro'])
);
RiviumTrace::addBreadcrumb(
Breadcrumb::http('POST', '/api/payments', 201, 450.5)
);
RiviumTrace::addBreadcrumb(
Breadcrumb::user('checkout_completed', ['items' => 3])
);
RiviumTrace::setUser([
'id' => $user->id,
'email' => $user->email,
'name' => $user->name,
]);
RiviumTrace::withScope(function ($scope) {
$scope->setUser(['id' => 'temp-user']);
processOrder($order);
});
'channels' => [
'riviumtrace' => [
'driver' => 'custom',
'via' => \RiviumTrace\Laravel\Logging\RiviumTraceLogChannel::class,
],
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'riviumtrace'],
],
],
Log::channel('riviumtrace')->info('Order created', ['order_id' => 123]);
Log::channel('riviumtrace')->error('Payment failed', ['reason' => 'declined']);
RiviumTrace::info('Processing started');
RiviumTrace::warn('Rate limit approaching', ['current' => 95, 'max' => 100]);
RiviumTrace::logError('External API timeout', ['service' => 'stripe']);
use RiviumTrace\Laravel\Performance\PerformanceSpan;
$result = RiviumTrace::trackOperation('process_payment', function () use ($order) {
return PaymentGateway::charge($order);
}, ['operationType' => 'custom', 'tags' => ['provider' => 'stripe']]);
RiviumTrace::reportPerformanceSpan(
PerformanceSpan::custom([
'operation' => 'generate_report',
'durationMs' => 1500,
'startTime' => $startTime,
'tags' => ['report_type' => 'monthly'],
])
);
RiviumTrace::reportPerformanceSpan(
PerformanceSpan::fromHttpRequest([
'method' => 'POST',
'url' => 'https://api.stripe.com/v1/charges',
'statusCode' => 200,
'durationMs' => 320,
'startTime' => $startTime,
])
);
'exception_handler' => [
'ignored_exceptions' => [
\App\Exceptions\BusinessException::class,
],
'report_4xx' => true,
],
'middleware' => ['enabled' => false],
'middleware' => [
'ignored_paths' => ['_debugbar/*', 'telescope/*', 'health'],
],
bash
php artisan vendor:publish --tag=riviumtrace-config