Skip to content
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

Open
wants to merge 66 commits into
base: main
Choose a base branch
from

Conversation

kaylareopelle
Copy link
Contributor

@kaylareopelle kaylareopelle commented May 14, 2024

Description

This an OpenTelemetry logs bridge for Ruby's standard Logger library.

It also includes patches to ActiveSupport::Logger.broadcast and the ActiveSupport::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.

TODOs:

  • Improve README
  • Add example
  • Add workaround to prevent duplicate logs in Rails 7.1
  • Verify OpenTelemetry logs aren't emitted as LogRecords (or should they be?) Seems they can
  • Determine whether attributes should be able to be passed to the bridge and add this functionality if they should (I'm leaning toward no because this is a bridge of an existing framework that did not have support for attributes, so it doesn't seem likely that attributes have a place to be reasonably added. We could include additional information as attributes, maybe like progname, but I don't know if that's valuable to users)
  • Verify where this bridge should live (currently under the instrumentation directory, but would a bridges directory be more appropriate? => Python puts logs instrumentation in instrumentation, JS put winston in packages, Go uses bridges, Java keeps it in instrumentation)
  • Depending on when this is released, add support for Rails 8 structured logging (structured logging pushed to Rails 8.1)

Closes #668

kaylareopelle and others added 30 commits September 19, 2023 08:37
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
…ntelemetry-ruby-contrib into logger-instrumentation
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.
@kaylareopelle kaylareopelle changed the title feat: 🚧 WIP: Logger instrumentation feat: Ruby Logger instrumentation Dec 5, 2024
* Add references to released logs gems
* Test Rails 7.0 - 8.0
* Rubocop
* Set gem version
…ntelemetry-ruby-contrib into logger-instrumentation
severity_text: severity,
severity_number: severity_number(severity),
timestamp: datetime,
body: msg,
Copy link
Contributor Author

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?

@kaylareopelle
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Ensures stale-bot keeps this issue/PR open
Projects
Status: Pending PR
Development

Successfully merging this pull request may close these issues.

Add instrumentation for Ruby Logger leveraging Log Records
3 participants