rollbar / pyrollbar

Error tracking and logging from Python to Rollbar
https://docs.rollbar.com/docs/python/
MIT License
213 stars 133 forks source link

Rollbar interprets empty tuple in 'server.history.args' as a CircularReference #402

Open ezra-agathos opened 2 years ago

ezra-agathos commented 2 years ago

System: macOS Catalina 10.15.7 Python: 3.6.13 Rollbar: 0.15.0

Problem

We use pyrollbar to capture error/exception information on python modules which run as jobs. On rollbar, we are seeing many reports that show something like this:

{
    "body": {
        ...
        "server": {
           ...,
            "history": [
                  {
                    "timestamp": 1643242402.460253, 
                    "args": [], 
                    "format": "script args: ***********"
                  }, 
                  {
                    "timestamp": 1643242416.966411, 
                    "args": [], 
                    "format": "*********"
                  }, 
                  {
                    "timestamp": 1643242428.563935, 
                    "args": "<CircularReference type:(tuple) ref:(server.history.1.args)>", 
                    "format": "**********"
                  },
                  ...
             ],
             ...
         },
         ...
     }
}

Below is the code that sets up the logger:

...
 if settings.ROLLBAR_API_KEY:
        rollbar.init(
            settings.ROLLBAR_API_KEY,
            settings.ROLLBAR_ENVIRONMENT,
            scrub_fields=settings.ROLLBAR_SCRUB_FIELDS,
        )
        # Send to rollbar all WARNING or higher logs
        rollbar_warn_logger = rollbar.logger.RollbarHandler()
        rollbar_warn_logger.setLevel(logging.WARNING)
        rollbar_warn_logger.addFilter(f)
        log.addHandler(rollbar_warn_logger)
        ...

Expectation

From what I understand, our code throws exceptions without any additional arguments. I would have expected that all instances of () would have been interpreted to a [] when converted to rolllbar payload.

Additional Information

The data is transformed to payload in _build_payload (line 1339, rollbar/init.py). Stepping through this, I noticed that the data didn't have any CircularReferences until after transformation via traverse (line 88 rollbar/lib/traverse.py). It appears that the id function is used to hash the key argument to a unique identifier inside memo. However, the id function will always return the same value for an empty tuple input. I couldn't find documentation on how to properly add an empty tuple to an allowed circular types - though I think this issue may be somewhat similar?: https://github.com/rollbar/pyrollbar/issues/286