You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Expected Behaviour
I've integrated Rollbar with Python's standard
logging
module using theRollbarHandler
.Some of my logging statements use the
extra
keyword parameter to add extra context, e.g.I expected
RollbarHandler
would include the data in the extra argument automatically, but it doesn't.Actual
RollbarHandler
looks for an attribute calledextra_data
on theLogRecord
, which isn't a standard part of thelogging
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 thatRollbarHandler
is expecting into theLogRecord
by providing my own subclass ofLogger
and overriding themakeRecord
function to add it in:Seeing as the purpose of
RollbarHandler
is to integrate with thelogging
module, it feels like this step shouldn't be necessary on my part. I thinkRollbarHandler
should be figuring out from theLogRecord
's__dict__
what data was added via theextra
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
The text was updated successfully, but these errors were encountered: