-
Notifications
You must be signed in to change notification settings - Fork 196
feat: Ruby Logger instrumentation #983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Ruby Logger instrumentation #983
Conversation
…-ruby-contrib into logger-instrumentation
…elle/opentelemetry-ruby-contrib into logger-instrumentation
Appraisal can't install gems from a git source. Since the appraisal is only necessary for active_support_logger, disable those tests while working on other features.
chore: Allow logger patch tests to run
…-ruby-contrib into logger-instrumentation
…elle/opentelemetry-ruby-contrib into logger-instrumentation
feat: map logger level to OTel level
severity_text: severity, | ||
severity_number: severity_number(severity), | ||
timestamp: datetime, | ||
body: msg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New Relic uses formatted_message
here. This includes both the progname and the message in the body, whereas msg
does not include the progname. Which seems more appropriate?
Test the outcome rather than the presence of variables
I'm still trying to figure out why one of the tests is failing on the CI, but passes locally. However, everything except the ActiveSupportLogger code should be ready for review. Please take a look and I'll push the update as soon as I can! |
I am very interested in getting this to work with Opentelemetry. Any way I could help with this work? |
…ntelemetry-ruby-contrib into logger-instrumentation
* move dev dependencies to Gemfile * require 'logger' in test helper * set min version to Ruby 3.1
Hi @tomash! Thanks for reaching out. It's great to hear there's interest in this PR. I'd love your help! The features for the bridge should be complete. I just updated the branch to align with some of the changes in Specifically, I could use help with:
|
For now I have this monstrosity in Gemfile:
And I can confirm it works well for our app (the logs appear in Honeycomb just as events). The only problem is that Rails logs are noisy by default and it makes "top messages" unusable (top message being "rendered profiles/_carousel.html.erb"), so I've also dropped in Lograge to produce fewer logs. I haven't seen open-telemetry/opentelemetry-ruby#1789 , will evaluate and compare! I do like how lightweight and easy to read it is. |
So I'm after a few weeks of running this PR in production for a medium-sized app with a lot of traffic, together with Lograge. Works beautifully. I've also evaluated open-telemetry/opentelemetry-ruby#1789 but we have a specific setup -- using both Newrelic and Honeycomb -- and that one-screener did not produce logs to both outputs (so maybe it was intercepting too hard). It also does not use The only flaw I found in this one is a very specific case.
|
Hello @tomash I also would like to test this in my Rails project. Can you share your integration? Especially interested in the lograge integration. Thanks! UPDATE: forget it, I see it just work out of the box after installing the gem with your I am sharing here my configurations:
UPDATE 2: I see the author or the PR has a proper Rails demo published |
Funny behaviour. If I have activated
And it gets into an infinite loop. It may be expected. But just for you to take into consideration :) |
@fguillen I was about to write an answer but you figured it all out in the meantime! Sharing my slightly-different lograge.rb initializer: Rails.application.configure do
config.lograge.enabled = true
# the hotwire connect-disconnect logs are just noise
config.lograge.ignore_actions = [
"Turbo::StreamsChannel#subscribe",
"Turbo::StreamsChannel#unsubscribe",
"Hotwire::Livereload::ReloadChannel#subscribe",
"Hotwire::Livereload::ReloadChannel#unsubscribe",
"ApplicationCable::Connection#connect",
"ApplicationCable::Connection#disconnect",
"ApplicationCable::Connection#reconnect",
"ActionCable::Connection::Base#connect",
"ActionCable::Connection::Base#disconnect",
]
config.lograge.custom_payload do |controller|
{
params: controller.request.filtered_parameters,
}
end
end In opentelemetry.rb initializer we also have this line, as I saw it in this PR's example code: at_exit do
OpenTelemetry.logger_provider.shutdown
end Why do you use |
Description
This an OpenTelemetry logs bridge for Ruby's standard Logger library.
It also includes patches to
ActiveSupport::Logger.broadcast
and theActiveSupport::BroadcastLogger
to emit only one log record for a broadcast.@khushijain21 is a co-author of this PR and contributed functionality as part of her LFX mentorship with OpenTelemetry in 2024.
Closes #668