asbiin/laravel-sentry-tunnel

Provides an endpoint to use the `tunnel`-parameter of the Sentry SDK

Fund package maintenance!
asbiin

2.2.0 2024-03-18 17:59 UTC

This package is auto-updated.

Last update: 2024-04-01 08:00:54 UTC


README

This package provides a URL for use with the tunnel-option of the Sentry SDK.

Installation

composer require asbiin/laravel-sentry-tunnel

Configuration

You can optionally publish the configuration files:

php artisan vendor:publish --provider=Naugrim\\LaravelSentryTunnel\\Provider

You must place at least one allowed host in your .env file:

SENTRY_TUNNEL_ALLOWED_HOSTS=my.host.com

NOTE: This essentially creates a reverse proxy to the SENTRY_TUNNEL_ALLOWED_HOSTS. As the Sentry DSN is not kept secret, this enables everyone to send messages to these hosts that seem to originate from your server.

Therefore, the default middleware list for the tunnel URL includes web and auth (so that only authenticated users can use the endpoint).

As you currently cannot pass a dynamic X-XSRF-TOKEN header in Sentry's transportOptions you either have to implement your own transport or place the tunnel URL in the exclude-list in the VerifyCsrfToken middleware.

If you want to change this behavior, provide a custom implementation of \SentryTunnel\Contracts\MiddlewareList via the container:

// app/Services/MyMiddlewareList.php

namespace App\Services;

use SentryTunnel\Services\MiddlewareList;

class MyMiddlewareList extends MiddlewareList
{
    public function getMiddlewareList() : array{
        return array_merge(
            parent::getMiddlewareList(),
            [
                "throttle",
            ]
        );
    }
}

Then add it to the container in your AppServiceProvider:

// app/Providers/AppServiceProvider.php

use Illuminate\Support\ServiceProvider;
use SentryTunnel\Contracts\MiddlewareList;
use App\Services\MyMiddlewareList;

class AppServiceProvider extends ServiceProvider
{
    public function register(){
        $this->app->alias(MyMiddlewareList::class, MiddlewareList::class);
    }
}

Optionally you can restrict the project IDs that are allowed to use this endpoint. The default behavior is to allow all projects.

SENTRY_TUNNEL_ALLOWED_PROJECTS=1234,456,78

You can change the URL of the tunnel if required. The default value is /sentry/tunnel

SENTRY_TUNNEL_URL="/super/secret/tunnel"

Usage

Consult Sentry's documentation.