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

RollbarHandler should include extra data from LogRecords automatically (or provide a switch to enable that) #388

Open
GrahamLea opened this issue Aug 20, 2021 · 1 comment

Comments

@GrahamLea
Copy link

Expected Behaviour

I've integrated Rollbar with Python's standard logging module using the RollbarHandler.
Some of my logging statements use the extra keyword parameter to add extra context, e.g.

    except:
        logger.exception("Uncaught error", extra={"customer.id": customer_id})

I expected RollbarHandler would include the data in the extra argument automatically, but it doesn't.

Actual

RollbarHandler looks for an attribute called extra_data on the LogRecord, which isn't a standard part of the logging API that I can see.
While pyrollbar provides a way to transform the payload, the LogRecord isn't available to that callback, so there's no way to get hold of the extra data at that point.

Workaround

I was able to put the extra_data attribute that RollbarHandler is expecting into the LogRecord by providing my own subclass of Logger and overriding the makeRecord function to add it in:

        if extra:
            record.extra_data = extra

Seeing as the purpose of RollbarHandler is to integrate with the logging module, it feels like this step shouldn't be necessary on my part. I think RollbarHandler should be figuring out from the LogRecord's __dict__ what data was added via the extra parameter and including this in the custom data.

Environment

Python 3.9.6 (v3.9.6:db3ff76da1, Jun 28 2021, 11:49:53) [Clang 6.0 (clang-600.0.57)]
pyrollbar===0.16.1

@GrahamLea
Copy link
Author

Related to #381

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

No branches or pull requests

1 participant