-
Notifications
You must be signed in to change notification settings - Fork 225
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
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
|
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
endIn 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
endWhy do you use |
|
hi @tomash:
As explained in a previous comment, I can not set And regarding: I haven't seen it is done in the Rails demo project. So I am not doing it. Don't know if it is necessary :/ |
|
I am having an issue when loading the logs in Grafana (Rails -> OtelCollector -> Loki -> Grafana). I don't know if it is related to this logger plugin or by my configuration or it is the expected behaviour. The case is that in Grafana I see the logs like this: The message has been created in a proper JSON format, but when it arrives at Grafana, it is in the I have tried many different |
|
SIG discussion 06/22/25 - Move this out of instrumentation, into a separate bridges package to make it easier to disable if people don't want to use it. |
…ntelemetry-ruby-contrib into logger-instrumentation
|
@xuan-cao-swi - I've looked into move the logger instrumentation into a separate
At the moment, I'd like to keep the logger instrumentation out of |
|
As discussed in... https://cloud-native.slack.com/archives/C01NWKKMKMY/p1759439218858049 I'm interested in trying this out... if you have time could you please merge in the latest changes? |
|
lgtm once the branch conflicts r resolved |
* raise min tested Rails version * use constants for Ruby version and post-install message * update internal dep versions for consistency
|
@ericmustin @robbkidd @xuan-cao-swi -- Made the updates we discussed in the SIG today. The logger instrumentation is no longer included in |
|
Also, the markdown link checker will fail until this PR is merged, because there's a link related to content in the PR. https://github.com/kaylareopelle/opentelemetry-ruby-contrib/actions/runs/18325633495/job/52189286587#step:3:262 |
robbkidd
left a comment
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.
|
Sorry I missed this, lgtm (in hindsight!) |
* WIP initial commit logger instrumentation * Rubocop require_relative * Add :: to find Ruby logger instead of OTel logger * Remove commented out option LOC * Add skip_instrumenting? method * Skip ActiveSupport::Logger#broadcast loggers * Add logger instrumentation library and version * Update severity_number logic, return orig value * Make instrumentation name a constant * WIP test active support logger * Map logger level to OTel level * Install WIP logs dependencies from git, not local * Update rubocop dependencies * Disable active_support_logger tests 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. * maps otel log level * Use the updated method name to emit, `on_emit` * Update tests referencing severity numbers * Loosen dependency version restrictions * fix: Remove NAME constant from gemspec * chore: Address Rubocop require_relative linter * Rubocop * fix: Bring back the NAME constant It's used in the instrumentation when on_emit is called * chore: Correct version number, add TODOs in README * fix: Revert version for now * change * move options * accomodated changes * removed configuring logger_provider * removed corresponding test * chore: Add tests for name and version config * chore: Rubocop * add check for logs sdk * test: Reinstate active support logger tests * style: Add language to code fence * Update instrumentation/logger/lib/opentelemetry/instrumentation.rb * docs: add some config info * feat: Remove config options * chore: Add TODO for version number update * feat: Update example and readme * test: remove appraisals for eol'd rails versions * feat: Support ActiveSupport::BroadcastLogger Rails 7.1+ uses ActiveSupport::BroadcastLogger. This needs to protect against emitting duplicate logs in a different way than ActiveSupport::Logger.broadcast. Emits the log record for the first logger in the broadcast, skip the others. Reset everything at the end of the method call. * test: Remove config option tests * chore: Prepare bridge for review * Add references to released logs gems * Test Rails 7.0 - 8.0 * Rubocop * Set gem version * chore: Rename skip_instrumenting to skip_otel_emit * chore: Bump instrumentation-logger version in all * chore: Remove simplecov * test: Update ActiveSupportLogger tests Test the outcome rather than the presence of variables * test: Add missing variable * chore: Update gem to include changes from main * move dev dependencies to Gemfile * require 'logger' in test helper * set min version to Ruby 3.1 * chore: Raise rubocop, rubocop-performance versions * Remove logger instrumentation from all * test: Exclude logger from all Gemfile/tests * chore: Match dependency-related files with repo * raise min tested Rails version * use constants for Ruby version and post-install message * update internal dep versions for consistency * chore: Remove extra requires from all --------- Co-authored-by: khushijain21 <[email protected]>

Description
This an OpenTelemetry logs bridge for Ruby's standard Logger library.
It also includes patches to
ActiveSupport::Logger.broadcastand theActiveSupport::BroadcastLoggerto 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