Addition of Javascript SDK #948
Replies: 1 comment 1 reply
-
My main concern with this are the many different ways of how you can build frontends in Laravel. Some people prefer blade, others use Livewire or Intertia, someone might build an SPA etc. We once had a step in our publish wizard that would install and setup the JS SDK automatically, but the feedback we got was that is was too limited. And then there is also the topic of using the loader or installing the JS SDK as an dependency. So TL;DR, I would like avoid us making strong ties to the way how to setup the JS SDK from the Laravel SDK. In your case, you could set the desired env variables into the view and reference them in your blade files, see https://docs.sentry.io/platforms/javascript/install/loader/#custom-configuration <?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
// ...
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
View::share('sentry_dsn', config('sentry.dsn'));
View::share('sentry_release', config('sentry.release'));
...
}
} And then you can reference this in your blade layout files etc. <script>
// Configure sentryOnLoad before adding the Loader Script
window.sentryOnLoad = function () {
Sentry.init({
// add custom config here
});
};
</script>
<script
src="https://js.sentry-cdn.com/8755500ab4bd6caa0d7067e324d0c134.min.js" crossorigin="anonymous"
></script> |
Beta Was this translation helpful? Give feedback.
-
The idea is to have the Sentry JS SDK rendered into view output automatically.
A rough idea of how this could be achived is done by Laravel Livewire: https://github.com/livewire/livewire/blob/main/src/Features/SupportAutoInjectedAssets/SupportAutoInjectedAssets.php
Sentry has a CDN method to allow avoidance of tracking the exact version JS within this project.
The main part that would be desirable to have is to let the settings from .env pass through to the JS. Especially the DSN and Environment, trace tags, etc. I would love to be able to configure as much of the JS SDK from the .env as possible, but also understand that may be bringing extra undesirable maintenance into this project, and much of it is configurable form the Sentry UI.
Please ensure you don't need to rebuild assets on DSN or other setting change.
What is the thought on this?
Beta Was this translation helpful? Give feedback.
All reactions