-
Notifications
You must be signed in to change notification settings - Fork 140
Description
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