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

Display Request and Response Bodies in Sentry Dashboard #3960

Open
romankulykov opened this issue Dec 5, 2024 · 1 comment
Open

Display Request and Response Bodies in Sentry Dashboard #3960

romankulykov opened this issue Dec 5, 2024 · 1 comment

Comments

@romankulykov
Copy link

Problem Statement

Description:
It would be extremely helpful to have the ability to view the request body and response body of API calls directly in the Sentry dashboard. This feature could provide critical insights for debugging issues involving backend communication.

Use Case:
• When an error happens, developers could see the request body (data sent to the backend) and the response body (data received from the backend) in the issue details.
• This would help in diagnosing problems caused by malformed requests, unexpected server responses, or API contract violations.

Expected Behavior:
• An option to enable capturing of request body and response body in the Sentry SDK.
• In the Sentry dashboard, this data would appear in the issue details under a new section, such as “API Details” or “Request/Response Data.”
• Sensitive information like passwords, tokens, or personally identifiable information (PII) should be masked or excluded for security.

Implementation Suggestion:
For Android, this functionality might be achievable through OkHttp. By implementing an interceptor, it is possible to capture the request and response bodies during API calls. These captured data could then be passed to Sentry as custom metadata or breadcrumbs. If such a solution already exists, guidance or examples in the documentation would be highly appreciated.

Questions:
• Is there currently a way to capture and display request and response bodies using Sentry?
• Could this functionality be added as part of Sentry’s SDKs or configured via breadcrumbs or custom events?
• Are there any workarounds or best practices to achieve this behavior until such a feature exists?

Solution Brainstorm

No response

@stefanosiano
Copy link
Member

hi @romankulykov, thanks for the feedback!
We decided not to send request and response body for security reasons. Also, regarding OkHttp, if we read the content of the response body, the user cannot read it anymore, and since the interceptor runs before the user code, we cannot just do it.
However, we send both the request and the response in the Hint object, which can be inspected in the beforeSend callback or in a custom EventProcessor.
You could write something like this:


        SentryAndroid.init(this) {
            it.dsn = <DSN>
            ... // other config
            it.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Hint ->
                val request = hint.get(TypeCheckHint.OKHTTP_REQUEST) as? Request
                val response = hint.get(TypeCheckHint.OKHTTP_RESPONSE) as? Response
                if (request != null && response != null) {
                    // Parse response and request and add to the event
                }
                event
            }
        }

Beware that if you read the response body in the beforeSend, you cannot read it in the try/catch blocks in your own code.
Please, let us know if this works for you

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Dec 10, 2024
@markushi markushi added the enhancement New feature or request label Dec 11, 2024
@stefanosiano stefanosiano moved this from Needs Discussion to Backlog in Mobile & Cross Platform SDK Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Backlog
Development

No branches or pull requests

3 participants