EcsLogging::Logger raises ArgumentError when used with ActiveSupport::TaggedLogging
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
調査の方向性
EcsLogging::Logger API と、ActiveSupport::TaggedLogging を使用した提供済みの RSpec 再現コードから始めます。5 つの引数を渡す tagged 呼び出しを追跡し、logger が ArgumentError を発生させず、message に [MyTag] test message を含む JSON を出力するように、互換性のカバレッジを追加または調整します。
索引モデルが issue の本文から書いたものです。
説明
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 ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
elastic/ecs-logging-ruby のほかの issue
-
agent-ruby
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
elastic/ecs-logging-ruby#77 ·
-
Replace tibdex/github-app-token with actions/create-github-app-token対応中かも @copilot-swe-agent が 401 日前に担当しました。 オープンagent-ruby
elastic/ecs-logging-ruby#71 · リアクション 1 件 · 担当者 1 名 ·
-
agent-ruby
難易度 2/5 1〜3時間 初心者へのやさしさ 20/100
elastic/ecs-logging-ruby#34 · コメント 2 件 ·
-
Failure with Rails 5オープンagent-ruby
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
elastic/ecs-logging-ruby#25 ·
elastic/ecs-logging-ruby の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
rubyevents/rubyevents#2277 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 2 日以内に返信