Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#79 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
rails, ruby

Línea de trabajo

Comienza con la API de EcsLogging::Logger y la reproducción de RSpec proporcionada usando ActiveSupport::TaggedLogging. Sigue la llamada tagged que pasa cinco argumentos y añade o ajusta la cobertura de compatibilidad para que el logger no genere ningún ArgumentError y emita JSON cuyo message incluya [MyTag] test message.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Ruby
Estrellas
8
Forks
10
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de elastic/ecs-logging-ruby

Todos los issues de elastic/ecs-logging-ruby

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.