[Python] Problem with sending data with exceptions

Hi there.
I have a problem with python Sentry SDK
When I want to capture an exception with the capture_exception method, I set a context with set_context and pass all the extra data to it as a dict and in the sentry web panel, I can’t find fields which have None values or in some exceptions, some fields are missing, Sentry will remove these fields. how can I send a JSON object with an exception?

Could you give us more context such as the code you are executing? Could you post a screenshot of the sentry UI and tell us what you would expect to see? I only have a vague understanding of the problem right now.

Thanks for your reply :pray:
It is the code:


def exception(self, data, extra_info):
    self.set_extra_data(level='error', data=data, extra_info=extra_info)
    # Add a custom exception
    if extra_info.get('action') is not None:
        try:
            raise type(extra_info['action'], (Exception,), {})(extra_info.get('reason', ''))
        except Exception as e:
            capture_exception()
    else:
        capture_exception()

def set_extra_data(self, level, data, extra_info):
    with configure_scope() as scope:
        # Set event level
        scope.level = level
        # Set custome tags for event
        if (extra_info.get('event_tags') is not None) and (type(extra_info['event_tags']) is dict):
            for event_tag_name in extra_info['event_tags'].keys():
                scope.set_tag(event_tag_name, extra_info['event_tags'][event_tag_name])
        # Set extra data to context <---- My problem is here
        scope.set_context('data', data)
        # Set user_info
        if data.get('user_id') is not None:
            scope.user = {'id': data['user_id']}
        # Set a UUID for fingerprint, I don't want to group my events
        scope.fingerprint = [str(uuid.uuid4())]

# data will set as extra data in context
my_instance.exception(data=data, extra_info={
    'action': 'Custome label for event',
    'reason': 'Custome desc for event',
    'event_tags': ['failed_action'],
})

It is my original data:

{
    "uid": "string",
    "cart_id": "string",
    "field": {
        "uid": "string",
        "field-1": "string",
        "items": {
            "feild": [
                {
                    "field-1": "string",
                    "field-2": "string",
                    "field-3": "string",
                    "item": {
                        "field-1": "string",
                        "field-2": "string",
                        "field-3": "string",
                        "field-4": "string",
                    },
                    "item_type": "string",
                    "price": 0,
                }
            ],
            "plan-refund": [
                {
                    "type": "1",
                    "field-1": "string",
                    "field-2": "string",
                    "field-3": "string",
                    "field-4": "string",
                    "field-5": "string",
                },
                {
                    "type": "2",
                    "field-1": "string",
                    "field-2": "string",
                    "field-3": "string",
                    "field-4": "string",
                    "field-5": "string",
                },
                {
                    "type": "3",
                    "field-1": "string",
                    "field-2": "string",
                    "field-3": "string",
                    "field-4": "string",
                    "field-5": "string",
                },
                {
                    "type": "4",
                    "field-1": "string",
                    "field-2": "string",
                    "field-3": "string",
                    "field-4": "string",
                    "field-5": "string",
                },
            ]
        },
        "creation_date": "2019-10-23 01:16:05",
        "status": "failed",
        "ip": "string",
        "id": "string",
        "field": 0
    }
}

It is Sentry data which show under the breadcrumbs section:


As you see some fields missed such as “type”: “3” and “field-4”, “field-5” in the “plan-refund” list or “status”, “uid” and etc.
Also, when I send a null field, It will remove it from the data.
Is this related to " Context Size Limits"?

The code that serializes the payload is here: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/serializer.py - I’m guessing you are bumping into the MAX_DATABAG_BREADTH limit which doesn’t seem configurable. @untitaker - can you confirm?

1 Like

That would be my best guess but judging by the amount of data they send it doesn’t seem like they should run into this issue.

kurama, could you post a link to a sentry issue that shows the trimmed data?

1 Like

Thanks for the reply again :pray:
We have a self-hosted Sentry and I can’t send you any link, I want to increase the MAX_DATABAG_BREADTH manually, I will post the results here.

I increased the MAX_DATABAG_BREADTH parameter manually but it didn’t fix anything. I got the packet that is sending to the sentry server with Wireshark and find out that the data is completely true but some fields are missing in the Sentry server.
I’m pretty sure there is some issue with storing data in the sentry server.

If you send the data that I put on the first post, you can see what’s going on.
Send it as extra data in the context:

{
  "cart_id": "string",
  "field": {
    "creation_date": "2019-10-23 01:16:05",
    "field": 0,
    "field-1": "string",
    "id": "string",
    "ip": "string",
    "items": {
      "feild": [
        {
          "field-1": "string",
          "field-2": "string",
          "field-3": "string",
          "item": {
            "field-1": "string",
            "field-2": "string",
            "field-3": "string",
            "field-4": "string"
          },
          "item_type": "string",
          "price": 0
        }
      ],
      "plan-refund": [
        {
          "field-1": "string",
          "field-2": "string",
          "field-3": "string",
          "field-4": "string",
          "field-5": "string",
          "type": "1"
        },
        {
          "field-1": "string",
          "field-2": "string",
          "field-3": "string",
          "field-4": "string",
          "field-5": "string",
          "type": "2"
        },
        {
          "field-1": "string",
          "field-2": "string",
          "field-3": "string",
          "field-4": "string",
          "field-5": "string",
          "type": "3"
        },
        {
          "field-1": "string",
          "field-2": "string",
          "field-3": "string",
          "field-4": "string",
          "field-5": "string",
          "type": "4"
        }
      ]
    },
    "status": "failed",
    "uid": "string"
  },
  "uid": "string"
}