Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve SDK support for server-based 500s #271

Open
dcramer opened this issue Dec 13, 2023 · 3 comments
Open

Improve SDK support for server-based 500s #271

dcramer opened this issue Dec 13, 2023 · 3 comments
Assignees
Labels
Type: Enhancement New feature or request

Comments

@dcramer
Copy link
Member

dcramer commented Dec 13, 2023

We need to adjust the way the SDK and Spotlight inteteract to support a better workflow.

Ideal outcome:

  • Server generates an error (e.g. 500 standard uncaught exception)
  • Sentry SDK captures that payload
  • On the framework/user specific error handler (e.g. Django's 500 error handler) we are able to grab the eventID and the full event payload (fully materialized) of the error.

I dont know exactly what this looks like in practice, but in SDKs we already return eventID from things like captureException(). We almost need that kind of behavior, but with the abilty to also grab the event payload.

Implementation wise we should look at Django, Laravel, and Rails. All have error frameworks to make this drop-in. In Laravel, for example, we need to hook it here:

<?php

namespace Spotlight\Laravel;

use Spotlight\Laravel\Renderers;
use Illuminate\Support\ServiceProvider;

class SpotlightServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        $this->app->bind(
            'Illuminate\Contracts\Foundation\ExceptionRenderer',
            fn (Application $app) => $app->make(SpotlightExceptionRenderer::class)
        );
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        //
    }
}

The error handler gets passed the exception, which at this point - similar to how User Feedback integration works - we'd need to get the payload. It's possible "the last error generated" is fine (I'm not sure), but "the last event" is probably incorrect these days. Really we want "the last unhandled error" OR we want a clean way to just pull the guaranteed payload of an exception.

On this error page, or on a generic injection thats available everywhere, it then becomes as easy as Spotlight.init() and Spotlight.trigger("sentry:showError", {eventId: event.event_id, event}).

For more clarity on the DX and how it must work, image you have 500.blade.php:

<h1>Internal Server Error</h1>
<StackTrace />

<script>
Spotlight.init();
Spotlight.trigger("sentry:showError", {
  event: {{ app('sentry')->getTheErrorThatCrashedTheServerAsJSON() }}
 });
 </script>
@Shubhdeep12 Shubhdeep12 added the Type: Enhancement New feature or request label Feb 3, 2024
@BYK BYK self-assigned this Jul 15, 2024
@BYK
Copy link
Member

BYK commented Jul 15, 2024

#434 now has code that can help with this. I'll focus on this as a follow up and abstract that code away later.

@BYK
Copy link
Member

BYK commented Jul 15, 2024

The interesting part is, we may get this without using a Sentry SDK on the server.

@BYK
Copy link
Member

BYK commented Nov 4, 2024

With #515 and #530 I think we have everything in place from Spotlight side. We were able to demonstrate the usage of these with getsentry/sentry-python#3600 and getsentry/sentry-python#3614 so I'll keep this open to track SDK integrations but I don't think we need anything more on Spotlight side.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants