Rails.logger methods return breadcrumbs instead of true when breadcrumbs logging is enabled#1299
Rails.logger methods return breadcrumbs instead of true when breadcrumbs logging is enabled#1299st0012 merged 1 commit intogetsentry:masterfrom henrahmagix:master
Conversation
st0012
left a comment
There was a problem hiding this comment.
@henrahmagix thanks for reporting this and even open the PR! just curious, why do you choose to use sentry_logger instead of active_support_logger?
❤️
No reason yet – we want to see what breadcrumb logging offers us first before we commit, so we're just trying it out, though I haven't released that addition yet. I just copy-pasted a line I saw somewhere (maybe sentry docs, can't remember though sorry!) so there's no reasoning behind the choice yet =) |
|
@st0012 I've rebased onto the main branch to fix the conflicts, so I took the opportunity to squash everything – with test addition – into one commit =) |
|
You're welcome @st0012! Thanks for being so responsive =) Could you post here when it's released please, so I get a notification? Ta! |
|
sure, but I can just tell you it'll be next week 🙂 |
I started writing a bug issue, then thought I'd make the code change and see if any tests fail, and go from there. Saves creating a separate PR when the code change is this small is all =) (at least, small right now, who knows it could balloon! or just be rejected, that's fine also =))
Describe the bug
Without configuring
breadcrumbs_logger,Rails.logger.inforeturnstrue(ornildepending on the app).After configuring
breadcrumbs_logger,Rails.logger.inforeturns the entire breadcrumb buffer: https://github.com/getsentry/sentry-ruby/blob/sentry-ruby-v4.2.2/sentry-ruby/lib/sentry/breadcrumb_buffer.rb#L16This is because
Loggermethods return the last value, and since Sentry's logger prepends theaddmethod and calls super, it's the last method to run, so it's return value will be returned.Unfortunately our (big) app has been logging at the end of lots of methods, and it's been ok up til now because we haven't cared about the return value and luckily the return value has been
trueornil. However now, with adding breadcrumb logging, we're getting unexpectedly big return values.Of course, we should be controlling our return values, and we will be putting the work in to do this, but it's a lot of work at the moment. So I'm wondering if this is required functionality of the Sentry logger, or it's possible to change? It feels odd to me for breadcrumbs data to be exposed through the logging interface.
Thanks in advance,
Henry
To Reproduce
In a
rails console, regardless of env:This is for reproducing in a console, but it occurs in our app (even in testing) through
Rails.logger. I can't seem to reproduce it withRails.loggerin a console, only withActiveSupport::Logger.new, but the output detailed below is what I also get fromRails.logger.Expected behavior
Actual behavior
It seems the first log always returns the breadcrumbs. If it doesn't, adding a breadcrumb will cause the next log to return the breadcrumbs:
Environment
Raven Config
This is not necessary but could be helpful.