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

undefined method `current_tags' for nil:NilClass #232

Closed
tmaier opened this issue Jul 30, 2024 · 1 comment
Closed

undefined method `current_tags' for nil:NilClass #232

tmaier opened this issue Jul 30, 2024 · 1 comment

Comments

@tmaier
Copy link

tmaier commented Jul 30, 2024

Environment

  • Ruby Version: ruby 3.2.4 (2024-04-23 revision af471c0e01) [x86_64-linux]
  • Semantic Logger Version: semantic_logger (4.16.0)
  • Application/framework names and versions (e.g. Rails, Sinatra, Puma, etc.). rails (7.1.3.4)
  • Rails Semantic Logger Version, if applicable. rails_semantic_logger (4.17.0)
  • Rails configuration. Only need the settings related to Rails Semantic Logger and Semantic Logger.
      # Heroku compability & development mode
      if ENV['RAILS_LOG_TO_STDOUT'].present? || Rails.env.development?
        $stdout.sync = true
        config.semantic_logger.add_appender(io: $stdout, formatter: config.rails_semantic_logger.format)
      end
    
      # AppSignal integration
      appsignal_logger = Appsignal::Logger.new('rails', format: Appsignal::Logger::LOGFMT)
      config.semantic_logger.add_appender(logger: appsignal_logger, formatter: :logfmt)
    
      # Disable logging to a file
      config.rails_semantic_logger.add_file_appender = false
    
      # "info" includes generic and useful information about system operation, but avoids logging too much
      # information to avoid inadvertent exposure of personally identifiable information (PII). If you
      # want to log everything, set the level to "debug".
      config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').downcase.strip.to_sym
    
      # Prepend all log lines with the following tags.
      config.log_tags = {
        subdomain: :subdomain,
        request_id: :request_id
      }
    
      # Disable logging of assets
      config.rails_semantic_logger.quiet_assets = true
      
      config.solid_queue.logger = SemanticLogger['SolidQueue']
  • Full Stack Trace, if an exception is being raised.
    lib/active_job/logging.rb:32 logger_tagged_by_active_job?	
    lib/active_job/logging.rb:24 tag_logger	
    lib/active_job/logging.rb:14 block (2 levels) in <module:Logging>	
    lib/active_support/callbacks.rb:130 instance_exec	
    lib/active_support/callbacks.rb:130 block in run_callbacks	
    lib/active_support/callbacks.rb:141 run_callbacks	
    lib/active_job/enqueuing.rb:93 enqueue	
    lib/active_job/enqueuing.rb:60 perform_later	
    app/models/concerns/publication/searchable.rb:238 block in elasticsearch_index_async	
    
  • I am using ActiveJob, SolidQueue gems

Expected Behavior

I just wanted to call IndexerJob.perform_later(operation.to_s, self.class.to_s, id) successfully

ActiveJob::Logging has the following method:

      def logger_tagged_by_active_job?
        logger.formatter.current_tags.include?("ActiveJob")
      end

This method expects a formatter to respond to current_tags method.

Source: https://github.com/rails/rails/blob/v7.1.3.4/activejob/lib/active_job/logging.rb

Actual Behavior

Formatter is nil and thus, unable to respond to current_tags method.

ApplicationJob.logger
#=> #<SemanticLogger::Logger:0x00007f3921c63070 @filter=nil, @level=nil, @level_index=nil, @name="Rails">
ApplicationJob.logger.formatter
#=> nil

Similar Issues

The logstash-logger gem had a similar issue in 2017: dwbutler/logstash-logger#112

Pull Request

  • Consider submitting a Pull Request with a fix for the issue.
    • This is particularly helpful when running newer Rails versions, since we are not running it yet.
  • Or, even a Pull request that only includes a test that reproduces the problem.
@tmaier
Copy link
Author

tmaier commented Jul 31, 2024

I found the issue. It was on my side.

@tmaier tmaier closed this as completed Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant