PHP code example of usesorane / sorane-laravel

1. Go to this page and download the library: Download usesorane/sorane-laravel 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/ */

    

usesorane / sorane-laravel example snippets


return [
    'key' => env('SORANE_KEY'),
    'events' => [
        'enabled' => env('SORANE_EVENTS_ENABLED', true),
        'queue' => env('SORANE_EVENTS_QUEUE', true),
        'queue_name' => env('SORANE_EVENTS_QUEUE_NAME', 'default'),
    ],
    'logging' => [
        'enabled' => env('SORANE_LOGGING_ENABLED', false),
        'queue' => env('SORANE_LOGGING_QUEUE', true),
        'queue_name' => env('SORANE_LOGGING_QUEUE_NAME', 'default'),
        'excluded_channels' => [
            // Add channels here that should never be sent to Sorane
            // Note: The handler uses 'single' channel for its own error logging to prevent loops
        ],
    ],
    'website_analytics' => [
        'enabled' => env('SORANE_WEBSITE_ANALYTICS_ENABLED', false),
        'queue' => env('SORANE_WEBSITE_ANALYTICS_QUEUE', 'default'),
        'excluded_paths' => [
            'horizon',
            'nova',
            'telescope',
            'admin',
            'filament',
            'api',
            'debugbar',
            'storage',
            'livewire',
            '_debugbar',
        ],
        'request_filter' => null,
    ],
];

use Sorane\ErrorReporting\Facades\Sorane;
use Sorane\ErrorReporting\Events\EventTracker;

// Track a simple event (names must be snake_case)
Sorane::trackEvent('button_clicked', [
    'button_id' => 'header-cta',
    'page' => 'homepage'
]);

// Track an event with user ID
Sorane::trackEvent('feature_used', [
    'feature_name' => 'export_data',
    'export_type' => 'csv'
], $userId);

// Use predefined constants to prevent typos
Sorane::trackEvent(EventTracker::USER_REGISTERED, [
    'registration_source' => 'website'
], $userId);

// ✅ Valid - uses snake_case format
Sorane::trackEvent('newsletter_signup', ['source' => 'footer']);

// ❌ Invalid - will throw InvalidArgumentException
Sorane::trackEvent('Newsletter Signup', ['source' => 'footer']);

// ✅ Use constants to avoid validation issues
use Sorane\ErrorReporting\Events\EventTracker;
Sorane::trackEvent(EventTracker::NEWSLETTER_SIGNUP, ['source' => 'footer']);

// ✅ Bypass validation if needed (advanced usage)
Sorane::trackEvent('Legacy Event Name', [], null, false);

use Sorane\ErrorReporting\Facades\SoraneEvents;

// Track product added to cart
SoraneEvents::productAddedToCart(
    productId: 'PROD-123',
    productName: 'Awesome Widget',
    price: 29.99,
    quantity: 2,
    category: 'Widgets',
    additionalProperties: ['color' => 'blue', 'size' => 'large']
);

// Track a sale
SoraneEvents::sale(
    orderId: 'ORDER-456',
    totalAmount: 89.97,
    products: [
        [
            'id' => 'PROD-123',
            'name' => 'Awesome Widget',
            'price' => 29.99,
            'quantity' => 2,
        ]
    ],
    currency: 'USD',
    additionalProperties: ['payment_method' => 'credit_card']
);

// Track user registration
SoraneEvents::userRegistered(
    userId: 123,
    additionalProperties: ['registration_source' => 'website']
);

// Track user login
SoraneEvents::userLoggedIn(
    userId: 123,
    additionalProperties: ['login_method' => 'email']
);

// Track custom page views
SoraneEvents::pageView(
    pageName: 'Product Details',
    additionalProperties: ['product_id' => 'PROD-123']
);

// Track custom events with validation
SoraneEvents::custom(
    eventName: 'newsletter_signup',
    properties: ['source' => 'footer'],
    userId: 123
);

// Track custom events without validation (advanced usage)
SoraneEvents::customUnsafe(
    eventName: 'Legacy Event Name',
    properties: ['source' => 'migration']
);

use Sorane\ErrorReporting\Events\EventTracker;

EventTracker::PRODUCT_ADDED_TO_CART      // 'product_added_to_cart'
EventTracker::PRODUCT_REMOVED_FROM_CART  // 'product_removed_from_cart'
EventTracker::CART_VIEWED               // 'cart_viewed'
EventTracker::CHECKOUT_STARTED          // 'checkout_started'
EventTracker::CHECKOUT_COMPLETED        // 'checkout_completed'
EventTracker::SALE                      // 'sale'
EventTracker::USER_REGISTERED           // 'user_registered'
EventTracker::USER_LOGGED_IN           // 'user_logged_in'
EventTracker::USER_LOGGED_OUT          // 'user_logged_out'
EventTracker::PAGE_VIEW                // 'page_view'
EventTracker::SEARCH                   // 'search'
EventTracker::NEWSLETTER_SIGNUP        // 'newsletter_signup'
EventTracker::CONTACT_FORM_SUBMITTED   // 'contact_form_submitted'

'events' => [
    'enabled' => env('SORANE_EVENTS_ENABLED', true),
    'queue' => env('SORANE_EVENTS_QUEUE', true),
    'queue_name' => env('SORANE_EVENTS_QUEUE_NAME', 'default'),
],

'channels' => [
    'sorane' => [
        'driver' => 'sorane',
        'level' => 'error', // Control which levels are sent to Sorane
    ],
    
    // Recommended: Create a stack for production
    'production' => [
        'driver' => 'stack',
        'channels' => array_merge(explode(',', env('LOG_STACK', 'single')), ['sorane']),
        'ignore_exceptions' => false,
    ],
],

use Illuminate\Support\Facades\Log;

// These automatically go to both file and Sorane
Log::error('Database connection failed', [
    'database' => 'mysql',
    'error_code' => 1045,
]);

Log::critical('System overload detected', [
    'cpu_usage' => '98%',
    'memory_usage' => '95%',
]);

// Use specific channels when needed
Log::channel('sorane')->error('This goes only to Sorane');

'logging' => [
    'enabled' => env('SORANE_LOGGING_ENABLED', false),
    'queue' => env('SORANE_LOGGING_QUEUE', true),
    'queue_name' => env('SORANE_LOGGING_QUEUE_NAME', 'default'),
    'excluded_channels' => ['sorane'],
],
bash
php artisan vendor:publish --tag="sorane-laravel-config"
bash
php artisan sorane:test-events
bash
php artisan sorane:test-logging