Class: Datadog::Tracing::SpanOperation::Events::OnError

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/span_operation.rb

Overview

Triggered when the span raises an error during measurement.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default, logger: Datadog.logger) ⇒ OnError

Returns a new instance of OnError.



434
435
436
437
# File 'lib/datadog/tracing/span_operation.rb', line 434

def initialize(default, logger: Datadog.logger)
  @handler = default
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



439
440
441
# File 'lib/datadog/tracing/span_operation.rb', line 439

def logger
  @logger
end

Instance Method Details

#publish(*args) ⇒ Object



462
463
464
465
466
467
468
469
470
471
472
# File 'lib/datadog/tracing/span_operation.rb', line 462

def publish(*args)
  begin
    @handler.call(*args)
  rescue => e
    logger.debug do
      "Error in on_error handler '#{@default}': #{e.class}: #{e} at #{Array(e.backtrace).first}"
    end
  end

  true
end

#wrap_defaultObject

DEV: Revisit this before full 1.0 release. It seems like OnError wants to behave like a middleware stack, where each “subscriber”‘s executed is chained to the previous one. This is different from how Event works, and might be incompatible.



447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/datadog/tracing/span_operation.rb', line 447

def wrap_default
  original = @handler

  @handler = proc do |op, error|
    yield(op, error)
  rescue => e
    logger.debug do
      "Custom on_error handler #{@handler} failed, using fallback behavior. \
        Cause: #{e.class}: #{e} Location: #{Array(e.backtrace).first}"
    end

    original&.call(op, error)
  end
end