Giter Site home page Giter Site logo

Comments (6)

xuan-cao-swi avatar xuan-cao-swi commented on August 15, 2024

Could you provide how you do the otel initialization that set the custom logger (e.g. OpenTelemetry::SDK.configure )?

Have you tried following config to set the custom logger?

OpenTelemetry::SDK.configure do |c|
  c.logger = ::Logger.new($stdout, level: <the_level_you_want>) # or any custom logger with ::Logger.new
  c.use_all()
end

from opentelemetry-ruby.

ngoral avatar ngoral commented on August 15, 2024
Opentelemetry::SDK.configure do |conf|
  conf.logger = Rails.logger
end

But I beleive that doesn't really matter since I can see that we always pass a nil as a message to a logger, and the message itself is passed in progname attribute.

So, yes, ActiveSupport::Logger manages it, and, I guess, some others do it too, and I can definitely patch my logger to be capable to manage it, but the logic in code itself seems a little odd to me.

from opentelemetry-ruby.

BrianHawley avatar BrianHawley commented on August 15, 2024

Looking at the Ruby logger source, it also passes a nil message from the info method to the add method, with source pretty much identical to the source in ForwardingLogger. However, the Ruby logger's add method treats a nil message as an excuse to call the block to construct the message, or reuses the progname parameter as a message if no block is passed.

So the bug is the ForwardingLogger add method not passing through the block to the logger it's forwarding to. Without that, the normal block fallback behavior doesn't work.

from opentelemetry-ruby.

xuan-cao-swi avatar xuan-cao-swi commented on August 15, 2024

@BrianHawley thanks for the finding. I did little test and I believe you are correct on "ForwardingLogger add method not passing through the block to the logger it's forwarding to".

Would you mind to contribute a PR to amend this?

::Logger.add expect block

from opentelemetry-ruby.

BrianHawley avatar BrianHawley commented on August 15, 2024

@ngoral I fixed ForwardingLogger's add method to forward the block parameter. You should fix your custom logger's add method to use the same parameter handling tricks as Ruby's Logger class:

if progname.nil?
  progname = @progname
end
if message.nil?
  if block_given?
    message = yield
  else
    message = progname
    progname = @progname
  end
end

You might prefer to just derive your custom logger from Ruby's Logger class, then change where you're logging to or the formatter. Up to you.

from opentelemetry-ruby.

szechyjs avatar szechyjs commented on August 15, 2024

This seems to also be busted when using Ougai as the logger.

Current workaround is OpenTelemetry.logger = Rails.logger

from opentelemetry-ruby.

Related Issues (20)

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.