honeybadger-io / honeybadger-ruby

Ruby gem for reporting errors to honeybadger.io
https://docs.honeybadger.io/lib/ruby/
MIT License
251 stars 145 forks source link

Improve console behavior in Rails applications #622

Closed roelbondoc closed 1 month ago

roelbondoc commented 1 month ago

Currently, the gem's behavior in rails console could use improvement, particularly around logging and automatic instrumentation. This affects both development and production environments.

Current Behavior

Problems

  1. 12-factor applications typically set environment variables at the application level, making it difficult to have different behavior for console sessions
  2. Console logging can be noisy, potentially leading users to disable the gem entirely in development
  3. No clear way to explicitly enable/disable features in console sessions

Current Workaround

Set HONEYBADGER_LOGGING_TTY_LEVEL=ERROR

Potential Solutions

  1. New Console-Specific Configuration:

  2. Disable All Features in Console:

    • Treat console sessions like development mode
    • Add a way to explicitly enable features when needed
    • Similar to the current Insights-only approach but more comprehensive
  3. Improve Logging Control:

    • Allow routing different types of logs to separate files
    • Don't emit logs at all when attached to the console (this is the opposite of what Rails does by default, however — we should follow Rails conventions as closely as possible)

Questions to Consider

Related

joshuap commented 1 month ago

@stympy @rabidpraxis @subzero10 thoughts on this?

stympy commented 1 month ago

Don't emit logs at all when attached to the console (this is the opposite of what Rails does by default, however — we should follow Rails conventions as closely as possible)

But the production Rails console doesn't log SQL queries, whereas the development console does, so if we want to follow Rails conventions, we could match that behavior for logging.

As for automatic instrumentation, I think we should disable that for all console sessions.

joshuap commented 1 month ago

Don't emit logs at all when attached to the console (this is the opposite of what Rails does by default, however — we should follow Rails conventions as closely as possible)

But the production Rails console doesn't log SQL queries, whereas the development console does, so if we want to follow Rails conventions, we could match that behavior for logging.

As for automatic instrumentation, I think we should disable that for all console sessions.

So if we just want to keep the current behavior (but fix the 12-factor issue), we could add the explicit insights.console_enabled option, default false (see Roel's branch).

That way, Honeybadger.notify and Honeybadger.event will still report in production, and you'll see those logs in the console if that's where you're sending logs, but the automatic instrumentation will be turned off in the console.

It sounds like that's what we're leaning towards?

stympy commented 1 month ago

So if we just want to keep the current behavior (but fix the 12-factor issue), we could add the explicit insights.console_enabled option, default false (see Roel's branch).

That way, Honeybadger.notify and Honeybadger.event will still report in production, and you'll see those logs in the console if that's where you're sending logs, but the automatic instrumentation will be turned off in the console.

It sounds like that's what we're leaning towards?

Sounds good to me!

rabidpraxis commented 1 month ago

👍🏻

joshuap commented 1 month ago

@roelbondoc go ahead and submit a PR for your branch when you get the chance!