UK-1 Datacenter
|
Back to Knowledgebase
Lv
Packagist trustportidentity/beacon-laravel v1.0.0

Laravel SDK Quickstart

The TrustPort Beacon Laravel SDK (trustportidentity/beacon-laravel) auto-registers via Laravel package discovery and tracks HTTP requests, database queries, and background jobs with almost zero overhead.

1Install via Composer

The service provider and Beacon facade are auto-discovered β€” no manual registration needed:

composer require trustportidentity/beacon-laravel

2Configure Your API Key

Add these to your .env file:

.env
BEACON_INGEST_URL=https://beacon-api.trustportidentity.com
BEACON_API_KEY=tb_live_your_tenant_key
BEACON_SERVICE_NAME=billing-api
BEACON_ENVIRONMENT=production

3Register the Middleware

Add BeaconMiddleware to your HTTP kernel so every request is traced:

app/Http/Kernel.phpLaravel 10/11/12
use TrustPortIdentity\Beacon\BeaconMiddleware;

protected $middleware = [
    BeaconMiddleware::class,
    // ...your other global middleware
];

4Custom Spans with the Beacon Facade

app/Http/Controllers/InvoiceController.phpProduction Ready
use TrustPortIdentity\Beacon\Beacon;

class InvoiceController extends Controller
{
    public function index()
    {
        $span = Beacon::span('db.mysql.select_invoices', 'database');
        $invoices = Invoice::where('status', 'pending')->get();
        $span->setTag('rows', $invoices->count())->end();

        Beacon::identify(['id' => auth()->id(), 'email' => auth()->user()?->email]);

        return response()->json($invoices);
    }
}

5Queue Job Tracking

Wrap a job's handle() body in a Beacon::span(..., 'job') to track queue processing time and failures the same way HTTP requests are tracked.

6Control Ingest Volume with BEACON_SAMPLE_RATE

Every request is already batched (BEACON_BATCH_SIZE) instead of one network call per request. On top of that, set BEACON_SAMPLE_RATE (0.0–1.0, default 1.0) to trace only a fraction of requests in high-traffic services β€” this is what actually keeps you inside your plan's monthly quota. Exceptions are always sent regardless of sampling.

.env
BEACON_SAMPLE_RATE=0.2  # trace ~20% of requests
Need help configuring Horizon or Octane?

Our engineers can help tune the batching interval for long-running workers.

Consult Architect