telegram-bot-rb / telegram-bot

Ruby gem for building Telegram Bot with optional Rails integration
MIT License
633 stars 113 forks source link

Telegram-bot poller mode with sentry #203

Closed mario-amazing closed 1 year ago

mario-amazing commented 1 year ago

In poller mode, the bot doesn't send raise_error to sentry. (OR rewrites logs somehow) LOG_TO_STDOUT doesn't help Bot sends only [OpenSSL::SSL::SSLError] error.

Expected behavior: same as with rails s -> webhook mode. Sends all errors to sentry

Gemfile:

gem "sentry-ruby" 
gem "sentry-rails"

config/initializers/sentry.rb

Sentry.init do |config|
  config.dsn = 'DSN'
  config.enabled_environments = %w[production]

  config.traces_sample_rate = 0
end
printercu commented 1 year ago

You can implement it the similar way: https://github.com/telegram-bot-rb/telegram-bot/issues/201#issuecomment-1454146574

I don't think will add a plugin for the bot poller similar to the one they have for rails controller 😉

mario-amazing commented 1 year ago

I think the issue in the Logger inside the bot poller If you have another vision of why the behavior above could be, explain it, please)

printercu commented 1 year ago

https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/railtie.rb#L10 this is where sentry installs plugin into action_controller.

Obviously it doesn't install such plugin for telegram bot poller. So you can either ask them for such plugin or implement it yourself. With a link I provided in the previous comment you can wrap super call with a code that will capture exception and send it to sentry. It will be something like this: https://github.com/getsentry/sentry-ruby/blob/803ba7394bc8301bec7c3de6c78c4b019214eb8f/sentry-ruby/lib/sentry/rack/capture_exceptions.rb#L12