Skip to content

Add include_source_context option #2017

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

Closed
antonpirker opened this issue Apr 17, 2023 · 4 comments · Fixed by #2020
Closed

Add include_source_context option #2017

antonpirker opened this issue Apr 17, 2023 · 4 comments · Fixed by #2020
Assignees
Labels
Good first issue Good for newcomers

Comments

@antonpirker
Copy link
Member

antonpirker commented Apr 17, 2023

Problem Statement

Some users do not like the source context to be there and want to disable it.

Solution Brainstorm

For this we need to add a SDK option include_source_context that defaults to True.
If set to false, the source context should not be included.

Here is probably the place where to decide whether to add the source context or not:
https://github.com/getsentry/sentry-python/blob/antonpirker/celery-beat-wo-restart/sentry_sdk/utils.py#L614-L625

farhat-nawaz pushed a commit to farhat-nawaz/sentry-python that referenced this issue Apr 17, 2023
Some users do not like the source context to be there, and so add `include_source_context` option to opt-out.

Fixes getsentry#2017
@realkosty
Copy link

realkosty commented Apr 20, 2023

As of right now this can be removed in before_send() as follows:

def before_send(event, hint):
    placeholder = "*** Code context removed in before_send ***"
    for exception in event.get("exception", {}).get("values", []):
        for frame in exception.get("stacktrace", {}).get("frames", []):
            for key in ["pre_context", "post_context"]: # add "context_line" to remove line itself
                if key in frame and type(frame[key]) == list:
                    frame[key] = [placeholder] * len(frame[key]) 

    return event

Screenshot 2023-04-20 at 12 11 07 PM

@sentrivana
Copy link
Contributor

Reopening since there's a bit missing in order to finish the implementation fully.

@antonpirker
Copy link
Member Author

Documentation for this option is still missing, but the option itself is already release in version 1.23.0

@antonpirker
Copy link
Member Author

documentation PR is on the way: getsentry/sentry-docs#7090

So we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants