Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

EcsLogging::Logger raises ArgumentError when used with ActiveSupport::TaggedLogging

オープン
#79 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
rails, ruby

調査の方向性

EcsLogging::Logger API と、ActiveSupport::TaggedLogging を使用した提供済みの RSpec 再現コードから始めます。5 つの引数を渡す tagged 呼び出しを追跡し、logger が ArgumentError を発生させず、message に [MyTag] test message を含む JSON を出力するように、互換性のカバレッジを追加または調整します。

索引モデルが issue の本文から書いたものです。

説明

agent-ruby

Description

When using EcsLogging::Logger wrapped with ActiveSupport::TaggedLogging, an ArgumentError is raised because EcsLogging::Logger doesn't support the same method signatures as standard Ruby Logger.

Spec to Reproduce

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  gem 'ecs-logging'
  gem 'activesupport', '>= 7.0'
  gem 'elastic-apm'
  gem 'rspec'
end

require 'active_support'
require 'active_support/isolated_execution_state'
require 'active_support/tagged_logging'
require 'ecs_logging/logger'
require 'elastic_apm'
require 'rspec/autorun'

RSpec.describe EcsLogging::Logger do
  describe 'with ElasticAPM custom context' do
    let(:output) { StringIO.new }
    let(:ecs_logger) { EcsLogging::Logger.new(output) }
    let(:tagged_logger) { ActiveSupport::TaggedLogging.new(ecs_logger) }

    before do
      allow(ElasticAPM).to receive(:running?).and_return(true)
      allow(ElasticAPM).to receive(:set_custom_context)
    end

    it 'works with ElasticAPM custom context' do
      expect {
        ElasticAPM.set_custom_context(key: 'value', event: 'test_event')
        tagged_logger.tagged('MyTag') do
          tagged_logger.info('test message')
        end
      }.not_to raise_error

      log_entry = JSON.parse(output.string)
      expect(log_entry['message']).to include('[MyTag] test message')
    end
  end
end
Details ```bash
❯ ruby ecs_logging_reproduction.rb
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
      psych (>= 4.0.0)
      Available/installed versions of this gem:
      - 5.3.1
      - 5.1.2
      erb (>= 0)
      Available/installed versions of this gem:
      - 6.0.2
      - 4.0.3
WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
Please report a bug if this causes problems.
.F

Failures:

  1) EcsLogging::Logger ElasticAPM custom context compatibility works with ElasticAPM custom context
     Failure/Error:
       expect {
         ElasticAPM.set_custom_context(key: 'value', event: 'test_event')
         tagged_logger.tagged('MyTag') do
           tagged_logger.info('test message')
         end
       }.not_to raise_error

       expected no Exception, got #<ArgumentError: wrong number of arguments (given 5, expected 4)> with backtrace:
         # ecs_logging_reproduction.rb:50:in `block (5 levels) in <main>'
         # ecs_logging_reproduction.rb:49:in `block (4 levels) in <main>'
         # ecs_logging_reproduction.rb:47:in `block (3 levels) in <main>'
     # ecs_logging_reproduction.rb:47:in `block (3 levels) in <main>'

Finished in 0.01716 seconds (files took 0.10125 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ecs_logging_reproduction.rb:46 # EcsLogging::Logger ElasticAPM custom context compatibility works with ElasticAPM custom context

```

Expected Behavior

The logger should output a JSON log entry with the tag included, similar to how it works with standard Logger.

Actual Behavior

An ArgumentError is raised because ActiveSupport::TaggedLogging calls methods on the underlying logger that EcsLogging::Logger doesn't implement with compatible signatures.

Environment

  • Ruby version: 3.2+
  • Rails version: 7.x / 8.x
  • ecs-logging-ruby version: latest

Workaround

We worked around this by not wrapping the ECS logger with TaggedLogging and instead including the tag directly in the message:

def logger
  @logger ||= Rails.logger
end

def log(level, event, **attributes)
  message = "[#{log_tag}] event=#{event} #{format_attributes(attributes)}"
  logger.public_send(level, message)
end

Suggestion

It would be helpful if EcsLogging::Logger could be compatible with ActiveSupport::TaggedLogging, or if the gem provided its own tagging mechanism that works with the ECS JSON format.

主要言語
Ruby
スター
8
フォーク
10
PR マージ指標
30日以内にマージされた PR はありません

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

elastic/ecs-logging-ruby のほかの issue

elastic/ecs-logging-ruby の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。