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

Sentry error reporting is dropping some local variables in favour of other - and no way to control this #3034

Open
sam-ghosh opened this issue May 1, 2024 · 1 comment

Comments

@sam-ghosh
Copy link

sam-ghosh commented May 1, 2024

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.39

Steps to Reproduce

I am using sentry with the following config

import sentry_sdk
from sentry_sdk import capture_exception
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
     dsn="https://2ca804fbf56741bf929d85fa2547b6c6@o176489.ingest.us.sentry.io/1260928",
    

    max_breadcrumbs=50,
    attach_stacktrace=True,
    max_value_length=100  # Example length, adjust as needed.
)

and then creating a test error with a few local vars large small

def generate_error():
    # Large nested dictionary
    small_a = 1
    small_b = 2
    # large_dict = {i: {j: "x" * 1000 for j in range(10)} for i in range(10)}
    
    # Large list
    large_list = ["y" * 1000 for _ in range(100)]

    try:
        result = 1 / 0  # This will cause a ZeroDivisionError
    except Exception as e:
        capture_exception(e)

generate_error()

when the error is generated i see that small_a and small_b are not captured, the entirely is filled up by large_list

image

how can i control this feature? I have seen my projects before that when the local vars have one large list and other small vars, I cannot control and tell sentry to show the smaller variables

Expected Result

small_ and small_b being shown in sentry

Actual Result

image

@antonpirker
Copy link
Member

Hey @sam-ghosh thanks for writing in!

In the SDK there is something called the serializer that tries to trim events in a semi smart way to prevent events being too big.

Iirc it should remove data based on max_value_length as you tried. (But may the length applies to the list of all local vars, not every single one.)

Anyhow, what you can do:

  • Use a event_scrubber to remove the big list. (The event scrubber is run BEFORE the serializer mentioned above.
  • Use a before_send hook to change the data. (The before_send hook is run AFTER the serializer mentioned above)

Hope this helps,
Anton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants