Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add the Refit Exception Content to Sentry #3314

Open
TimVerheul opened this issue Apr 18, 2024 · 4 comments
Open

Add the Refit Exception Content to Sentry #3314

TimVerheul opened this issue Apr 18, 2024 · 4 comments
Labels
Feature New feature or request

Comments

@TimVerheul
Copy link

Problem Statement

Refit is a populair library for making requests. If an exception occurs, only the Exception Message will be sent to Sentry. The Message is a very broad description (a 400 was received) without containing valuable information.
This information is stored in the Content part of the Exception. Unfortunately, Sentry does not send this.
So when a Refit Exception occurs, you won't know what exactly is causing this.

image

Solution Brainstorm

As a temporary solution I add my own EventExceptionProcessor but it would be nice to have something like .CatchRefit() to handle this.

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Apr 18, 2024

Hey @TimVerheul , thanks for reaching out.

There are so many libraries out there and only so many hours in a day, so I'm not sure if we can add something specifically for Refit

However, I'm wondering if we could potentially create something a bit more generic. Maybe some way to configure the SentryHttpFailedRequestHandler to check for (and extract) JSON content from response bodies for certain request targets and/or HttpStatus codes.

@bitsandfoxes thoughts?

@bitsandfoxes
Copy link
Contributor

This originates from a discussion on Discord.

We have a way that enables users to tailor the exception handling to their need if we lack some sort of integration with any specific framework. The way @TimVerheul managed to unblock himself looks like this

public class RefitExceptionProcessor : ISentryEventExceptionProcessor
{
    public void Process(Exception exception, SentryEvent sentryEvent)
    {
        if (exception is Refit.ApiException apiException)
        {
            sentryEvent.Message = apiException.Content;
            sentryEvent.Contexts["Refit"] = new
            {
                RefitMessage = apiException.Message,
                RefitContent = apiException.Content,
            }
        }
    }
}

I'm not sure about the benefit of crawling through whatever a framework/library has done to their own exception types and "guess" what bits might be relevant.

@bitsandfoxes
Copy link
Contributor

I see I misread your comment. You wanted to check the content on the response bodies. Won't we run into all kinds of PII and therefor opt-in/out related issues when trying to parse and capture the bodies?

@bitsandfoxes bitsandfoxes added the Feature New feature or request label Apr 19, 2024
@TimVerheul
Copy link
Author

I think having the code written here will help others who might got the same issue as I had. I agree, it's not possible to handle every custom exception for every library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
Status: No status
Status: No status
Development

No branches or pull requests

3 participants