Laravel SDK

Laravel SDK

Official Laravel SDK for AllStack error tracking and monitoring by Techsea. This package provides seamless integration for error tracking and monitoring in your Laravel applications.

Installation

You can install the package via composer:

composer require techsea/allstack-laravel

Configuration

  1. Add the following variables to your .env file:

ALLSTACK_API_KEY=your-api-key
ALLSTACK_ENVIRONMENT=production
  1. The service provider will be automatically registered thanks to Laravel's package discovery.

Usage

Capturing Exceptions

try {
    // Your code here
} catch (\Throwable $e) {
    app(Techsea\AllStack\AllStackClient::class)->captureException($e);
}

For Global Capturing Exceptions Laravel 11x

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(\Techsea\AllStack\Middleware\AllStackMiddleware::class);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        // Register a custom exception reporting callback
        $exceptions->report(function (Throwable $exception) {
            // Resolve the AllStackClient from the container
            $allStackClient = app(AllStackClient::class);
            
            // Capture the exception using AllStack
            $allStackClient->captureException($exception);
            
            // Optionally, stop further propagation to Laravel's default logging
            // return false; // Uncomment to prevent default logging
        });
    })
    ->create();

For Laravel 8x

use Techsea\AllStack\AllStackClient;
php
class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array<int, class-string<Throwable>>
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array<int, string>
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (Throwable $e) {
            $allStackClient = app(AllStackClient::class);
            
            // Capture the exception using AllStack
            $allStackClient->captureException($e);
        });
    }
}

Tracking HTTP Requests

Add the middleware to your app/Http/Kernel.php:

protected $middleware = [
    // ...
    \Techsea\AllStack\Middleware\AllStackMiddleware::class,
];

Or use it in specific routes:

Route::middleware([\Techsea\AllStack\Middleware\AllStackMiddleware::class])->group(function () {
    // Your routes here
});

Features

  • Exception tracking with stack traces

  • HTTP request monitoring

  • System information collection

  • Environment-specific configuration

  • Automatic context gathering

  • Error handling and logging

Last updated