stellarsecurity/application-insights-laravel

Stellar Security - Application Insights style telemetry for Laravel (HTTP, DB, jobs, mail, dependencies).

Installs: 102

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/stellarsecurity/application-insights-laravel

1.0.5 2025-12-11 23:08 UTC

This package is auto-updated.

Last update: 2025-12-11 23:09:32 UTC


README

Built by StellarSecurity.com

Lightweight telemetry package for Laravel that sends structured events to your observability backend (e.g. Azure Application Insights).

It can automatically track:

  • Incoming HTTP requests
  • Outgoing HTTP calls (Guzzle)
  • Database slow queries
  • Failed jobs
  • Mail failures
  • Custom AV / security events

Installation

composer require stellarsecurity/application-insights-laravel

Laravel will auto-discover the service provider.

Then publish the config:

php artisan vendor:publish --tag=stellar-ai-config

Set your instrumentation key:

STELLAR_AI_INSTRUMENTATION_KEY="446e6a5e-a5ca-4c50-b311-e82648d987ef"

If you use queues, enable queue mode (default = true):

STELLAR_AI_USE_QUEUE=true

and run a worker:

php artisan queue:work

If you don’t use queues, the package will send telemetry synchronously.

Enable automatic HTTP request tracking

In bootstrap/app.php (Laravel 11/12 style), register the HTTP middleware:

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Foundation\Configuration\Exceptions;
use StellarSecurity\ApplicationInsightsLaravel\Middleware\LogHttpRequests;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        // ...
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Append Stellar HTTP logging to the global stack
        $middleware->append(LogHttpRequests::class);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        // see "Enable automatic exception tracking" below
    })
    ->create();

After this, every incoming HTTP request will be sent to Application Insights as telemetry (method, URL, status code, duration, etc.).

Enable automatic exception tracking

Still in bootstrap/app.php, wire the exception hook inside withExceptions:

use Throwable;
use Illuminate\Foundation\Configuration\Exceptions;
use StellarSecurity\ApplicationInsightsLaravel\ApplicationInsights;

return Application::configure(basePath: dirname(__DIR__))
    // ...
    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->report(function (Throwable $e) {
            // Send exceptions to Application Insights
            app(ApplicationInsights::class)->trackException($e);
        });
    })
    ->create();

Now every reported exception will be pushed to Application Insights as a custom event / exception telemetry.

Basic manual usage

You can also send custom events from anywhere:

use StellarSecurity\ApplicationInsightsLaravel\ApplicationInsights;

app(ApplicationInsights::class)->trackEvent('AV.HashCheck', [
    'client'  => 'Stellar Antivirus Desktop',
    'verdict' => 'malware',
]);

What gets tracked automatically?

Once installed and configured:

  • HTTP requests – via LogHttpRequests middleware
  • Exceptions – via the withExceptions hook
  • (Optional) Queued jobs / DB / mail / dependencies – depending on how you use the package in your app

Telemetry is batched and sent to the official Azure ingestion endpoint.

About Stellar Security

Stellar Security builds privacy-focused security products (Stellar Antivirus, StellarOS, VPN and more) with Swiss-grade security.