Giter Site home page Giter Site logo

logtail / logtail-ruby-rails Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 4.0 104 KB

Better Stack Rails client

Home Page: https://betterstack.com/logs

License: Other

Ruby 91.84% HTML 6.10% JavaScript 1.31% CSS 0.75%
logging logtail rails ruby ruby-gem ruby-on-rails

logtail-ruby-rails's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

logtail-ruby-rails's Issues

Filter sent to betterstack does not seem to be working

I am trying to filter out logs for our /up endpoint by following these docs

config.logtail.filter_sent_to_better_stack do |log_entry|
  # Filter out logs from the /up endpoint
  log_entry.context_snapshot[:http][:path] == "/up"
end
config.logger = Logtail::Logger.create_default_logger(Rails.application.credentials.logtail.source_token)

It doesn't seem to be working ๐Ÿค”
The docs say "see Logtail::LogEntry for available attributes of the block parameter."
The only method I see on the Logtail::LogEntry class is to_hash, should I be checking the HTTP path with to_hash instead?

log_entry.to_hash[:http][:path] == "/up"

Am I missing anything?

Wrong number of arguments (given 2, expected 0..1)

I have just installed the gem and got this error

Rails.logger.error("Something bad happened.")

-> This works!

Rails.logger.warn("Log message wih structured logging.", {
    item: "Orange Soda",
    price: 100.00
})

/.rbenv/versions/3.2.2/lib/ruby/3.2.0/logger.rb:700:in `warn': wrong number of arguments (given 2, expected 0..1) (ArgumentError)

ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin23]

gem 'rails', '7.1.2'
logtail-rails (0.2.6)

Not able to make the test project work

Hi,

It seems like the example application doesnt work out of the box.

To reproduce:

  • Clone the repo
  • Go to example-project
  • Insert key into config/application.rb
  • bundle install && rails s
  • Open up localhost and click the "lets go" button

Expected result
Logs appearing in BetterStack

Actual result
No logs appearing

However, I did get some logs initially due to an exception in the application. I tried to access it via a local dev host alias I have, and then Rails by default spits out an exception which was sent to BetterStack: [ActionDispatch::HostAuthorization::DefaultResponseApp] Blocked host: my.local.dev

So it seems like the key is correct and some of the setup works at least, but not the main logging test.

How to filter sensitive headers from logs?

I'm evaluating the product ATM. I see that in the live view, under event.http_request_received.headers_json I can see all request's headers. The problem is that these headers might contain sensitive data, like access tokens.

I've configured Rails with the right set of Rails.application.config.filter_parameters, but I can still see the access token in plain text in the logs.

Is there a way to stop sending request headers to Logtail?

Thanks!

SQL logs aren't sent to logtail when Doorkeeper is used

Hey guys!

Trying to implement logtail to our project which is using very popular doorkeeper gem. Got one weird thing that some logs are sent to logtail but ActiveRecord logs weren't.

I didn't dig it to understand what happened but found workaround that works for us and maybe will be helpful for others who use Doorkeeper too ๐Ÿ˜ƒ .

So, it seems that initializers order is matter and renaming initializers/logtail.rb -> initializers/00_logtail.rb fixes the problem.

Would be perfect to get advice how to debug this and maybe I'll find time to open PR ๐Ÿค“

Ability to filter out some logs

Some endpoints like /, /status are calling regularly and I would like not to log them to logtail
There should be a way to filter out logs for some controllers before sending data

LoadError: cannot load such file /logtail-rails-0.1.8/lib/logtail-rails/tasks/logtail.rake

I have installed as recommend in the getting started tutorial.
I can successfully run rails console and send an event

rails console
Rails.logger.error("Something bad happened.")

but when I start the local webserver

bin/dev
=> Booting Puma
14:22:45 web.1  | => Rails 7.0.4.2 application starting in development 
14:22:45 web.1  | => Run `bin/rails server --help` for more startup options
14:22:45 css.1  | rails aborted!
14:22:45 css.1  | LoadError: cannot load such file -- /Users/myname/.rvm/gems/ruby-3.1.2/gems/logtail-rails-0.1.8/lib/logtail-rails/tasks/logtail.rake
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/dead_end-4.0.0/lib/dead_end/core_ext.rb:65:in `load'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/dead_end-4.0.0/lib/dead_end/core_ext.rb:65:in `load'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/logtail-rails-0.1.8/lib/logtail-rails/railtie.rb:11:in `block in <class:Railtie>'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/railtie.rb:286:in `instance_exec'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/railtie.rb:286:in `block in run_tasks_blocks'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/railtie.rb:298:in `each'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/railtie.rb:298:in `each_registered_block'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/railtie.rb:286:in `run_tasks_blocks'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/application.rb:505:in `block in run_tasks_blocks'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/engine/railties.rb:15:in `each'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/engine/railties.rb:15:in `each'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/application.rb:505:in `run_tasks_blocks'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/engine.rb:464:in `load_tasks'
14:22:45 css.1  | /Users/myname/Dropbox/dev/amazon/Rakefile:6:in `<main>'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
14:22:45 css.1  | /Users/myname/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
14:22:45 css.1  | bin/rails:4:in `<main>'

Gemfile
gem "logtail-rails"

Gemfile.lock

    logtail (0.1.12)
      msgpack (~> 1.0)
    logtail-rack (0.2.4)
      logtail (~> 0.1)
      rack (>= 1.2, < 4.0)
    logtail-rails (0.1.8)
      actionpack (>= 3.0.0)
      activerecord (>= 3.0.0)
      logtail (~> 0.1)
      logtail-rack (~> 0.1)
      railties (>= 3.0.0)

config/application.rb

    config.logger = Logger.new(STDOUT)
    config.logger = Logtail::Logger.create_default_logger("XXXX")

Update 0.2.4 -> 0.2.6 causes build errors on Heroku

Hi!

After updating logtail-rails to 0.2.6 I started experiencing build errors on Heroku (locally everything seams to work fine).
What might be misleading is that error is not directly related to logtails. Rather to Sentry gem which also uses ActiveSupport::BroadcastLogger and probably gets into some kind of loading priority problems.

Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
NameError: uninitialized constant ActiveSupport::BroadcastLogger (NameError)

         @logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts)
                                  ^^^^^^^^^^^^^^^^^
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-rails-5.12.0/lib/sentry/rails/configuration.rb:17:in `block in <class:Configuration>'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry/configuration.rb:608:in `instance_eval'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry/configuration.rb:608:in `block in run_post_initialization_callbacks'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry/configuration.rb:607:in `each'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry/configuration.rb:607:in `run_post_initialization_callbacks'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry/configuration.rb:353:in `initialize'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry-ruby.rb:210:in `new'
/tmp/build_30e21af1/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.12.0/lib/sentry-ruby.rb:210:in `init'
/tmp/build_30e21af1/config/initializers/sentry.rb:4:in `<main>'

logtail-rails was the only updated dependency at this point.

Disable logtail integration by `config.logtail.enabled = false`

Hi,

When logtail-rails is required, it will automatically be enabled and changes development log output.

That is fine, but it would be great if logtail could actually be disabled in the environment config like everything in Rails.

Right now it has to be disabled by Logtail::Integrations::Rails.enabled = false, which is unexpected, since it provides config.logtail configuration object.

I'm happy to make a PR that takes config.logtail.enabled as the global configuration in the Railtie and disables the integration.

Looks like there are config.integrations.{active_record,action_view,action_controller} that could be configured, but still it would be nice to have one that manages them all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.