logtail / logtail-ruby-rails Goto Github PK
View Code? Open in Web Editor NEWBetter Stack Rails client
Home Page: https://betterstack.com/logs
License: Other
Better Stack Rails client
Home Page: https://betterstack.com/logs
License: Other
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?
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)
Hi,
It seems like the example application doesnt work out of the box.
To reproduce:
example-project
config/application.rb
bundle install && rails s
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.
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!
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 ๐ค
Specifically, this check:
fails with Rails < 7.1 because ::ActiveSupport::BroadcastLogger
does not exist. You probably want to add a defined?()
guard to the check.
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
Sidekiq made a change for Rails 7.1 that now calls Rails.logger.broadcast_to
: sidekiq/sidekiq@916a564.
However, if the Rails.logger
is set to a Logtail::Logger
, the sidekiq process will crash with an undefined method
error (as broadcast_to
is not a method on Logtail::Logger
).
Have any questions? Please explore the Logtail documentation or contact our support.
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")
Heya, I'm looking at the example Rails project and the around_action
example. However, I cannot get it to log the user context. The only difference I can see is that I'm using Rails API, so my ApplicationController
inherits from ActionController::API
. Any help appreciated.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.